Skip to content

Commit

Permalink
Upgrade discord.py version
Browse files Browse the repository at this point in the history
  • Loading branch information
DXsmiley committed Oct 12, 2019
1 parent 4fdbd11 commit af6fe9e
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 34 deletions.
3 changes: 2 additions & 1 deletion Pipfile
Expand Up @@ -10,7 +10,7 @@ sympy = "*"
aioredis = "==1.2.0"
coverage = "*"
expiringdict = {git = "https://github.com/mailgun/expiringdict.git", ref = "2fa0e533c2737e89ccaf66e72b497f5a654d2607"}
"discord.py" = {git = "https://github.com/Rapptz/discord.py", ref = "7f4c57dd5ad20b7fa10aea485f674a4bc24b9547"}
"discord.py" = "==1.2.3"
psutil = "*"
xmltodict = "*"
Markdown = "*"
Expand All @@ -23,6 +23,7 @@ pytest-asyncio = "*"
pytest-cov = "*"
pytest-ordering = "*"
pytest-quickcheck = "==0.8.3"
dismock = {git = "https://github.com/RenanMsV/dismock.git", ref = "8615119682a543ee2ebdb84646eb415f2c2729f8"}

[requires]
python_version = "3.6"
2 changes: 2 additions & 0 deletions mathbot/bot.py
Expand Up @@ -81,10 +81,12 @@ async def on_message(self, message):
perms.read_message_history,
]
if not context.valid:
# dispatch a custom event
self.dispatch('message_discarded', message)
elif not all(required):
await message.channel.send(REQUIRED_PERMISSIONS_MESSAGE)
else:
# Use d.py to invoke the actual command handler
context.send = self.send_patch(message, context.send)
await self.invoke(context)

Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/about.py
Expand Up @@ -6,7 +6,7 @@
import aiohttp
import datetime
import core.help
from discord.ext.commands import command
from discord.ext.commands import command, Cog
import codecs
from modules.reporter import report
from core.settings import command_allowed
Expand Down Expand Up @@ -37,7 +37,7 @@ async def get_bot_total_servers(id):
return jdata.get('server_count')


class AboutModule:
class AboutModule(Cog):

# Send a message detailing the shard number, server count,
# uptime and and memory using of this shard
Expand Down
3 changes: 2 additions & 1 deletion mathbot/modules/analytics.py
Expand Up @@ -10,7 +10,7 @@
(BOTS_GG_URL, 'bots-gg', 'guildCount', 'shardCount', 'shardId')
]

class AnalyticsModule:
class AnalyticsModule(Cog):

def __init__(self, bot):
self.bot = bot
Expand Down Expand Up @@ -39,6 +39,7 @@ async def identify_bot_farms(self):
server.name
))

@Cog.listener()
async def on_ready(self):
num_servers = len(self.bot.guilds)
num_shards = self.bot.parameters.get('shards total')
Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/blame.py
Expand Up @@ -6,12 +6,12 @@

import core.help
from core.util import respond
from discord.ext.commands import command
from discord.ext.commands import command, Cog
from discord import Embed, Colour
import json


class BlameModule:
class BlameModule(Cog):

@command()
@respond
Expand Down
5 changes: 3 additions & 2 deletions mathbot/modules/calcmod.py
Expand Up @@ -23,7 +23,7 @@
import abc
import functools

from discord.ext.commands import command, guild_only, has_permissions
from discord.ext.commands import command, guild_only, has_permissions, Cog

core.help.load_from_file('./help/calculator_brief.md')
core.help.load_from_file('./help/calculator_full.md')
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(self):
ENABLE_HISTORY = True


class CalculatorModule():
class CalculatorModule(Cog):

__slots__ = ['bot', 'command_history', 'replay_state']

Expand Down Expand Up @@ -215,6 +215,7 @@ async def handle_calc_reload(self, ctx):
del self.replay_state[channel]
await ctx.send('Calculator state has been flushed from this channel.')

