Maki is a Discord bot that does things. Written in Python 3 and relies on Discord.py API implementation.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

74 行
1.6KB

  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. 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. url = msg.content[8:]
  36. response = "Avatar updated!"
  37. try:
  38. httpresponse = urllib.request.urlopen(url)
  39. imgdata = httpresponse.read()
  40. yield from client.edit_profile(avatar=imgdata)
  41. except urllib.error.URLError as e:
  42. response = "URL Error: " + str(e)
  43. except discord.HTTPException:
  44. response = "Dicsord failed to edit my profile!"
  45. except discord.InvalidArgument:
  46. response = "Invalid image!"
  47. except:
  48. response = "Error updating avatar!"
  49. yield from discord_send(client, msg, response)
  50. # COMMAND HANDLING
  51. admincommands = {
  52. "die": cmd_die,
  53. "quiet": cmd_quiet,
  54. "loud": cmd_loud,
  55. "avatar": cmd_avatar,
  56. }