1
0
mirror of https://github.com/MrDetonia/Maki.git synced 2024-11-13 00:26:53 -05:00
Maki/admincommands.py

67 lines
1.3 KiB
Python
Raw Normal View History

# Maki
# ----
# Discord bot by MrDetonia
#
# Copyright 2017 Zac Herd
# Licensed under BSD 3-clause License, see LICENSE.md for more info
# IMPORTS
import os
import asyncio
import subprocess
import discord
import urllib.request
# 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)
@asyncio.coroutine
def cmd_avatar(client, msg):
# TODO: error-check
# unsafe, but admin command - use with care for now
url = msg.content[8:]
try:
response = urllib.request.urlopen(url)
imgdata = response.read()
yield from client.edit_profile(avatar=imgdata)
except:
yield from discord_send(client, msg, "Error updating avatar!")
# COMMAND HANDLING
admincommands = {
"die": cmd_die,
"quiet": cmd_quiet,
"loud": cmd_loud,
"avatar": cmd_avatar,
}