Created
July 12, 2021 19:58
-
-
Save rsayers/6701203effc839ac648ecd5ddd3ffdcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import asyncio | |
import subprocess | |
from humanfriendly import format_timespan | |
import datetime | |
startup = datetime.datetime.now() | |
client = discord.Client() | |
cmds = {} | |
def register_command(name, fn): | |
cmds[name] = fn | |
def fortune(*args): | |
return subprocess.check_output(['fortune']).decode('utf-8') | |
def cowsay(*args): | |
return "```\n{}\n```".format(subprocess.check_output(['cowsay']+list(args)).decode('utf-8')) | |
def figlet(*args): | |
return "```\n{}\n```".format(subprocess.check_output(['figlet']+list(args)).decode('utf-8')) | |
def uptime(*args): | |
return "This bot instance has been up {}".format(format_timespan((datetime.datetime.now()-startup).seconds)) | |
register_command("!fortune", fortune) | |
register_command("!cowsay", cowsay) | |
register_command("!figlet", figlet) | |
register_command("!uptime", uptime) | |
@client.event | |
async def on_ready(): | |
print('Logged in as') | |
print(client.user.name) | |
print(client.user.id) | |
print('------') | |
@client.event | |
async def on_message(message): | |
parts = message.content.split(' ') | |
cmd = parts[0] | |
if cmd in cmds: | |
await client.send_message(message.channel, cmds[parts[0]](*parts[1:])) | |
client.run(YOUR_SECRET_KEY) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment