2016-07-23 23:58:35 +12:00
|
|
|
import discord
|
2016-07-09 13:27:19 +12:00
|
|
|
from discord.ext import commands
|
2016-07-16 08:13:26 +12:00
|
|
|
from .utils import checks
|
2016-07-23 23:58:35 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
import subprocess
|
2016-07-17 02:45:44 +12:00
|
|
|
import os
|
|
|
|
import glob
|
2016-07-09 13:27:19 +12:00
|
|
|
import random
|
2016-07-11 01:58:46 +12:00
|
|
|
import re
|
2016-07-19 11:25:03 +12:00
|
|
|
import calendar
|
2016-08-07 10:20:16 +12:00
|
|
|
import pendulum
|
2016-07-19 11:25:03 +12:00
|
|
|
import datetime
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-07-19 11:29:40 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
class Core:
|
2016-07-23 23:58:35 +12:00
|
|
|
"""Core commands, these are the miscallaneous commands that don't fit into other categories'"""
|
2016-07-11 09:18:30 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2016-07-29 11:08:06 +12:00
|
|
|
|
2016-07-19 11:25:03 +12:00
|
|
|
@commands.command()
|
2016-07-31 00:30:28 +12:00
|
|
|
@checks.customPermsOrRole(send_messages=True)
|
2016-07-19 11:25:03 +12:00
|
|
|
async def calendar(self, month: str=None, year: int=None):
|
2016-07-19 11:40:09 +12:00
|
|
|
"""Provides a printout of the current month's calendar
|
2016-07-19 11:25:03 +12:00
|
|
|
Provide month and year to print the calendar of that year and month"""
|
|
|
|
months = {
|
|
|
|
"january": 1,
|
|
|
|
"february": 2,
|
|
|
|
"march": 3,
|
|
|
|
"april": 4,
|
|
|
|
"may": 5,
|
|
|
|
"june": 6,
|
|
|
|
"july": 7,
|
|
|
|
"august": 8,
|
|
|
|
"september": 9,
|
|
|
|
"october": 10,
|
|
|
|
"november": 11,
|
|
|
|
"december": 12
|
|
|
|
}
|
|
|
|
if month is None:
|
|
|
|
month = datetime.date.today().month
|
|
|
|
else:
|
2016-07-19 11:30:52 +12:00
|
|
|
month = months.get(month.lower())
|
2016-07-19 11:25:03 +12:00
|
|
|
if month is None:
|
|
|
|
await self.bot.say("Please provide a valid Month!")
|
|
|
|
return
|
|
|
|
if year is None:
|
|
|
|
year = datetime.datetime.today().year
|
|
|
|
cal = calendar.TextCalendar().formatmonth(year, month)
|
2016-08-01 07:11:05 +12:00
|
|
|
await self.bot.say("```\n{}```".format(cal))
|
2016-07-31 02:59:35 +12:00
|
|
|
|
|
|
|
@commands.command()
|
|
|
|
@checks.customPermsOrRole(send_messages=True)
|
|
|
|
async def uptime(self):
|
|
|
|
"""Provides a printout of the current bot's uptime"""
|
2016-08-07 10:20:16 +12:00
|
|
|
await self.bot.say("Uptime: ```\n{}```".format((pendulum.utcnow() - self.bot.uptime).in_words()))
|
2016-07-19 11:25:03 +12:00
|
|
|
|
2016-08-08 02:03:36 +12:00
|
|
|
@commands.command(aliases=['invite'])
|
|
|
|
@checks.customPermsOrRole(send_messages=True)
|
2016-07-10 06:28:48 +12:00
|
|
|
async def addbot(self):
|
2016-07-10 06:31:40 +12:00
|
|
|
"""Provides a link that you can use to add me to a server"""
|
2016-07-10 06:27:14 +12:00
|
|
|
perms = discord.Permissions.none()
|
|
|
|
perms.read_messages = True
|
|
|
|
perms.send_messages = True
|
|
|
|
perms.manage_roles = True
|
|
|
|
perms.ban_members = True
|
|
|
|
perms.kick_members = True
|
|
|
|
perms.manage_messages = True
|
|
|
|
perms.embed_links = True
|
|
|
|
perms.read_message_history = True
|
|
|
|
perms.attach_files = True
|
2016-07-11 09:18:30 +12:00
|
|
|
await self.bot.say("Use this URL to add me to a server that you'd like!\n{}"
|
|
|
|
.format(discord.utils.oauth_url('183748889814237186', perms)))
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2016-07-17 02:20:17 +12:00
|
|
|
@commands.command(pass_context=True)
|
2016-07-31 00:30:28 +12:00
|
|
|
@checks.customPermsOrRole(send_messages=True)
|
2016-07-17 02:46:02 +12:00
|
|
|
async def doggo(self, ctx):
|
2016-07-17 02:20:17 +12:00
|
|
|
"""Use this to print a random doggo image.
|
|
|
|
Doggo is love, doggo is life."""
|
2016-08-12 14:13:35 +12:00
|
|
|
f = glob.glob('images/doggo*')[random.randint(0, len(glob.glob('doggo*')) - 1)]
|
2016-07-22 23:54:03 +12:00
|
|
|
with open(f, 'rb') as f:
|
2016-07-24 02:20:10 +12:00
|
|
|
await self.bot.upload(f)
|
2016-08-08 06:04:52 +12:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
|
|
|
@checks.customPermsOrRole(send_messages=True)
|
|
|
|
async def snek(self, ctx):
|
|
|
|
"""Use this to print a random snek image.
|
|
|
|
Sneks are o3o"""
|
2016-08-12 14:13:35 +12:00
|
|
|
f = glob.glob('images/snek*')[random.randint(0, len(glob.glob('snek*')) - 1)]
|
2016-08-08 06:04:52 +12:00
|
|
|
with open(f, 'rb') as f:
|
|
|
|
await self.bot.upload(f)
|
2016-07-18 08:54:31 +12:00
|
|
|
|
2016-07-10 06:27:14 +12:00
|
|
|
@commands.command()
|
2016-07-31 00:30:28 +12:00
|
|
|
@checks.customPermsOrRole(send_messages=True)
|
2016-07-09 13:27:19 +12:00
|
|
|
async def joke(self):
|
|
|
|
"""Prints a random riddle"""
|
2016-07-10 00:57:25 +12:00
|
|
|
fortuneCommand = "/usr/bin/fortune riddles"
|
|
|
|
fortune = subprocess.check_output(fortuneCommand.split()).decode("utf-8")
|
|
|
|
await self.bot.say(fortune)
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2016-07-31 00:30:28 +12:00
|
|
|
@checks.customPermsOrRole(send_messages=True)
|
2016-07-25 06:09:15 +12:00
|
|
|
async def roll(self, ctx, notation: str="d6"):
|
2016-07-11 01:58:03 +12:00
|
|
|
"""Rolls a die based on the notation given
|
|
|
|
Format should be #d#"""
|
|
|
|
try:
|
2016-07-25 03:34:04 +12:00
|
|
|
dice = re.search("(\d*)d(\d*)", notation).group(1)
|
2016-07-12 06:16:18 +12:00
|
|
|
num = int(re.search("(\d*)d(\d*)", notation).group(2))
|
2016-07-17 02:20:17 +12:00
|
|
|
# This error will be hit if the notation is completely different than #d#
|
2016-07-12 06:18:57 +12:00
|
|
|
except AttributeError:
|
|
|
|
await self.bot.say("Please provide the die notation in #d#!")
|
|
|
|
return
|
2016-07-17 02:20:17 +12:00
|
|
|
# This error will be hit if there was an issue converting to an int
|
|
|
|
# This means the notation was still given wrong
|
2016-07-12 06:18:57 +12:00
|
|
|
except ValueError:
|
2016-07-11 01:58:03 +12:00
|
|
|
await self.bot.say("Please provide the die notation in #d#!")
|
|
|
|
return
|
2016-07-17 02:20:17 +12:00
|
|
|
# Dice will be None if d# was provided, assume this means 1d#
|
2016-07-25 03:34:04 +12:00
|
|
|
dice = dice or 1
|
|
|
|
dice = int(dice)
|
2016-07-12 06:16:18 +12:00
|
|
|
if dice > 10:
|
2016-07-11 01:58:03 +12:00
|
|
|
await self.bot.say("I'm not rolling more than 10 dice, I have tiny hands")
|
|
|
|
return
|
2016-07-12 06:16:18 +12:00
|
|
|
if num > 100:
|
2016-07-12 05:56:43 +12:00
|
|
|
await self.bot.say("What die has more than 100 sides? Please, calm down")
|
2016-07-11 01:58:03 +12:00
|
|
|
return
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-23 23:58:35 +12:00
|
|
|
valueStr = ", ".join(str(random.randint(1, num)) for i in range(0, int(dice)))
|
2016-07-11 09:18:30 +12:00
|
|
|
|
2016-07-25 03:34:04 +12:00
|
|
|
if dice == 1:
|
2016-07-12 06:13:25 +12:00
|
|
|
fmt = '{0.message.author.name} has rolled a {2} sided die and got the number {3}!'
|
2016-07-11 01:58:03 +12:00
|
|
|
else:
|
2016-07-12 05:58:53 +12:00
|
|
|
fmt = '{0.message.author.name} has rolled {1}, {2} sided dice and got the numbers {3}!'
|
2016-07-12 06:13:25 +12:00
|
|
|
await self.bot.say(fmt.format(ctx, dice, num, valueStr))
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-07-13 03:58:57 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Core(bot))
|