on_messages.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from discord.errors import HTTPException
  2. from utils import (
  3. in_bot_channel,
  4. receive_message_then_send,
  5. get_commands_list_to_send,
  6. get_embed,
  7. message_is_song_name,
  8. get_video_url_by_song_name,
  9. get_on_delete_content
  10. )
  11. from img_urls import good_face_url
  12. from decorators import (
  13. author_is_not_bot,
  14. notify_if_wrong_command
  15. )
  16. class Messages:
  17. @author_is_not_bot
  18. @notify_if_wrong_command
  19. async def on_message(self, message):
  20. if not await in_bot_channel(message=message):
  21. return
  22. if await receive_message_then_send(message, "ping", "pong"):
  23. return
  24. if await receive_message_then_send(message, "avatar"):
  25. image_to_send = await get_embed(self.user.avatar_url)
  26. await message.channel.send(embed=image_to_send)
  27. return
  28. if await receive_message_then_send(message, "!help"):
  29. await message.channel.send(await get_commands_list_to_send(self))
  30. return
  31. if message.attachments:
  32. await message.delete()
  33. await message.channel.send('No attachments! :)')
  34. return
  35. if await receive_message_then_send(message, "face"):
  36. image_to_send = await get_embed(url=good_face_url)
  37. await message.channel.send(embed=image_to_send)
  38. return
  39. if await message_is_song_name(message):
  40. try:
  41. url = await get_video_url_by_song_name(message)
  42. except (NameError, HTTPException):
  43. await message.channel.send('Bad song name!')
  44. return
  45. await message.channel.send(url)
  46. return
  47. return True
  48. async def on_typing(self, channel, user, when):
  49. if not await in_bot_channel(channel=channel):
  50. return
  51. await channel.send(f"{user.mention} started typing something on {when}. I saw it!")
  52. async def on_message_delete(self, message):
  53. if not await in_bot_channel(message=message):
  54. return
  55. message_content = await get_on_delete_content(message)
  56. await message.channel.send(
  57. f"{message.author.mention}'s message has just been deleted which was {message_content}"
  58. )