1
1
from enum import Enum , unique
2
2
3
+ import json
4
+
3
5
import discord
4
6
from discord .ext import commands
5
7
8
+ class FileHandler ():
9
+ file = "bot/cogs/belts.json"
10
+
11
+ def __init__ (self , belt ):
12
+ self .belt = belt
13
+ self .msg = self .get_info ()[0 ]
14
+ self .color = self .get_info ()[1 ]
15
+
16
+ def get_info (self ):
17
+ with open (self .file ) as json_file :
18
+ data = json .load (json_file )
19
+ msg = f"Subiste para { self .belt } :clap:\n \n Próximos objetivos:"
20
+ color = int (data [self .belt ]["color" ], 16 )
21
+ for param in data [self .belt ]["objectives" ]:
22
+ msg += '\n ' + param
23
+
24
+ return (
25
+ msg ,
26
+ color
27
+ )
28
+
29
+ translator_to_emoji = {"Branco" : ":white_circle:" ,
30
+ "Amarelo" : ":yellow_circle:" ,
31
+ "Azul" : ":blue_circle:" ,
32
+ "Verde" : ":green_circle:" ,
33
+ "Laranja" : ":orange_circle:" ,
34
+ "Vermelho" : ":red_circle:" ,
35
+ "Roxo" : ":purple_circle:" ,
36
+ "Preto" : ":black_circle:" }
37
+
6
38
@unique
7
39
class Belts (Enum ):
8
40
Branco = 1
@@ -40,7 +72,7 @@ def get_role_from_name(guild, belt):
40
72
for role in guild .roles :
41
73
if role .name == belt :
42
74
return role
43
-
75
+
44
76
class BeltsAttributions (commands .Cog ):
45
77
def __init__ (self , client ):
46
78
self .client = client
@@ -62,11 +94,24 @@ async def promove(self, ctx, user, belt):
62
94
reason = None ,
63
95
atomic = True
64
96
)
65
-
97
+
98
+ # Public message
66
99
await ctx .send (
67
100
f'{ user } agora és cinturão { belt } :tada:'
68
101
)
69
-
102
+
103
+ # Private message
104
+ file_handler = FileHandler (belt )
105
+ emoji = translator_to_emoji [belt ]
106
+ user = member
107
+ embed = discord .Embed (
108
+ title = f"{ emoji } Parabéns, subiste de cinturão :tada:" ,
109
+ description = file_handler .msg ,
110
+ color = file_handler .color
111
+ )
112
+
113
+ await user .send (embed = embed )
114
+
70
115
elif belt == ninja .current_belt ().name :
71
116
await ctx .reply (
72
117
f"Esse já é o cinturão do ninja { user } !"
@@ -79,11 +124,24 @@ async def promove(self, ctx, user, belt):
79
124
reason = None ,
80
125
atomic = True
81
126
)
82
-
127
+
128
+ # Public message
83
129
await ctx .send (
84
130
f'{ user } agora és cinturão { belt } :tada:'
85
131
)
86
-
132
+
133
+ # Private message
134
+ file_handler = FileHandler (belt )
135
+ emoji = translator_to_emoji [belt ]
136
+ user = member
137
+ embed = discord .Embed (
138
+ title = f"{ emoji } Parabéns, subiste de cinturão :tada:" ,
139
+ description = file_handler .msg ,
140
+ color = file_handler .color
141
+ )
142
+
143
+ await user .send (embed = embed )
144
+
87
145
elif belt != ninja .next_belt ().name :
88
146
await ctx .send (
89
147
f'{ user } esse cinturão não é valido de se ser atribuido.'
0 commit comments