Maki is a Discord bot that does things. Written in Python 3 and relies on Discord.py API implementation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.4KB

  1. # Maki
  2. # ----
  3. # Discord bot by MrDetonia
  4. #
  5. # Copyright 2018 Zac Herd
  6. # Licensed under BSD 3-clause License, see LICENSE.md for more info
  7. # IMPORTS
  8. import os
  9. import asyncio
  10. import subprocess
  11. import discord
  12. import urllib.request
  13. # LOCAL IMPORTS
  14. from common import *
  15. from helpers import *
  16. # COMMAND IMPLEMENTATINS
  17. @asyncio.coroutine
  18. def cmd_die(client, msg):
  19. print("INFO: accepting .die from " + msg.author.name)
  20. yield from client.send_message(msg.channel, "But will I dream? ;-;")
  21. yield from client.logout()
  22. @asyncio.coroutine
  23. def cmd_quiet(client, msg):
  24. quiet[msg.server.id] = 1
  25. @asyncio.coroutine
  26. def cmd_loud(client, msg):
  27. if msg.server.id in quiet:
  28. quiet.pop(msg.server.id, None)
  29. @asyncio.coroutine
  30. def cmd_avatar(client, msg):
  31. url = msg.content[8:]
  32. response = "Avatar updated!"
  33. try:
  34. httpresponse = urllib.request.urlopen(url)
  35. imgdata = httpresponse.read()
  36. yield from client.edit_profile(avatar=imgdata)
  37. except urllib.error.URLError as e:
  38. response = "URL Error: " + str(e)
  39. except discord.HTTPException:
  40. response = "Dicsord failed to edit my profile!"
  41. except discord.InvalidArgument:
  42. response = "Invalid image!"
  43. except:
  44. response = "Error updating avatar!"
  45. yield from discord_send(client, msg, response)
  46. # COMMAND HANDLING
  47. admincommands = {
  48. "die": cmd_die,
  49. "quiet": cmd_quiet,
  50. "loud": cmd_loud,
  51. "avatar": cmd_avatar,
  52. }