Skip to content

Commit 70bf213

Browse files
authored
Refactor Enum Classes (#27)
* Ci changes * re-refactor Enum class
1 parent 290441e commit 70bf213

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

bot/cogs/belts.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class Ninja:
6666
def __init__(self, guild: discord.Guild, member: discord.Member):
6767
self.guild = guild
6868
self.member = member
69-
self.roles = [role for role in member.roles]
69+
self.roles = list(member.roles)
7070

71-
def current_belt(self) -> Belts:
71+
def current_belt(self):
7272
"""This function returns the current belt of the ninja."""
7373

7474
highest_belt = None
@@ -79,6 +79,8 @@ def current_belt(self) -> Belts:
7979

8080
return highest_belt
8181

82+
return highest_belt
83+
8284
def next_belt(self) -> Belts:
8385
"""This function returns the next belt of the ninja."""
8486

@@ -94,7 +96,9 @@ def __init__(self, client: commands.Bot):
9496
self.client = client
9597

9698
@commands.command(name="promove")
97-
@commands.has_any_role("🛡️ Admin", "🏆 Champion", "🧑‍🏫 Mentores")
99+
@commands.has_any_role(
100+
Roles["ADMIN"].name, Roles["CHAMPION"].name, Roles["MENTOR"].name
101+
)
98102
async def promove(
99103
self, ctx: discord.ext.commands.Context, user: str, belt: str
100104
) -> None:

bot/cogs/utils/constants.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import discord
44
from discord.ext import commands
5+
from emoji import emojize
56

67
translator_to_emoji = {
78
"Branco": ":white_circle:",
@@ -14,17 +15,37 @@
1415
"Preto": ":black_circle:",
1516
}
1617

18+
Roles = Enum(
19+
value="Roles",
20+
names=[
21+
(emojize(":older_man: Guardiões"), 1),
22+
("GUARDIOES", 1),
23+
(emojize(":ninja: Ninja"), 2),
24+
("NINJAS", 2),
25+
(emojize(":person_raising_hand: Voluntários"), 3),
26+
("VOLUNTARIOS", 3),
27+
(emojize(":teacher: Mentores"), 4),
28+
("MENTOR", 4),
29+
(emojize(":shield: Admin"), 5),
30+
("ADMIN", 5),
31+
(emojize(":trophy: Champion"), 6),
32+
("CHAMPION", 6),
33+
],
34+
)
1735

18-
@unique
19-
class Belts(Enum):
20-
Branco = 1
21-
Amarelo = 2
22-
Azul = 3
23-
Verde = 4
24-
Laranja = 5
25-
Vermelho = 6
26-
Roxo = 7
27-
Preto = 8
36+
Belts = Enum(
37+
value="Belts",
38+
names=[
39+
("Branco", 1),
40+
("Amarelo", 2),
41+
("Azul", 3),
42+
("Verde", 4),
43+
("Laranja", 5),
44+
("Vermelho", 6),
45+
("Roxo", 7),
46+
("Preto", 8),
47+
],
48+
)
2849

2950

3051
def get_role_from_name(guild: discord.Guild, belt: str) -> discord.Role:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
discord==1.0.1
22
discord.py==1.7.3
3+
emoji==1.7.0
34
python-dotenv==0.20.0
45
SQLAlchemy==1.4.37

0 commit comments

Comments
 (0)