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.

67 lines
1.3KB

  1. # Maki
  2. # ----
  3. # Discord bot by MrDetonia
  4. #
  5. # Copyright 2017 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. if msg.content[5:] == "reload":
  23. # touch file to signal reload
  24. with open("reload", "a"):
  25. os.utime("reload", None)
  26. @asyncio.coroutine
  27. def cmd_quiet(client, msg):
  28. quiet[msg.server.id] = 1
  29. @asyncio.coroutine
  30. def cmd_loud(client, msg):
  31. if msg.server.id in quiet:
  32. quiet.pop(msg.server.id, None)
  33. @asyncio.coroutine
  34. def cmd_avatar(client, msg):
  35. # TODO: error-check
  36. # unsafe, but admin command - use with care for now
  37. url = msg.content[8:]
  38. try:
  39. response = urllib.request.urlopen(url)
  40. imgdata = response.read()
  41. yield from client.edit_profile(avatar=imgdata)
  42. except:
  43. yield from discord_send(client, msg, "Error updating avatar!")
  44. # COMMAND HANDLING
  45. admincommands = {
  46. "die": cmd_die,
  47. "quiet": cmd_quiet,
  48. "loud": cmd_loud,
  49. "avatar": cmd_avatar,
  50. }