Преглед изворни кода

refactored, shortened code with new functions for more readability

tenessy0570 пре 3 година
родитељ
комит
3202a921a6
2 измењених фајлова са 19 додато и 5 уклоњено
  1. 10 5
      __init__.py
  2. 9 0
      utils.py

+ 10 - 5
__init__.py

@@ -1,14 +1,19 @@
+import environment_vars
 import discord
 from os import environ
-import environment_vars
-from decorators import author_is_not_bot, notify_if_wrong_command
 from img_urls import good_face_url
+from decorators import (
+    author_is_not_bot,
+    notify_if_wrong_command
+)
 from utils import (
     on_ready_print,
     receive_message_then_send,
     get_commands_from_file,
     message_is_song_name,
-    get_video_url_by_song_name
+    get_video_url_by_song_name,
+    get_image,
+    get_commands_list_to_send
 )
 
 
@@ -27,7 +32,7 @@ class MyClient(discord.Client):
             return
 
         if await receive_message_then_send(message, "!help"):
-            await message.channel.send("Available commands: \n" + self._help_commands_for_output)
+            await message.channel.send(get_commands_list_to_send(self))
             return
 
         if message.attachments:
@@ -36,7 +41,7 @@ class MyClient(discord.Client):
             return
 
         if await receive_message_then_send(message, "face"):
-            image_to_send = discord.Embed().set_image(url=good_face_url)
+            image_to_send = get_image(url=good_face_url)
             await message.channel.send(embed=image_to_send)
             return
 

+ 9 - 0
utils.py

@@ -1,3 +1,4 @@
+import discord
 from youtubesearchpython import VideosSearch
 
 
@@ -46,3 +47,11 @@ def get_video_url_by_song_name(message):
     videos_search = VideosSearch(song_name, limit=1)
     video_id = _get_movie_id(videos_search)
     return url + video_id
+
+
+def get_image(url):
+    return discord.Embed().set_image(url=url)
+
+
+def get_commands_list_to_send(self):
+    return "Available commands: \n" + self._help_commands_for_output