__init__.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import environment_vars
  2. import discord
  3. from os import environ
  4. from img_urls import good_face_url
  5. from decorators import (
  6. author_is_not_bot,
  7. notify_if_wrong_command
  8. )
  9. from utils import (
  10. on_ready_print,
  11. receive_message_then_send,
  12. get_commands_from_file,
  13. message_is_song_name,
  14. get_video_url_by_song_name,
  15. get_image,
  16. get_commands_list_to_send
  17. )
  18. class MyClient(discord.Client):
  19. _help_commands = get_commands_from_file("commands_list_divided_with_newline")
  20. _help_commands_for_output = ('~ ' + command for command in _help_commands)
  21. _help_commands_for_output = '\n'.join(_help_commands_for_output)
  22. async def on_ready(self):
  23. on_ready_print(self)
  24. @author_is_not_bot
  25. @notify_if_wrong_command
  26. async def on_message(self, message):
  27. if await receive_message_then_send(message, "ping", "pong"):
  28. return
  29. if await receive_message_then_send(message, "avatar"):
  30. image_to_send = get_image(self.user.avatar_url)
  31. await message.channel.send(embed=image_to_send)
  32. return
  33. if await receive_message_then_send(message, "!help"):
  34. await message.channel.send(get_commands_list_to_send(self))
  35. return
  36. if message.attachments:
  37. await message.delete()
  38. await message.channel.send('No attachments! :)')
  39. return
  40. if await receive_message_then_send(message, "face"):
  41. image_to_send = get_image(url=good_face_url)
  42. await message.channel.send(embed=image_to_send)
  43. return
  44. if message_is_song_name(message):
  45. try:
  46. url = get_video_url_by_song_name(message)
  47. except NameError as error_info:
  48. await message.channel.send(error_info)
  49. return
  50. await message.channel.send(url)
  51. return
  52. return True
  53. bot_token = environ.get('bot_token')
  54. client = MyClient()
  55. client.run(bot_token)