1
0
Fork 0
mirror of synced 2024-05-14 17:42:23 +12:00

Update to use new cog paradigm

This commit is contained in:
phxntxm 2019-02-23 14:13:10 -06:00
parent 2035b963eb
commit 5f568b37de
26 changed files with 155 additions and 183 deletions

View file

@ -7,7 +7,7 @@ from discord.ext import commands
valid_perms = [p for p in dir(discord.Permissions) if isinstance(getattr(discord.Permissions, p), property)] valid_perms = [p for p in dir(discord.Permissions) if isinstance(getattr(discord.Permissions, p), property)]
class Admin: class Admin(commands.Cog):
"""These are commands that allow more intuitive configuration, that don't fit into the config command""" """These are commands that allow more intuitive configuration, that don't fit into the config command"""
@commands.command() @commands.command()

View file

@ -57,7 +57,7 @@ def parse_string(date):
return datetime.date(year, month, day) return datetime.date(year, month, day)
class Birthday: class Birthday(commands.Cog):
"""Track and announce birthdays""" """Track and announce birthdays"""
def __init__(self, bot): def __init__(self, bot):
@ -157,7 +157,7 @@ WHERE
EXAMPLE: !birthdays EXAMPLE: !birthdays
RESULT: A printout of the birthdays from everyone on this server""" RESULT: A printout of the birthdays from everyone on this server"""
if member: if member:
date = await self.bot.db.fetchrow("SELECT birthday FROM users WHERE id=$1", member.id) date = await ctx.bot.db.fetchrow("SELECT birthday FROM users WHERE id=$1", member.id)
if date is None or date["birthday"] is None: if date is None or date["birthday"] is None:
await ctx.send(f"I do not have {member.display_name}'s birthday saved!") await ctx.send(f"I do not have {member.display_name}'s birthday saved!")
else: else:
@ -207,9 +207,9 @@ WHERE
await ctx.send(f"I have just saved your birthday as {date}") await ctx.send(f"I have just saved your birthday as {date}")
try: try:
await self.bot.db.execute("INSERT INTO users (id, birthday) VALUES ($1, $2)", ctx.author.id, date) await ctx.bot.db.execute("INSERT INTO users (id, birthday) VALUES ($1, $2)", ctx.author.id, date)
except UniqueViolationError: except UniqueViolationError:
await self.bot.db.execute("UPDATE users SET birthday = $1 WHERE id = $2", date, ctx.author.id) await ctx.bot.db.execute("UPDATE users SET birthday = $1 WHERE id = $2", date, ctx.author.id)
@birthday.command(name='remove') @birthday.command(name='remove')
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
@ -219,7 +219,7 @@ WHERE
EXAMPLE: !birthday remove EXAMPLE: !birthday remove
RESULT: I have magically forgotten your birthday""" RESULT: I have magically forgotten your birthday"""
await ctx.send("I don't know your birthday anymore :(") await ctx.send("I don't know your birthday anymore :(")
await self.bot.db.execute("UPDATE users SET birthday=NULL WHERE id=$1", ctx.author.id) await ctx.bot.db.execute("UPDATE users SET birthday=NULL WHERE id=$1", ctx.author.id)
def setup(bot): def setup(bot):

View file

@ -6,14 +6,14 @@ import asyncio
import math import math
class Blackjack: class Blackjack(commands.Cog):
"""Pretty self-explanatory""" """Pretty self-explanatory"""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.games = {} self.games = {}
def __unload(self): def cog_unload(self):
# Simply cancel every task # Simply cancel every task
for game in self.games.values(): for game in self.games.values():
game.task.cancel() game.task.cancel()

View file

@ -7,14 +7,12 @@ import re
from enum import Enum from enum import Enum
class Chess: class Chess(commands.Cog):
"""Pretty self-explanatory""" """Pretty self-explanatory"""
def __init__(self, bot): # Our format for games is going to be a little different, because we do want to allow multiple games per guild
self.bot = bot # Format should be {'server_id': [Game, Game, Game]}
# Our format for games is going to be a little different, because we do want to allow multiple games per guild games = {}
# Format should be {'server_id': [Game, Game, Game]}
self.games = {}
def play(self, player, notation): def play(self, player, notation):
"""Our task to handle a player making their actual move""" """Our task to handle a player making their actual move"""
@ -152,7 +150,7 @@ class Chess:
elif result is MoveStatus.valid: elif result is MoveStatus.valid:
game = self.get_game(ctx.message.author) game = self.get_game(ctx.message.author)
link = game.draw_board() link = game.draw_board()
await self.bot.upload(link) await ctx.bot.upload(link)
@commands.command() @commands.command()
@checks.can_run(send_messages=True) @checks.can_run(send_messages=True)

View file

@ -26,9 +26,13 @@ class MessageFormatError(ConfigException):
# noinspection PyMethodMayBeStatic,PyUnusedLocal # noinspection PyMethodMayBeStatic,PyUnusedLocal
class GuildConfiguration: class GuildConfiguration(commands.Cog):
"""Handles configuring the different settings that can be used on the bot""" """Handles configuring the different settings that can be used on the bot"""
keys = {
}
def _str_to_bool(self, opt, setting): def _str_to_bool(self, opt, setting):
setting = setting.title() setting = setting.title()
if setting.title() not in ["True", "False"]: if setting.title() not in ["True", "False"]:
@ -596,7 +600,7 @@ WHERE
""" """
return await ctx.bot.db.execute(query, setting, ctx.guild.id) return await ctx.bot.db.execute(query, setting, ctx.guild.id)
async def __after_invoke(self, ctx): async def cog_after_invoke(self, ctx):
"""Here we will facilitate cleaning up settings, will remove channels/roles that no longer exist, etc.""" """Here we will facilitate cleaning up settings, will remove channels/roles that no longer exist, etc."""
pass pass

View file

@ -1,9 +1,11 @@
from utils import config
import aiohttp import aiohttp
import logging import logging
import json import json
import discord import discord
from utils import config
from discord.ext import commands
log = logging.getLogger() log = logging.getLogger()
discord_bots_url = 'https://bots.discord.pw/api/bots/{}/stats' discord_bots_url = 'https://bots.discord.pw/api/bots/{}/stats'
@ -11,14 +13,14 @@ discordbots_url = "https://discordbots.org/api/bots/{}/stats"
carbonitex_url = 'https://www.carbonitex.net/discord/data/botdata.php' carbonitex_url = 'https://www.carbonitex.net/discord/data/botdata.php'
class StatsUpdate: class StatsUpdate(commands.Cog):
"""This is used purely to update stats information for the bot sites""" """This is used purely to update stats information for the bot sites"""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.session = aiohttp.ClientSession() self.session = aiohttp.ClientSession()
def __unload(self): def cog_unload(self):
self.bot.loop.create_task(self.session.close()) self.bot.loop.create_task(self.session.close())
async def update(self): async def update(self):
@ -59,15 +61,19 @@ class StatsUpdate:
async with self.session.post(url, data=payload, headers=headers) as resp: async with self.session.post(url, data=payload, headers=headers) as resp:
log.info('discordbots.com statistics retruned {} for {}'.format(resp.status, payload)) log.info('discordbots.com statistics retruned {} for {}'.format(resp.status, payload))
@commands.Cog.listener
async def on_guild_join(self, _): async def on_guild_join(self, _):
await self.update() await self.update()
@commands.Cog.listener
async def on_guild_leave(self, _): async def on_guild_leave(self, _):
await self.update() await self.update()
@commands.Cog.listener
async def on_ready(self): async def on_ready(self):
await self.update() await self.update()
@commands.Cog.listener
async def on_member_join(self, member): async def on_member_join(self, member):
query = """ query = """
SELECT SELECT
@ -99,6 +105,7 @@ WHERE
except (discord.Forbidden, discord.HTTPException, AttributeError): except (discord.Forbidden, discord.HTTPException, AttributeError):
pass pass
@commands.Cog.listener
async def on_member_remove(self, member): async def on_member_remove(self, member):
query = """ query = """
SELECT SELECT

