Przeglądaj źródła

added decorator to notify if inputted command was wrong

tenessy0570 3 lat temu
rodzic
commit
90dbc11464
2 zmienionych plików z 11 dodań i 3 usunięć
  1. 3 3
      __init__.py
  2. 8 0
      decorators.py

+ 3 - 3
__init__.py

@@ -1,7 +1,7 @@
 import discord
 from os import environ
 import environment_vars
-from decorators import author_is_not_bot
+from decorators import author_is_not_bot, notify_if_wrong_command
 from img_urls import good_face_url
 from utils import on_ready_print, receive_message_then_send, get_commands_from_file
 
@@ -15,6 +15,7 @@ class MyClient(discord.Client):
         on_ready_print(self)
 
     @author_is_not_bot
+    @notify_if_wrong_command
     async def on_message(self, message):
         if await receive_message_then_send(message, "ping", "pong"):
             return
@@ -33,8 +34,7 @@ class MyClient(discord.Client):
             await message.channel.send(embed=image_to_send)
             return
 
-        await message.channel.send('I cant understand you :(\nType !help for available command list')
-        return
+        return True
 
 
 bot_token = environ.get('bot_token')

+ 8 - 0
decorators.py

@@ -4,3 +4,11 @@ def author_is_not_bot(func):
             return None
         return await func(self, message, *args, **kwargs)
     return wrapper
+
+
+def notify_if_wrong_command(func):
+    async def wrapper(self, message, *args, **kwargs):
+        function_return = func(self, message, *args, **kwargs)
+        if await function_return:
+            await message.channel.send('I cant understand you :(\nType !help for available command list')
+    return wrapper