Maki is a Discord bot that does things. Written in Python 3 and relies on Discord.py API implementation.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

66 lignes
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. }