@Cog.listener()
async def on_message_discarded(self, message):
''' Trigger the calculator when the message is prefixed by "==" '''
async def send(*args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/dice.py
Expand Up @@ -7,7 +7,7 @@
import core.help
import core.settings
import core.util
from discord.ext.commands import command
from discord.ext.commands import command, Cog
import math

core.help.load_from_file('./help/roll.md')
Expand All @@ -21,7 +21,7 @@ class DiceException(Exception): pass
class ValuesTooBigException(DiceException): pass


class DiceModule:
class DiceModule(Cog):

''' Module to allow the user to roll dice '''

Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/echo.py
@@ -1,10 +1,10 @@
# Has a command which echoes whatever text was given to it.
# Used only for testing purposes.

from discord.ext.commands import command
from discord.ext.commands import command, Cog


class EchoModule:
class EchoModule(Cog):

def __init__(self, bot):
self.bot = bot
Expand Down
5 changes: 3 additions & 2 deletions mathbot/modules/heartbeat.py
Expand Up @@ -4,14 +4,15 @@
import asyncio
import discord
import traceback
from discord.ext.commands import command
from discord.ext.commands import command, Cog

class Heartbeat:
class Heartbeat(Cog):

def __init__(self, bot):
self.bot = bot
self.background_task = None

@Cog.listener()
async def on_ready(self):
self.background_task = self.bot.loop.create_task(self.pulse())

Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/help.py
Expand Up @@ -2,7 +2,7 @@

import re
import core.help
from discord.ext.commands import command
from discord.ext.commands import command, Cog
import discord
from utils import is_private

Expand All @@ -18,7 +18,7 @@ def doubleformat(string, **replacements):
return string


class HelpModule:
class HelpModule(Cog):
''' Module that serves help pages. '''

@command()
Expand Down
6 changes: 4 additions & 2 deletions mathbot/modules/latex/__init__.py
Expand Up @@ -19,7 +19,7 @@
import json
from queuedict import QueueDict
from open_relative import *
from discord.ext.commands import command
from discord.ext.commands import command, Cog
from utils import is_private, MessageEditGuard
from contextlib import suppress

Expand Down Expand Up @@ -71,7 +71,7 @@ def __repr__(self):
return f'RenderingError@{id(self)}'


class LatexModule:
class LatexModule(Cog):

def __init__(self, bot):
self.bot = bot
Expand All @@ -91,6 +91,7 @@ async def texw(self, context, *, latex=''):
async def texp(self, context, *, latex=''):
await self.handle(context.message, latex, noblock=True)

@Cog.listener()
async def on_message_discarded(self, message):
if not message.author.bot and message.content.count('$$') >= 2 and not message.content.startswith('=='):
if is_private(message.channel) or (await self.bot.settings.resolve_message('c-tex', message) and await self.bot.settings.resolve_message('f-inline-tex', message)):
Expand Down Expand Up @@ -138,6 +139,7 @@ async def render_and_reply(self, message, latex, colour_back):
with suppress(discord.errors.NotFound):
await message.delete()

@Cog.listener()
async def on_reaction_add(self, reaction, user):
if not user.bot:
if reaction.emoji == DELETE_EMOJI:
Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/oeis.py
Expand Up @@ -2,13 +2,13 @@
import json

from urllib.parse import urlencode
from discord.ext.commands import command
from discord.ext.commands import command, Cog
from core.settings import command_allowed
import core

core.help.load_from_file('./help/oeis.md')

class OEIS:
class OEIS(Cog):

@command()
@command_allowed('c-oeis')
Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/purge.py
Expand Up @@ -4,7 +4,7 @@
from utils import is_private


from discord.ext.commands import command, guild_only, has_permissions
from discord.ext.commands import command, guild_only, has_permissions, Cog

USER_PERM_ERROR = '''\
You do not have the permissions required to perform that operation in this channel.
Expand All @@ -18,7 +18,7 @@

core.help.load_from_file('./help/purge.md')

class PurgeModule:
class PurgeModule(Cog):
@command()
@guild_only()
@has_permissions(manage_messages=True)
Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/reboot.py
@@ -1,8 +1,8 @@
from discord.ext.commands import command
from discord.ext.commands import command, Cog
import subprocess
import modules.reporter

class Reboot:
class Reboot(Cog):

@command()
async def reboot(self, ctx):
Expand Down
5 changes: 4 additions & 1 deletion mathbot/modules/reporter.py
Expand Up @@ -2,6 +2,7 @@
import asyncio
import traceback
import discord
from discord.ext.commands import Cog
import termcolor

import core.keystore
Expand All @@ -10,6 +11,7 @@
import typing



# This queue is a global object, which actually means that multiple
# shards might fiddle with it. HOWEVER, this is fine since there'll
# just be multiple shards pushing from the queue to the redis store
Expand All @@ -19,12 +21,13 @@
QUEUE = collections.deque()


class ReporterModule:
class ReporterModule(Cog):

def __init__(self, bot):
self.bot = bot
self.send_task = None

@Cog.listener()
async def on_ready(self):
self.send_task = self.bot.loop.create_task(self.send_reports())
self.sent_duty_note = False
Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/settings.py
Expand Up @@ -5,7 +5,7 @@
import core.help
import core.settings

from discord.ext.commands import command, guild_only, has_permissions
from discord.ext.commands import command, guild_only, has_permissions, Cog


core.help.load_from_file('./help/settings.md')
Expand Down Expand Up @@ -47,7 +47,7 @@ class WasProblems(Exception):
pass


class SettingsModule:
class SettingsModule(Cog):

reduce_value = {
'enable': 1,
Expand Down
4 changes: 2 additions & 2 deletions mathbot/modules/throws.py
@@ -1,6 +1,6 @@
from discord.ext.commands import command
from discord.ext.commands import command, Cog

class ThrowsModule:
class ThrowsModule(Cog):

@command()
async def throw(self, context):
Expand Down
7 changes: 4 additions & 3 deletions mathbot/modules/wolfram.py
Expand Up @@ -36,7 +36,7 @@
import core.blame
from imageutil import *

from discord.ext.commands import command, check
from discord.ext.commands import command, check, Cog
from core.util import respond
from utils import is_private, image_to_discord_file

Expand Down Expand Up @@ -192,7 +192,7 @@ def guild(self):
return self.channel.guild


class WolframModule:
class WolframModule(Cog):

def __init__(self, bot):
self.bot = bot
Expand All @@ -217,6 +217,7 @@ async def command_impl(self, ctx, query, small, name):
if ok:
await self.answer_query(ctx, query, small=small)

@Cog.listener()
async def on_reaction_add(self, reaction, user):
if not user.bot: # Might need to change this when autmated testing is reinstated
if reaction.emoji == RERUN_EMOJI and await self.bot.settings.resolve_message('c-wolf', reaction.message):
Expand Down Expand Up @@ -260,7 +261,7 @@ async def delete_results(self, reaction, user):
if data is not None and user.id == data['blame']:
async def get_and_delete(i):
try:
m = await reaction.message.channel.get_message(i)
m = await reaction.message.channel.fetch_message(i)
await m.delete()
except discord.errors.NotFound:
pass
Expand Down
5 changes: 3 additions & 2 deletions mathbot/patrons.py
@@ -1,4 +1,4 @@
from discord.ext.commands import command
from discord.ext.commands import command, Cog
import discord

TIER_NONE = 0
Expand All @@ -23,7 +23,7 @@ async def get_patron_listing(self):
return (await self.keystore.get('patron', 'listing')) or 'nobody?'


class PatronModule:
class PatronModule(Cog):

def __init__(self, bot):
self.bot = bot
Expand All @@ -38,6 +38,7 @@ async def check_patronage(self, ctx):
m.append(f'The patrongage of this server\'s owner is {get_tier_name(tier)}')
await ctx.send('\n'.join(m))

@Cog.listener()
async def on_ready(self):
guild = self.bot.get_guild(233826358369845251)
listing = []
Expand Down

0 comments on commit af6fe9e

Please sign in to comment.