tenessy0570 3 anni fa
commit
05db8e935b
5 ha cambiato i file con 68 aggiunte e 0 eliminazioni
  1. 4 0
      .gitignore
  2. 43 0
      __init__.py
  3. 6 0
      decorators.py
  4. 2 0
      img_urls.py
  5. 13 0
      utils.py

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+environment_vars.py
+bot-env/
+.idea/
+__pycache__/

+ 43 - 0
__init__.py

@@ -0,0 +1,43 @@
+import discord
+from os import environ
+import environment_vars
+from decorators import author_is_not_bot
+from img_urls import good_face_url
+from utils import on_ready_print, receive_message_then_send
+
+
+class MyClient(discord.Client):
+    _help_commands = ['face', 'ping']
+    _help_commands_for_output = ('~ ' + command for command in _help_commands)
+    _help_commands_for_output = '\n'.join(_help_commands_for_output)
+
+    async def on_ready(self):
+        on_ready_print(self)
+
+    @author_is_not_bot
+    async def on_message(self, message):
+
+        if await receive_message_then_send(message, "ping", "pong"):
+            return
+
+        if await receive_message_then_send(message, "!help"):
+            await message.channel.send("Available commands: \n" + self._help_commands_for_output)
+            return
+
+        if message.attachments:
+            await message.delete()
+            await message.channel.send('No attachments! :)')
+            return
+
+        if await receive_message_then_send(message, "face"):
+            image_to_send = discord.Embed().set_image(url=good_face_url)
+            await message.channel.send(embed=image_to_send)
+            return
+
+        await message.channel.send('I cant understand you :(\nType !help for available command list')
+        return
+
+
+bot_token = environ.get('bot_token')
+client = MyClient()
+client.run(bot_token)

+ 6 - 0
decorators.py

@@ -0,0 +1,6 @@
+def author_is_not_bot(func):
+    async def wrapper(self, message, *args, **kwargs):
+        if message.author == self.user:
+            return None
+        return await func(self, message, *args, **kwargs)
+    return wrapper

+ 2 - 0
img_urls.py

@@ -0,0 +1,2 @@
+good_face_url = "https://sun9-50.userapi.com/impg/jq6twD1hupMyGQFC_iqyZcFOwYNrc3Vjmu3Fcg/d-Z4YGf" \
+                "E8-Y.jpg?size=667x600&quality=96&sign=a8b00f560509b7439a3a69ead4850ae7&type=album"

+ 13 - 0
utils.py

@@ -0,0 +1,13 @@
+def on_ready_print(self):
+    print("---------")
+    print("Logged as")
+    print(self.user.name)
+    print(self.user.id)
+    print("---------")
+
+
+async def receive_message_then_send(message, received: str, to_send="") -> None:
+    if message.content == received:
+        if to_send:
+            await message.channel.send(to_send)
+        return True