View file

@ -64,13 +64,11 @@ class Game:
return fmt return fmt
class Hangman: class Hangman(commands.Cog):
"""Pretty self-explanatory""" """Pretty self-explanatory"""
def __init__(self, bot): games = {}
self.bot = bot pending_games = []
self.games = {}
self.pending_games = []
def create(self, word, ctx): def create(self, word, ctx):
# Create a new game, then save it as the server's game # Create a new game, then save it as the server's game
@ -166,7 +164,7 @@ class Hangman:
self.pending_games.append(ctx.guild.id) self.pending_games.append(ctx.guild.id)
try: try:
msg = await self.bot.wait_for('message', check=check, timeout=60) msg = await ctx.bot.wait_for('message', check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
self.pending_games.remove(ctx.guild.id) self.pending_games.remove(ctx.guild.id)
await ctx.send( await ctx.send(

View file

@ -7,12 +7,9 @@ import math
import utils import utils
class Images: class Images(commands.Cog):
"""Commands that post images, or look up images""" """Commands that post images, or look up images"""
def __init__(self, bot):
self.bot = bot
@commands.command(aliases=['rc']) @commands.command(aliases=['rc'])
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
async def cat(self, ctx): async def cat(self, ctx):

View file

@ -85,12 +85,10 @@ hugs = \
"*approaches {user} after having gone to the gym for several months and almost crushes them.*"] "*approaches {user} after having gone to the gym for several months and almost crushes them.*"]
class Interaction: class Interaction(commands.Cog):
"""Commands that interact with another user""" """Commands that interact with another user"""
def __init__(self, bot): battles = defaultdict(list)
self.bot = bot
self.battles = defaultdict(list)
def get_receivers_battle(self, receiver): def get_receivers_battle(self, receiver):
for battle in self.battles.get(receiver.guild.id, []): for battle in self.battles.get(receiver.guild.id, []):
@ -142,7 +140,7 @@ class Interaction:
await ctx.send("Error: Could not find user: {}".format(user)) await ctx.send("Error: Could not find user: {}".format(user))
return return
settings = await self.bot.db.fetchrow( settings = await ctx.bot.db.fetchrow(
"SELECT custom_hugs, include_default_hugs FROM guilds WHERE id = $1", "SELECT custom_hugs, include_default_hugs FROM guilds WHERE id = $1",
ctx.guild.id ctx.guild.id
) )
@ -193,7 +191,7 @@ class Interaction:
await ctx.send("Why would you want to battle yourself? Suicide is not the answer") await ctx.send("Why would you want to battle yourself? Suicide is not the answer")
return return
# Check if the person battled is me # Check if the person battled is me
if self.bot.user.id == player2.id: if ctx.bot.user.id == player2.id:
ctx.command.reset_cooldown(ctx) ctx.command.reset_cooldown(ctx)
await ctx.send("I always win, don't even try it.") await ctx.send("I always win, don't even try it.")
return return
@ -214,7 +212,7 @@ class Interaction:
f"{ctx.prefix}accept or {ctx.prefix}decline" f"{ctx.prefix}accept or {ctx.prefix}decline"
# Add a call to turn off battling, if the battle is not accepted/declined in 3 minutes # Add a call to turn off battling, if the battle is not accepted/declined in 3 minutes
part = functools.partial(self.battling_off, battle) part = functools.partial(self.battling_off, battle)
self.bot.loop.call_later(180, part) ctx.bot.loop.call_later(180, part)
await ctx.send(fmt) await ctx.send(fmt)
@commands.command() @commands.command()
@ -238,7 +236,7 @@ class Interaction:
return return
# Lets get the settings # Lets get the settings
settings = await self.bot.db.fetchrow( settings = await ctx.bot.db.fetchrow(
"SELECT custom_battles, include_default_battles FROM guilds WHERE id = $1", "SELECT custom_battles, include_default_battles FROM guilds WHERE id = $1",
ctx.guild.id ctx.guild.id
) )
@ -278,7 +276,7 @@ FROM
) AS sub ) AS sub
WHERE id = any($2) WHERE id = any($2)
""" """
results = await self.bot.db.fetch(query, member_list, [winner.id, loser.id]) results = await ctx.bot.db.fetch(query, member_list, [winner.id, loser.id])
old_winner = old_loser = None old_winner = old_loser = None
for result in results: for result in results:
@ -309,7 +307,7 @@ VALUES
($1, $2, $3, $4) ($1, $2, $3, $4)
""" """
if old_loser: if old_loser:
await self.bot.db.execute( await ctx.bot.db.execute(
update_query, update_query,
loser_rating, loser_rating,
old_loser['battle_wins'], old_loser['battle_wins'],
@ -317,9 +315,9 @@ VALUES
loser.id loser.id
) )
else: else:
await self.bot.db.execute(insert_query, loser.id, loser_rating, 0, 1) await ctx.bot.db.execute(insert_query, loser.id, loser_rating, 0, 1)
if old_winner: if old_winner:
await self.bot.db.execute( await ctx.bot.db.execute(
update_query, update_query,
winner_rating, winner_rating,
old_winner['battle_wins'] + 1, old_winner['battle_wins'] + 1,
@ -327,9 +325,9 @@ VALUES
winner.id winner.id
) )
else: else:
await self.bot.db.execute(insert_query, winner.id, winner_rating, 1, 0) await ctx.bot.db.execute(insert_query, winner.id, winner_rating, 1, 0)
results = await self.bot.db.fetch(query, member_list, [winner.id, loser.id]) results = await ctx.bot.db.fetch(query, member_list, [winner.id, loser.id])
new_winner_rank = new_loser_rank = None new_winner_rank = new_loser_rank = None
for result in results: for result in results:
@ -393,13 +391,13 @@ VALUES
ctx.command.reset_cooldown(ctx) ctx.command.reset_cooldown(ctx)
await ctx.send("You can't boop yourself! Silly...") await ctx.send("You can't boop yourself! Silly...")
return return
if boopee.id == self.bot.user.id: if boopee.id == ctx.bot.user.id:
ctx.command.reset_cooldown(ctx) ctx.command.reset_cooldown(ctx)
await ctx.send("Why the heck are you booping me? Get away from me >:c") await ctx.send("Why the heck are you booping me? Get away from me >:c")
return return
query = "SELECT amount FROM boops WHERE booper = $1 AND boopee = $2" query = "SELECT amount FROM boops WHERE booper = $1 AND boopee = $2"
amount = await self.bot.db.fetchrow(query, booper.id, boopee.id) amount = await ctx.bot.db.fetchrow(query, booper.id, boopee.id)
if amount is None: if amount is None:
amount = 1 amount = 1
replacement_query = "INSERT INTO boops (booper, boopee, amount) VALUES($1, $2, $3)" replacement_query = "INSERT INTO boops (booper, boopee, amount) VALUES($1, $2, $3)"
@ -408,7 +406,7 @@ VALUES
amount = amount['amount'] + 1 amount = amount['amount'] + 1
await ctx.send(f"{booper.mention} has just booped {boopee.mention}{message}! That's {amount} times now!") await ctx.send(f"{booper.mention} has just booped {boopee.mention}{message}! That's {amount} times now!")
await self.bot.db.execute(replacement_query, booper.id, boopee.id, amount) await ctx.bot.db.execute(replacement_query, booper.id, boopee.id, amount)
class Battle: class Battle:

