2017-05-10 06:52:17 -04:00
|
|
|
# Maki
|
|
|
|
# ----
|
|
|
|
# Discord bot by MrDetonia
|
|
|
|
#
|
2018-01-27 07:04:12 -05:00
|
|
|
# Copyright 2018 Zac Herd
|
2017-05-10 06:52:17 -04:00
|
|
|
# Licensed under BSD 3-clause License, see LICENSE.md for more info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# IMPORTS
|
|
|
|
import os
|
|
|
|
import asyncio
|
|
|
|
import subprocess
|
|
|
|
import discord
|
2017-12-08 14:10:28 -05:00
|
|
|
import urllib.request
|
2017-05-10 06:52:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
# LOCAL IMPORTS
|
|
|
|
from common import *
|
|
|
|
from helpers import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# COMMAND IMPLEMENTATINS
|
|
|
|
@asyncio.coroutine
|
|
|
|
def cmd_die(client, msg):
|
|
|
|
print("INFO: accepting .die from " + msg.author.name)
|
|
|
|
yield from client.send_message(msg.channel, "But will I dream? ;-;")
|
|
|
|
yield from client.logout()
|
|
|
|
|
|
|
|
if msg.content[5:] == "reload":
|
|
|
|
# touch file to signal reload
|
|
|
|
with open("reload", "a"):
|
|
|
|
os.utime("reload", None)
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def cmd_quiet(client, msg):
|
|
|
|
quiet[msg.server.id] = 1
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def cmd_loud(client, msg):
|
|
|
|
if msg.server.id in quiet:
|
|
|
|
quiet.pop(msg.server.id, None)
|
|
|
|
|
|
|
|
|
2017-12-08 14:10:28 -05:00
|
|
|
@asyncio.coroutine
|
|
|
|
def cmd_avatar(client, msg):
|
|
|
|
url = msg.content[8:]
|
2017-12-24 09:54:19 -05:00
|
|
|
response = "Avatar updated!"
|
2017-12-08 14:10:28 -05:00
|
|
|
try:
|
2018-01-27 07:00:45 -05:00
|
|
|
httpresponse = urllib.request.urlopen(url)
|
|
|
|
imgdata = httpresponse.read()
|
2017-12-08 14:10:28 -05:00
|
|
|
yield from client.edit_profile(avatar=imgdata)
|
2017-12-24 09:54:19 -05:00
|
|
|
except urllib.error.URLError as e:
|
2018-01-27 07:00:45 -05:00
|
|
|
response = "URL Error: " + str(e)
|
2017-12-24 09:54:19 -05:00
|
|
|
except discord.HTTPException:
|
|
|
|
response = "Dicsord failed to edit my profile!"
|
|
|
|
except discord.InvalidArgument:
|
|
|
|
response = "Invalid image!"
|
2017-12-08 14:10:28 -05:00
|
|
|
except:
|
2017-12-24 09:54:19 -05:00
|
|
|
response = "Error updating avatar!"
|
|
|
|
|
|
|
|
yield from discord_send(client, msg, response)
|
2017-05-10 06:52:17 -04:00
|
|
|
|
|
|
|
# COMMAND HANDLING
|
|
|
|
admincommands = {
|
|
|
|
"die": cmd_die,
|
|
|
|
"quiet": cmd_quiet,
|
|
|
|
"loud": cmd_loud,
|
2017-12-08 14:10:28 -05:00
|
|
|
"avatar": cmd_avatar,
|
|
|
|
}
|