Explorar o código

some refactor

tenessy0570 %!s(int64=3) %!d(string=hai) anos
pai
achega
37fe9009b8
Modificáronse 2 ficheiros con 16 adicións e 4 borrados
  1. 7 2
      __init__.py
  2. 9 2
      utils.py

+ 7 - 2
__init__.py

@@ -18,7 +18,9 @@ from utils import (
     in_bot_channel,
     get_message_by_id,
     get_reaction_info,
-    create_message_and_add_reactions, create_and_get_roles_dict
+    create_message_and_add_reactions,
+    create_and_get_roles_dict,
+    get_roles_for_send
 )
 
 
@@ -32,15 +34,18 @@ class MyClient(discord.Client):
         ":train:": u"\U0001F68B",
         ":kimono:": u"\U0001F458"
     }
+
     _roles = create_and_get_roles_dict(_emojis)
+    _roles_for_send = get_roles_for_send(_roles)
 
     async def on_ready(self):
         await on_ready_print(self)
         _channel = None
 
         for channel in self.get_all_channels():
-            if channel.name == 'bot':
+            if channel.name != 'bot':
                 _channel = channel
+
         await create_message_and_add_reactions(self, _channel)
 
     @author_is_not_bot

+ 9 - 2
utils.py

@@ -85,7 +85,7 @@ async def get_reaction_info(payload):
 
 
 async def create_message_and_add_reactions(self, _channel):
-    message = await _channel.send("Loaded")
+    message = await _channel.send(self._roles_for_send)
     await message.add_reaction(emoji=self._emojis[':smiling_face_with_3_hearts:'])
     await message.add_reaction(emoji=self._emojis[':train:'])
     await message.add_reaction(emoji=self._emojis[':kimono:'])
@@ -95,6 +95,13 @@ def create_and_get_roles_dict(_emojis):
     _roles = {}
 
     for key, i in zip(_emojis, range(1, len(_emojis) + 1)):
-        _roles[f"Role {i}"] = _emojis[key]
+        _roles[key] = f"Role {i}"
 
     return _roles
+
+
+def get_roles_for_send(_roles):
+    roles = ""
+    for key, value in _roles.items():
+        roles += f"{key} ~ @{value}\n"
+    return roles