View file

@ -8,13 +8,10 @@ import discord
import re import re
class Links: class Links(commands.Cog):
"""This class contains all the commands that make HTTP requests """This class contains all the commands that make HTTP requests
In other words, all commands here rely on other URL's to complete their requests""" In other words, all commands here rely on other URL's to complete their requests"""
def __init__(self, bot):
self.bot = bot
@commands.command(aliases=['g']) @commands.command(aliases=['g'])
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
async def google(self, ctx, *, query: str): async def google(self, ctx, *, query: str):

View file

@ -38,13 +38,10 @@ def _command_signature(cmd):
return ' '.join(result) return ' '.join(result)
class Miscallaneous: class Miscallaneous(commands.Cog):
"""Core commands, these are the miscallaneous commands that don't fit into other categories'""" """Core commands, these are the miscallaneous commands that don't fit into other categories'"""
process = psutil.Process()
def __init__(self, bot): process.cpu_percent()
self.bot = bot
self.process = psutil.Process()
self.process.cpu_percent()
@commands.command() @commands.command()
@commands.cooldown(1, 3, commands.cooldowns.BucketType.user) @commands.cooldown(1, 3, commands.cooldowns.BucketType.user)
@ -56,7 +53,7 @@ class Miscallaneous:
if command is None: if command is None:
p = await utils.HelpPaginator.from_bot(ctx) p = await utils.HelpPaginator.from_bot(ctx)
else: else:
entity = self.bot.get_cog(command) or self.bot.get_command(command) entity = ctx.bot.get_cog(command) or ctx.bot.get_command(command)
if entity is None: if entity is None:
clean = command.replace('@', '@\u200b') clean = command.replace('@', '@\u200b')
@ -74,7 +71,7 @@ class Miscallaneous:
chunks = [] chunks = []
if entity: if entity:
entity = self.bot.get_cog(entity) or self.bot.get_command(entity) entity = ctx.bot.get_cog(entity) or ctx.bot.get_command(entity)
if entity is None: if entity is None:
fmt = "Hello! Here is a list of the sections of commands that I have " \ fmt = "Hello! Here is a list of the sections of commands that I have " \
"(there are a lot of commands so just start with the sections...I know, I'm pretty great)\n" "(there are a lot of commands so just start with the sections...I know, I'm pretty great)\n"
@ -88,7 +85,7 @@ class Miscallaneous:
chunks.append(fmt) chunks.append(fmt)
cogs = sorted(self.bot.cogs.values(), key=lambda c: c.__class__.__name__) cogs = sorted(ctx.bot.cogs.values(), key=lambda c: c.__class__.__name__)
for cog in cogs: for cog in cogs:
tmp = "**{}**\n".format(cog.__class__.__name__) tmp = "**{}**\n".format(cog.__class__.__name__)
if cog.__doc__: if cog.__doc__:
@ -102,14 +99,14 @@ class Miscallaneous:
tmp += "\n{}".format(entity.help) tmp += "\n{}".format(entity.help)
chunks.append(tmp) chunks.append(tmp)
else: else:
cmds = sorted(ctx.bot.get_cog_commands(entity.__class__.__name__), key=lambda c: c.name) cmds = sorted(entity.get_commands(), key=lambda c: c.name)
fmt = "Here are a list of commands under the section {}\n".format(entity.__class__.__name__) fmt = "Here are a list of commands under the section {}\n".format(entity.__class__.__name__)
fmt += "Type `{}help command` to get more help on a specific command\n\n".format(ctx.prefix) fmt += "Type `{}help command` to get more help on a specific command\n\n".format(ctx.prefix)
chunks.append(fmt) chunks.append(fmt)
for command in cmds: for command in cmds:
for subcommand in utils.get_all_subcommands(command): for subcommand in command.walk_commands():
tmp = "**{}**\n\t{}\n".format(subcommand.qualified_name, subcommand.short_doc) tmp = "**{}**\n\t{}\n".format(subcommand.qualified_name, subcommand.short_doc)
if len(chunks[len(chunks) - 1] + tmp) > 2000: if len(chunks[len(chunks) - 1] + tmp) > 2000:
chunks.append(tmp) chunks.append(tmp)
@ -144,7 +141,7 @@ class Miscallaneous:
"""Returns the latency between the server websocket, and between reading messages""" """Returns the latency between the server websocket, and between reading messages"""
msg_latency = datetime.datetime.utcnow() - ctx.message.created_at msg_latency = datetime.datetime.utcnow() - ctx.message.created_at
fmt = "Message latency {0:.2f} seconds".format(msg_latency.seconds + msg_latency.microseconds / 1000000) fmt = "Message latency {0:.2f} seconds".format(msg_latency.seconds + msg_latency.microseconds / 1000000)
fmt += "\nWebsocket latency {0:.2f} seconds".format(self.bot.latency) fmt += "\nWebsocket latency {0:.2f} seconds".format(ctx.bot.latency)
await ctx.send(fmt) await ctx.send(fmt)
@commands.command(aliases=["coin"]) @commands.command(aliases=["coin"])
@ -231,8 +228,8 @@ class Miscallaneous:
# Set the owner # Set the owner
embed = discord.Embed(**opts) embed = discord.Embed(**opts)
if hasattr(self.bot, 'owner'): if hasattr(ctx.bot, 'owner'):
embed.set_author(name=str(self.bot.owner), icon_url=self.bot.owner.avatar_url) embed.set_author(name=str(ctx.bot.owner), icon_url=ctx.bot.owner.avatar_url)
# Setup the process statistics # Setup the process statistics
name = "Process statistics" name = "Process statistics"
@ -242,17 +239,17 @@ class Miscallaneous:
cpu_usage = self.process.cpu_percent() / psutil.cpu_count() cpu_usage = self.process.cpu_percent() / psutil.cpu_count()
value += 'Memory: {:.2f} MiB'.format(memory_usage) value += 'Memory: {:.2f} MiB'.format(memory_usage)
value += '\nCPU: {}%'.format(cpu_usage) value += '\nCPU: {}%'.format(cpu_usage)
if hasattr(self.bot, 'uptime'): if hasattr(ctx.bot, 'uptime'):
value += "\nUptime: {}".format((pendulum.now(tz="UTC") - self.bot.uptime).in_words()) value += "\nUptime: {}".format((pendulum.now(tz="UTC") - ctx.bot.uptime).in_words())
embed.add_field(name=name, value=value, inline=False) embed.add_field(name=name, value=value, inline=False)
# Setup the user and guild statistics # Setup the user and guild statistics
name = "User/Guild statistics" name = "User/Guild statistics"
value = "" value = ""
value += "Channels: {}".format(len(list(self.bot.get_all_channels()))) value += "Channels: {}".format(len(list(ctx.bot.get_all_channels())))
value += "\nUsers: {}".format(len(self.bot.users)) value += "\nUsers: {}".format(len(ctx.bot.users))
value += "\nServers: {}".format(len(self.bot.guilds)) value += "\nServers: {}".format(len(ctx.bot.guilds))
embed.add_field(name=name, value=value, inline=False) embed.add_field(name=name, value=value, inline=False)
# The game statistics # The game statistics
@ -261,10 +258,10 @@ class Miscallaneous:
# Lets make this one a list and join it at the end # Lets make this one a list and join it at the end
value = [] value = []
hm = self.bot.get_cog('Hangman') hm = ctx.bot.get_cog('Hangman')
ttt = self.bot.get_cog('TicTacToe') ttt = ctx.bot.get_cog('TicTacToe')
bj = self.bot.get_cog('Blackjack') bj = ctx.bot.get_cog('Blackjack')
interaction = self.bot.get_cog('Interaction') interaction = ctx.bot.get_cog('Interaction')
if hm: if hm:
value.append("Hangman games: {}".format(len(hm.games))) value.append("Hangman games: {}".format(len(hm.games)))
@ -274,7 +271,7 @@ class Miscallaneous:
value.append("Blackjack games: {}".format(len(bj.games))) value.append("Blackjack games: {}".format(len(bj.games)))
if interaction: if interaction:
count_battles = 0 count_battles = 0
for battles in self.bot.get_cog('Interaction').battles.values(): for battles in ctx.bot.get_cog('Interaction').battles.values():
count_battles += len(battles) count_battles += len(battles)
value.append("Battles running: {}".format(len(bj.games))) value.append("Battles running: {}".format(len(bj.games)))
embed.add_field(name=name, value="\n".join(value), inline=False) embed.add_field(name=name, value="\n".join(value), inline=False)
@ -288,8 +285,8 @@ class Miscallaneous:
EXAMPLE: !uptime EXAMPLE: !uptime
RESULT: A BAJILLION DAYS""" RESULT: A BAJILLION DAYS"""
if hasattr(self.bot, 'uptime'): if hasattr(ctx.bot, 'uptime'):
await ctx.send("Uptime: ```\n{}```".format((pendulum.now(tz="UTC") - self.bot.uptime).in_words())) await ctx.send("Uptime: ```\n{}```".format((pendulum.now(tz="UTC") - ctx.bot.uptime).in_words()))
else: else:
await ctx.send("I've just restarted and not quite ready yet...gimme time I'm not a morning pony :c") await ctx.send("I've just restarted and not quite ready yet...gimme time I'm not a morning pony :c")
@ -314,7 +311,7 @@ class Miscallaneous:
perms.connect = True perms.connect = True
perms.attach_files = True perms.attach_files = True
perms.add_reactions = True perms.add_reactions = True
app_info = await self.bot.application_info() app_info = await ctx.bot.application_info()
await ctx.send("Use this URL to add me to a server that you'd like!\n<{}>" await ctx.send("Use this URL to add me to a server that you'd like!\n<{}>"
.format(discord.utils.oauth_url(app_info.id, perms))) .format(discord.utils.oauth_url(app_info.id, perms)))

View file

@ -6,12 +6,9 @@ import discord
import asyncio import asyncio
class Moderation: class Moderation(commands.Cog):
"""Moderation commands, things that help control a server...but not the settings of the server""" """Moderation commands, things that help control a server...but not the settings of the server"""
def __init__(self, bot):
self.bot = bot
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@utils.can_run(kick_members=True) @utils.can_run(kick_members=True)
@ -40,7 +37,7 @@ class Moderation:
# Lets only accept an int for this method, in order to ensure only an ID is provided # Lets only accept an int for this method, in order to ensure only an ID is provided
# Due to that though, we need to ensure a string is passed as the member's ID # Due to that though, we need to ensure a string is passed as the member's ID
try: try:
await self.bot.http.unban(member_id, ctx.guild.id) await ctx.bot.http.unban(member_id, ctx.guild.id)
await ctx.send("\N{OK HAND SIGN}") await ctx.send("\N{OK HAND SIGN}")
except discord.Forbidden: except discord.Forbidden:
await ctx.send("But I can't, muh permissions >:c") await ctx.send("But I can't, muh permissions >:c")
@ -61,7 +58,7 @@ class Moderation:
# Lets first check if a user ID was provided, as that will be the easiest case to ban # Lets first check if a user ID was provided, as that will be the easiest case to ban
if member.isdigit(): if member.isdigit():
try: try:
await self.bot.http.ban(member, ctx.guild.id, reason=reason) await ctx.bot.http.ban(member, ctx.guild.id, reason=reason)
await ctx.send("\N{OK HAND SIGN}") await ctx.send("\N{OK HAND SIGN}")
except discord.Forbidden: except discord.Forbidden:
await ctx.send("But I can't, muh permissions >:c") await ctx.send("But I can't, muh permissions >:c")

View file

@ -10,7 +10,7 @@ BASE_URL = 'https://osu.ppy.sh/api/'
MAX_RETRIES = 5 MAX_RETRIES = 5
class Osu: class Osu(commands.Cog):
"""View OSU stats""" """View OSU stats"""
def __init__(self, bot): def __init__(self, bot):
@ -107,7 +107,7 @@ class Osu:
"id": author.id, "id": author.id,
"osu": user.username "osu": user.username
} }
await self.bot.db.upsert("users", update) await ctx.bot.db.upsert("users", update)
@osu.command(name='score', aliases=['scores']) @osu.command(name='score', aliases=['scores'])
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
@ -180,7 +180,7 @@ class Osu:
entries.append(entry) entries.append(entry)
try: try:
pages = utils.DetailedPages(self.bot, message=ctx.message, entries=entries) pages = utils.DetailedPages(ctx.bot, message=ctx.message, entries=entries)
await pages.paginate() await pages.paginate()
except utils.CannotPaginate as e: except utils.CannotPaginate as e:
await ctx.send(str(e)) await ctx.send(str(e))

View file

@ -16,12 +16,9 @@ check_o_stats = ['wins']
log = logging.getLogger() log = logging.getLogger()
class Overwatch: class Overwatch(commands.Cog):
"""Class for viewing Overwatch stats""" """Class for viewing Overwatch stats"""
def __init__(self, bot):
self.bot = bot
@commands.group() @commands.group()
async def ow(self, ctx): async def ow(self, ctx):
"""Command used to lookup information on your own user, or on another's """Command used to lookup information on your own user, or on another's
@ -39,7 +36,7 @@ class Overwatch:
EXAMPLE: !ow stats @OtherPerson Junkrat EXAMPLE: !ow stats @OtherPerson Junkrat
RESULT: Whether or not you should unfriend this person because they're a dirty rat""" RESULT: Whether or not you should unfriend this person because they're a dirty rat"""
user = user or ctx.message.author user = user or ctx.message.author
bt = self.bot.db.load('overwatch', key=str(user.id), pluck='battletag') bt = ctx.bot.db.load('overwatch', key=str(user.id), pluck='battletag')
if bt is None: if bt is None:
await ctx.send("I do not have this user's battletag saved!") await ctx.send("I do not have this user's battletag saved!")
@ -119,7 +116,7 @@ class Overwatch:
'battletag': bt 'battletag': bt
} }
await self.bot.db.save('overwatch', entry) await ctx.bot.db.save('overwatch', entry)
await ctx.send("I have just saved your battletag {}".format(ctx.message.author.mention)) await ctx.send("I have just saved your battletag {}".format(ctx.message.author.mention))
@ow.command(name="delete", aliases=['remove']) @ow.command(name="delete", aliases=['remove'])
@ -133,7 +130,7 @@ class Overwatch:
'member_id': str(ctx.message.author.id), 'member_id': str(ctx.message.author.id),
'battletag': None 'battletag': None
} }
await self.bot.db.save('overwatch', entry) await ctx.bot.db.save('overwatch', entry)
await ctx.send("I no longer have your battletag saved {}".format(ctx.message.author.mention)) await ctx.send("I no longer have your battletag saved {}".format(ctx.message.author.mention))

View file

@ -16,16 +16,13 @@ def get_syntax_error(e):
return '```py\n{0.text}{1:>{0.offset}}\n{2}: {0}```'.format(e, '^', type(e).__name__) return '```py\n{0.text}{1:>{0.offset}}\n{2}: {0}```'.format(e, '^', type(e).__name__)
class Owner: class Owner(commands.Cog):
"""Commands that can only be used by the owner of the bot, bot management commands""" """Commands that can only be used by the owner of the bot, bot management commands"""
_last_result = None
sessions = set()
def __init__(self, bot): async def cog_check(self, ctx):
self.bot = bot return await ctx.bot.is_owner(ctx.author)
self._last_result = None
self.sessions = set()
async def __local_check(self, ctx):
return await self.bot.is_owner(ctx.author)
@staticmethod @staticmethod
def cleanup_code(content): def cleanup_code(content):
@ -43,7 +40,7 @@ class Owner:
variables = { variables = {
'ctx': ctx, 'ctx': ctx,
'bot': self.bot, 'bot': ctx.bot,
'message': msg, 'message': msg,
'guild': msg.guild, 'guild': msg.guild,
'server': msg.guild, 'server': msg.guild,
@ -69,7 +66,7 @@ class Owner:
while True: while True:
try: try:
response = await self.bot.wait_for('message', check=check, timeout=10.0 * 60.0) response = await ctx.bot.wait_for('message', check=check, timeout=10.0 * 60.0)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send('Exiting REPL session.') await ctx.send('Exiting REPL session.')
self.sessions.remove(msg.channel.id) self.sessions.remove(msg.channel.id)
@ -134,7 +131,7 @@ class Owner:
@commands.command() @commands.command()
async def sendtochannel(self, ctx, cid: int, *, message): async def sendtochannel(self, ctx, cid: int, *, message):
"""Sends a message to a provided channel, by ID""" """Sends a message to a provided channel, by ID"""
channel = self.bot.get_channel(cid) channel = ctx.bot.get_channel(cid)
await channel.send(message) await channel.send(message)
try: try:
await ctx.message.delete() await ctx.message.delete()
@ -144,7 +141,7 @@ class Owner:
@commands.command() @commands.command()
async def debug(self, ctx, *, body: str): async def debug(self, ctx, *, body: str):
env = { env = {
'bot': self.bot, 'bot': ctx.bot,
'ctx': ctx, 'ctx': ctx,
'channel': ctx.message.channel, 'channel': ctx.message.channel,
'author': ctx.message.author, 'author': ctx.message.author,
@ -202,19 +199,19 @@ class Owner:
"""Shuts the bot down""" """Shuts the bot down"""
fmt = 'Shutting down, I will miss you {0.author.name}' fmt = 'Shutting down, I will miss you {0.author.name}'
await ctx.send(fmt.format(ctx.message)) await ctx.send(fmt.format(ctx.message))
await self.bot.logout() await ctx.bot.logout()
await self.bot.close() await ctx.bot.close()
@commands.command() @commands.command()
async def name(self, ctx, new_nick: str): async def name(self, ctx, new_nick: str):
"""Changes the bot's name""" """Changes the bot's name"""
await self.bot.user.edit(username=new_nick) await ctx.bot.user.edit(username=new_nick)
await ctx.send('Changed username to ' + new_nick) await ctx.send('Changed username to ' + new_nick)
@commands.command() @commands.command()
async def status(self, ctx, *, status: str): async def status(self, ctx, *, status: str):
"""Changes the bot's 'playing' status""" """Changes the bot's 'playing' status"""
await self.bot.change_presence(activity=discord.Game(name=status, type=0)) await ctx.bot.change_presence(activity=discord.Game(name=status, type=0))
await ctx.send("Just changed my status to '{}'!".format(status)) await ctx.send("Just changed my status to '{}'!".format(status))
@commands.command() @commands.command()
@ -228,7 +225,7 @@ class Owner:
# This try catch will catch errors such as syntax errors in the module we are loading # This try catch will catch errors such as syntax errors in the module we are loading
try: try:
self.bot.load_extension(module) ctx.bot.load_extension(module)
await ctx.send("I have just loaded the {} module".format(module)) await ctx.send("I have just loaded the {} module".format(module))
except Exception as error: except Exception as error:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
@ -243,7 +240,7 @@ class Owner:
if not module.startswith("cogs"): if not module.startswith("cogs"):
module = "cogs.{}".format(module) module = "cogs.{}".format(module)
self.bot.unload_extension(module) ctx.bot.unload_extension(module)
await ctx.send("I have just unloaded the {} module".format(module)) await ctx.send("I have just unloaded the {} module".format(module))
@commands.command() @commands.command()
@ -254,11 +251,11 @@ class Owner:
module = module.lower() module = module.lower()
if not module.startswith("cogs"): if not module.startswith("cogs"):
module = "cogs.{}".format(module) module = "cogs.{}".format(module)
self.bot.unload_extension(module) ctx.bot.unload_extension(module)
# This try block will catch errors such as syntax errors in the module we are loading # This try block will catch errors such as syntax errors in the module we are loading
try: try:
self.bot.load_extension(module) ctx.bot.load_extension(module)
await ctx.send("I have just reloaded the {} module".format(module)) await ctx.send("I have just reloaded the {} module".format(module))
except Exception as error: except Exception as error:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'

View file

@ -1,9 +1,10 @@
import asyncio import asyncio
import discord import discord
import traceback import traceback
import utils import utils
from discord.ext import commands
BASE_URL = 'https://api.picarto.tv/v1' BASE_URL = 'https://api.picarto.tv/v1'
@ -21,7 +22,7 @@ def produce_embed(*channels):
return discord.Embed(title="Channels that have gone online!", description=description.strip()) return discord.Embed(title="Channels that have gone online!", description=description.strip())
class Picarto: class Picarto(commands.Cog):
"""Pretty self-explanatory""" """Pretty self-explanatory"""
def __init__(self, bot): def __init__(self, bot):

View file

@ -1,4 +1,5 @@
from discord.ext import commands from discord.ext import commands
import utils import utils
@ -35,7 +36,7 @@ class Poll:
await self.message.remove_reaction(r, member) await self.message.remove_reaction(r, member)
class Polls: class Polls(commands.Cog):
"""Create custom polls that can be tracked through reactions""" """Create custom polls that can be tracked through reactions"""
def __init__(self, bot): def __init__(self, bot):
@ -65,6 +66,7 @@ class Polls:
if p.message.id == message.id: if p.message.id == message.id:
return p return p
@commands.Cog.listener
async def on_reaction_add(self, reaction, user): async def on_reaction_add(self, reaction, user):
if user.id == self.bot.user.id: if user.id == self.bot.user.id:
return return

View file

@ -9,12 +9,9 @@ import asyncio
import random import random
class Raffle: class Raffle(commands.Cog):
"""Used to hold custom raffles""" """Used to hold custom raffles"""
raffles = defaultdict(list)
def __init__(self, bot):
self.bot = bot
self.raffles = defaultdict(list)
def create_raffle(self, ctx, title, num): def create_raffle(self, ctx, title, num):
raffle = GuildRaffle(ctx, title, num) raffle = GuildRaffle(ctx, title, num)
@ -83,7 +80,7 @@ class Raffle:
check = lambda m: m.author == author and m.channel == channel check = lambda m: m.author == author and m.channel == channel
try: try:
msg = await self.bot.wait_for('message', check=check, timeout=120) msg = await ctx.bot.wait_for('message', check=check, timeout=120)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long! >:c") await ctx.send("You took too long! >:c")
return return
@ -103,7 +100,7 @@ class Raffle:
return False return False
try: try:
msg = await self.bot.wait_for('message', timeout=120, check=check) msg = await ctx.bot.wait_for('message', timeout=120, check=check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long! >:c") await ctx.send("You took too long! >:c")
return return

View file

@ -7,12 +7,9 @@ import re
import asyncio import asyncio
class Roles: class Roles(commands.Cog):
"""Class to handle management of roles on the server""" """Class to handle management of roles on the server"""
def __init__(self, bot):
self.bot = bot
@commands.command(aliases=['color']) @commands.command(aliases=['color'])
@commands.guild_only() @commands.guild_only()
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
@ -125,7 +122,7 @@ class Roles:
if len(members) == 0: if len(members) == 0:
await ctx.send("Please provide the list of members you want to remove a role from") await ctx.send("Please provide the list of members you want to remove a role from")
try: try:
msg = await self.bot.wait_for('message', check=check, timeout=60) msg = await ctx.bot.wait_for('message', check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -141,7 +138,7 @@ class Roles:
"Here is a list of this server's roles:" "Here is a list of this server's roles:"
"```\n{}```".format("\n".join([r.name for r in server_roles]))) "```\n{}```".format("\n".join([r.name for r in server_roles])))
try: try:
msg = await self.bot.wait_for('message', check=check, timeout=60) msg = await ctx.bot.wait_for('message', check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -188,7 +185,7 @@ class Roles:
if len(members) == 0: if len(members) == 0:
await ctx.send("Please provide the list of members you want to add a role to") await ctx.send("Please provide the list of members you want to add a role to")
try: try:
msg = await self.bot.wait_for('message', check=check, timeout=60) msg = await ctx.bot.wait_for('message', check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -202,7 +199,7 @@ class Roles:
"Here is a list of this server's roles:" "Here is a list of this server's roles:"
"```\n{}```".format("\n".join([r.name for r in server_roles]))) "```\n{}```".format("\n".join([r.name for r in server_roles])))
try: try:
msg = await self.bot.wait_for('message', check=check, timeout=60) msg = await ctx.bot.wait_for('message', check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -253,7 +250,7 @@ class Roles:
return False return False
try: try:
msg = await self.bot.wait_for('message', timeout=60, check=check) msg = await ctx.bot.wait_for('message', timeout=60, check=check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -309,7 +306,7 @@ class Roles:
await ctx.send( await ctx.send(
"Alright! I'm ready to create a new role, please respond with the name of the role you want to create") "Alright! I'm ready to create a new role, please respond with the name of the role you want to create")
try: try:
msg = await self.bot.wait_for('message', timeout=60.0, check=author_check) msg = await ctx.bot.wait_for('message', timeout=60.0, check=author_check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -324,7 +321,7 @@ class Roles:
# For this we're going to give a couple extra minutes before we timeout # For this we're going to give a couple extra minutes before we timeout
# as it might take a bit to figure out which permissions they want # as it might take a bit to figure out which permissions they want
try: try:
msg = await self.bot.wait_for('message', timeout=180.0, check=num_seperated_check) msg = await ctx.bot.wait_for('message', timeout=180.0, check=num_seperated_check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -335,7 +332,7 @@ class Roles:
# Check if this role should be in a separate section on the sidebard, i.e. hoisted # Check if this role should be in a separate section on the sidebard, i.e. hoisted
await ctx.send("Do you want this role to be in a separate section on the sidebar? (yes or no)") await ctx.send("Do you want this role to be in a separate section on the sidebar? (yes or no)")
try: try:
msg = await self.bot.wait_for('message', timeout=60.0, check=yes_no_check) msg = await ctx.bot.wait_for('message', timeout=60.0, check=yes_no_check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -344,7 +341,7 @@ class Roles:
# Check if this role should be able to be mentioned # Check if this role should be able to be mentioned
await ctx.send("Do you want this role to be mentionable? (yes or no)") await ctx.send("Do you want this role to be mentionable? (yes or no)")
try: try:
msg = await self.bot.wait_for('message', timeout=60.0, check=yes_no_check) msg = await ctx.bot.wait_for('message', timeout=60.0, check=yes_no_check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long. I'm impatient, don't make me wait") await ctx.send("You took too long. I'm impatient, don't make me wait")
return return
@ -368,7 +365,7 @@ class Roles:
await ctx.send("We did it! You just created the new role {}\nIf you want to add this role" await ctx.send("We did it! You just created the new role {}\nIf you want to add this role"
" to some people, mention them now".format(role.name)) " to some people, mention them now".format(role.name))
try: try:
msg = await self.bot.wait_for('message', timeout=60.0, check=members_check) msg = await ctx.bot.wait_for('message', timeout=60.0, check=members_check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
# There's no need to mention the users, so don't send a failure message if they didn't, just return # There's no need to mention the users, so don't send a failure message if they didn't, just return
return return

View file

@ -8,12 +8,9 @@ from discord.ext import commands
import utils import utils
class Roulette: class Roulette(commands.Cog):
"""A fun game that ends in someone getting kicked!""" """A fun game that ends in someone getting kicked!"""
roulettes = []
def __init__(self, bot):
self.bot = bot
self.roulettes = []
def get_game(self, server): def get_game(self, server):
for x in self.roulettes: for x in self.roulettes:

View file

@ -413,7 +413,7 @@ class Game:
self.players.append(p) self.players.append(p)
class Spades: class Spades(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.pending_game = None self.pending_game = None
@ -446,7 +446,7 @@ class Spades:
g.join(author) g.join(author)
self.pending_game = g self.pending_game = g
def __unload(self): def cog_unload(self):
# Simply cancel every task # Simply cancel every task
for _, task in self.games: for _, task in self.games:
task.cancel() task.cancel()

View file

@ -8,7 +8,7 @@ from base64 import urlsafe_b64encode
import utils import utils
class Spotify: class Spotify(commands.Cog):
"""Pretty self-explanatory""" """Pretty self-explanatory"""
def __init__(self, bot): def __init__(self, bot):

View file

@ -6,7 +6,7 @@ import datetime
from discord.ext import commands from discord.ext import commands
class Stats: class Stats(commands.Cog):
"""Leaderboard/stats related commands""" """Leaderboard/stats related commands"""
def __init__(self, bot): def __init__(self, bot):
@ -177,7 +177,7 @@ ORDER BY
LIMIT 1 LIMIT 1
""" """
members = [m.id for m in ctx.guild.members] members = [m.id for m in ctx.guild.members]
most = await self.bot.db.fetchrow(query, ctx.author.id, members) most = await ctx.bot.db.fetchrow(query, ctx.author.id, members)
if most is None or len(most) == 0: if most is None or len(most) == 0:
await ctx.send(f"You have not booped anyone in this server {ctx.author.mention}") await ctx.send(f"You have not booped anyone in this server {ctx.author.mention}")
@ -212,7 +212,7 @@ LIMIT 10
""" """
members = [m.id for m in ctx.guild.members] members = [m.id for m in ctx.guild.members]
most = await self.bot.db.fetch(query, ctx.author.id, members) most = await ctx.bot.db.fetch(query, ctx.author.id, members)
if len(most) != 0: if len(most) != 0:
embed = discord.Embed(title="Your booped victims", colour=ctx.author.colour) embed = discord.Embed(title="Your booped victims", colour=ctx.author.colour)
@ -244,7 +244,7 @@ ORDER BY
battle_rating DESC battle_rating DESC
""" """
results = await self.bot.db.fetch(query, [m.id for m in ctx.guild.members]) results = await ctx.bot.db.fetch(query, [m.id for m in ctx.guild.members])
if len(results) == 0: if len(results) == 0:
await ctx.send("No one has battled on this server!") await ctx.send("No one has battled on this server!")
@ -291,7 +291,7 @@ WHERE id = $2
member_list = [m.id for m in ctx.guild.members] member_list = [m.id for m in ctx.guild.members]
result = await ctx.bot.db.fetch(query, member_list, member.id) result = await ctx.bot.db.fetch(query, member_list, member.id)
server_rank = result["rank"] server_rank = result["rank"]
# overall_rank = "{}/{}".format(*self.bot.br.get_rank(member)) # overall_rank = "{}/{}".format(*ctx.bot.br.get_rank(member))
rating = result["battle_rating"] rating = result["battle_rating"]
record = f"{result['battle_wins']} - {result['battle_losses']}" record = f"{result['battle_wins']} - {result['battle_losses']}"

View file

@ -6,12 +6,9 @@ import utils
import asyncio import asyncio
class Tags: class Tags(commands.Cog):
"""This class contains all the commands for custom tags""" """This class contains all the commands for custom tags"""
def __init__(self, bot):
self.bot = bot
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
@ -20,7 +17,7 @@ class Tags:
EXAMPLE: !tags EXAMPLE: !tags
RESULT: All tags setup on this server""" RESULT: All tags setup on this server"""
tags = await self.bot.db.fetch("SELECT trigger FROM tags WHERE guild=$1", ctx.guild.id) tags = await ctx.bot.db.fetch("SELECT trigger FROM tags WHERE guild=$1", ctx.guild.id)
if len(tags) > 0: if len(tags) > 0:
entries = [t['trigger'] for t in tags] entries = [t['trigger'] for t in tags]
@ -37,7 +34,7 @@ class Tags:
EXAMPLE: !mytags EXAMPLE: !mytags
RESULT: All your tags setup on this server""" RESULT: All your tags setup on this server"""
tags = await self.bot.db.fetch( tags = await ctx.bot.db.fetch(
"SELECT trigger FROM tags WHERE guild=$1 AND creator=$2", "SELECT trigger FROM tags WHERE guild=$1 AND creator=$2",
ctx.guild.id, ctx.guild.id,
ctx.author.id ctx.author.id
@ -59,7 +56,7 @@ class Tags:
EXAMPLE: !tag butts EXAMPLE: !tag butts
RESULT: Whatever you setup for the butts tag!!""" RESULT: Whatever you setup for the butts tag!!"""
tag = await self.bot.db.fetchrow( tag = await ctx.bot.db.fetchrow(
"SELECT id, result FROM tags WHERE guild=$1 AND trigger=$2", "SELECT id, result FROM tags WHERE guild=$1 AND trigger=$2",
ctx.guild.id, ctx.guild.id,
tag.lower().strip() tag.lower().strip()
@ -67,7 +64,7 @@ class Tags:
if tag: if tag:
await ctx.send("\u200B{}".format(tag['result'])) await ctx.send("\u200B{}".format(tag['result']))
await self.bot.db.execute("UPDATE tags SET uses = uses + 1 WHERE id = $1", tag['id']) await ctx.bot.db.execute("UPDATE tags SET uses = uses + 1 WHERE id = $1", tag['id'])
else: else:
await ctx.send("There is no tag called {}".format(tag)) await ctx.send("There is no tag called {}".format(tag))
@ -86,7 +83,7 @@ class Tags:
my_msg = await ctx.send("Ready to setup a new tag! What do you want the trigger for the tag to be?") my_msg = await ctx.send("Ready to setup a new tag! What do you want the trigger for the tag to be?")
try: try:
msg = await self.bot.wait_for("message", check=check, timeout=60) msg = await ctx.bot.wait_for("message", check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long!") await ctx.send("You took too long!")
return return
@ -102,7 +99,7 @@ class Tags:
"Current forbidden tag triggers are: \n{}".format("\n".join(forbidden_tags))) "Current forbidden tag triggers are: \n{}".format("\n".join(forbidden_tags)))
return return
tag = await self.bot.db.fetchrow( tag = await ctx.bot.db.fetchrow(
"SELECT result FROM tags WHERE guild=$1 AND trigger=$2", "SELECT result FROM tags WHERE guild=$1 AND trigger=$2",
ctx.guild.id, ctx.guild.id,
trigger.lower().strip() trigger.lower().strip()
@ -122,7 +119,7 @@ class Tags:
trigger)) trigger))
try: try:
msg = await self.bot.wait_for("message", check=check, timeout=60) msg = await ctx.bot.wait_for("message", check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long!") await ctx.send("You took too long!")
return return
@ -135,7 +132,7 @@ class Tags:
pass pass
await ctx.send("I have just setup a new tag for this server! You can call your tag with {}".format(trigger)) await ctx.send("I have just setup a new tag for this server! You can call your tag with {}".format(trigger))
await self.bot.db.execute( await ctx.bot.db.execute(
"INSERT INTO tags(guild, creator, trigger, result) VALUES ($1, $2, $3, $4)", "INSERT INTO tags(guild, creator, trigger, result) VALUES ($1, $2, $3, $4)",
ctx.guild.id, ctx.guild.id,
ctx.author.id, ctx.author.id,
@ -153,7 +150,7 @@ class Tags:
def check(m): def check(m):
return m.channel == ctx.message.channel and m.author == ctx.message.author and len(m.content) > 0 return m.channel == ctx.message.channel and m.author == ctx.message.author and len(m.content) > 0
tag = await self.bot.db.fetchrow( tag = await ctx.bot.db.fetchrow(
"SELECT id, trigger FROM tags WHERE guild=$1 AND creator=$2 AND trigger=$3", "SELECT id, trigger FROM tags WHERE guild=$1 AND creator=$2 AND trigger=$3",
ctx.guild.id, ctx.guild.id,
ctx.author.id, ctx.author.id,
@ -163,7 +160,7 @@ class Tags:
if tag: if tag:
my_msg = await ctx.send(f"Alright, what do you want the new result for the tag {tag} to be") my_msg = await ctx.send(f"Alright, what do you want the new result for the tag {tag} to be")
try: try:
msg = await self.bot.wait_for("message", check=check, timeout=60) msg = await ctx.bot.wait_for("message", check=check, timeout=60)
except asyncio.TimeoutError: except asyncio.TimeoutError:
await ctx.send("You took too long!") await ctx.send("You took too long!")
return return
@ -177,7 +174,7 @@ class Tags:
pass pass
await ctx.send(f"Alright, the tag {trigger} has been updated") await ctx.send(f"Alright, the tag {trigger} has been updated")
await self.bot.db.execute("UPDATE tags SET result=$1 WHERE id=$2", new_result, tag['id']) await ctx.bot.db.execute("UPDATE tags SET result=$1 WHERE id=$2", new_result, tag['id'])
else: else:
await ctx.send(f"You do not have a tag called {trigger} on this server!") await ctx.send(f"You do not have a tag called {trigger} on this server!")
@ -191,7 +188,7 @@ class Tags:
EXAMPLE: !tag delete stupid_tag EXAMPLE: !tag delete stupid_tag
RESULT: Deletes that stupid tag""" RESULT: Deletes that stupid tag"""
tag = await self.bot.db.fetchrow( tag = await ctx.bot.db.fetchrow(
"SELECT id FROM tags WHERE guild=$1 AND creator=$2 AND trigger=$3", "SELECT id FROM tags WHERE guild=$1 AND creator=$2 AND trigger=$3",
ctx.guild.id, ctx.guild.id,
ctx.author.id, ctx.author.id,
@ -200,7 +197,7 @@ class Tags:
if tag: if tag:
await ctx.send(f"I have just deleted the tag {trigger}") await ctx.send(f"I have just deleted the tag {trigger}")
await self.bot.db.execute("DELETE FROM tags WHERE id=$1", tag['id']) await ctx.bot.db.execute("DELETE FROM tags WHERE id=$1", tag['id'])
else: else:
await ctx.send(f"You do not own a tag called {trigger} on this server!") await ctx.send(f"You do not own a tag called {trigger} on this server!")
@ -210,7 +207,7 @@ class Tags:
async def info_tag(self, ctx, *, trigger: str): async def info_tag(self, ctx, *, trigger: str):
"""Shows some information a bout the tag given""" """Shows some information a bout the tag given"""
tag = await self.bot.db.fetchrow( tag = await ctx.bot.db.fetchrow(
"SELECT creator, uses, trigger FROM tags WHERE guild=$1 AND trigger=$2", "SELECT creator, uses, trigger FROM tags WHERE guild=$1 AND trigger=$2",
ctx.guild.id, ctx.guild.id,
trigger trigger

View file

@ -97,12 +97,9 @@ class Board:
return "```\n{}```".format(_board) return "```\n{}```".format(_board)
class TicTacToe: class TicTacToe(commands.Cog):
"""Pretty self-explanatory""" """Pretty self-explanatory"""
boards = {}
def __init__(self, bot):
self.bot = bot
self.boards = {}
def create(self, server_id, player1, player2): def create(self, server_id, player1, player2):
self.boards[server_id] = Board(player1, player2) self.boards[server_id] = Board(player1, player2)
@ -193,7 +190,7 @@ class TicTacToe:
await ctx.send("{} has won this game of TicTacToe, better luck next time {}".format(winner.display_name, await ctx.send("{} has won this game of TicTacToe, better luck next time {}".format(winner.display_name,
loser.display_name)) loser.display_name))
# Handle updating ratings based on the winner and loser # Handle updating ratings based on the winner and loser
await utils.update_records('tictactoe', self.bot.db, winner, loser) await utils.update_records('tictactoe', ctx.bot.db, winner, loser)
# This game has ended, delete it so another one can be made # This game has ended, delete it so another one can be made
del self.boards[ctx.message.guild.id] del self.boards[ctx.message.guild.id]
else: else:

View file

@ -4,11 +4,8 @@ import utils
import discord import discord
class Tutorial:
def __init__(self, bot):
self.bot = bot
class Tutorial(commands.Cog):
@commands.command() @commands.command()
# @utils.can_run(send_messages=True) # @utils.can_run(send_messages=True)
async def tutorial(self, ctx, *, cmd_or_cog = None): async def tutorial(self, ctx, *, cmd_or_cog = None):
@ -18,17 +15,17 @@ class Tutorial:
# The list of commands we need to run through # The list of commands we need to run through
commands = [] commands = []
if cmd_or_cog: if cmd_or_cog:
cmd = self.bot.get_command(cmd_or_cog.lower()) cmd = ctx.bot.get_command(cmd_or_cog.lower())
# This should be a cog # This should be a cog
if cmd is None: if cmd is None:
cog = self.bot.get_cog(cmd_or_cog.title()) cog = ctx.bot.get_cog(cmd_or_cog.title())
if cog is None: if cog is None:
await ctx.send("Could not find a command or a cog for {}".format(cmd_or_cog)) await ctx.send("Could not find a command or a cog for {}".format(cmd_or_cog))
return return
commands = set([ commands = set([
c c
for c in self.bot.walk_commands() for c in ctx.bot.walk_commands()
if c.cog_name == cmd_or_cog.title() if c.cog_name == cmd_or_cog.title()
]) ])
# Specific command # Specific command
@ -36,7 +33,7 @@ class Tutorial:
commands = [cmd] commands = [cmd]
# Use all commands # Use all commands
else: else:
commands = set(self.bot.walk_commands()) commands = set(ctx.bot.walk_commands())
# Loop through all the commands that we want to use # Loop through all the commands that we want to use
for command in commands: for command in commands: