Skip to content

Commit 41142a1

Browse files
committed
v1.1.1 support
1 parent e205b57 commit 41142a1

File tree

7 files changed

+37
-29
lines changed

7 files changed

+37
-29
lines changed

bot.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from motor.motor_asyncio import AsyncIOMotorClient
4747

4848
from core.changelog import Changelog
49-
from core.clients import SelfHostedClient, PluginDatabaseClient
49+
from core.clients import DatabaseClient, PluginDatabaseClient
5050
from core.config import ConfigManager
5151
from core.utils import info, error
5252
from core.models import Bot, PermissionLevel
@@ -103,9 +103,9 @@ def __init__(self):
103103
self._db = None
104104

105105
self._configure_logging()
106-
106+
# TODO: Raise fatal error if mongo_uri or other essentials are not found
107107
self._db = AsyncIOMotorClient(self.config.mongo_uri).modmail_bot
108-
self._api = SelfHostedClient(self)
108+
self._api = DatabaseClient(self)
109109
self.plugin_db = PluginDatabaseClient(self)
110110

111111
self.metadata_task = self.loop.create_task(self.metadata_loop())
@@ -563,7 +563,8 @@ async def process_modmail(self, message):
563563

564564
elif str(message.author.id) in self.blocked_users:
565565
reaction = blocked_emoji
566-
if reason.startswith('System Message: New Account.'):
566+
if reason.startswith('System Message: New Account.') or \
567+
reason.startswith('System Message: Recently Joined.'):
567568
# Met the age limit already
568569
reaction = sent_emoji
569570
del self.config.blocked[str(message.author.id)]
@@ -718,8 +719,7 @@ async def on_raw_reaction_add(self, payload):
718719
return
719720
channel = await _thread.recipient.create_dm()
720721

721-
# TODO: change to fetch_message (breaking change in d.py)
722-
message = await channel.get_message(payload.message_id)
722+
message = await channel.fetch_message(payload.message_id)
723723
reaction = payload.emoji
724724

725725
close_emoji = await self.convert_emoji(
@@ -810,6 +810,9 @@ async def on_message_delete(self, message):
810810
if message_id == url.split('/')[-1]:
811811
return await msg.delete()
812812

813+
async def on_bulk_message_delete(self, messages):
814+
await discord.utils.async_all(self.on_message_delete(msg) for msg in messages)
815+
813816
async def on_message_edit(self, before, after):
814817
if before.author.bot:
815818
return
@@ -953,7 +956,7 @@ async def metadata_loop(self):
953956
"owner_id": owner.id,
954957
"bot_id": self.user.id,
955958
"bot_name": str(self.user),
956-
"avatar_url": self.user.avatar_url,
959+
"avatar_url": str(self.user.avatar_url),
957960
"guild_id": self.guild_id,
958961
"guild_name": self.guild.name,
959962
"member_count": len(self.guild.members),

cogs/modmail.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ async def delete(self, ctx, message_id: Optional[int] = None):
818818
linked_message_id = await self.find_linked_message(ctx, message_id)
819819

820820
if linked_message_id is None:
821-
return await ctx.send(embed=discord.Embed(
821+
return await ctx.send(
822+
embed=discord.Embed(
822823
title='Failed',
823824
description='Cannot find a message to delete.',
824825
color=discord.Color.red()

cogs/plugins.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ async def load_plugin(self, username, repo, plugin_name):
111111

112112
try:
113113
self.bot.load_extension(ext)
114-
except ModuleNotFoundError as exc:
115-
raise DownloadError('Invalid plugin structure') from exc
114+
except commands.ExtensionError as exc:
115+
raise DownloadError('Invalid plugin.') from exc
116116
else:
117117
msg = f'Loaded plugins.{username}-{repo}.{plugin_name}'
118118
logger.info(info(msg))
@@ -129,10 +129,10 @@ async def plugin(self, ctx):
129129
async def plugin_add(self, ctx, *, plugin_name):
130130
"""Adds a plugin"""
131131
if plugin_name in self.bot.config.plugins:
132-
return await ctx.send('Plugin already installed')
132+
return await ctx.send('Plugin already installed.')
133133
if plugin_name in self.bot.cogs.keys():
134134
# another class with the same name
135-
return await ctx.send('Another cog exists with the same name')
135+
return await ctx.send('Another cog exists with the same name.')
136136

137137
message = await ctx.send('Downloading plugin...')
138138
async with ctx.typing():
@@ -143,14 +143,14 @@ async def plugin_add(self, ctx, *, plugin_name):
143143
await self.download_plugin_repo(*parsed_plugin[:-1])
144144
except DownloadError as exc:
145145
return await ctx.send(
146-
f'Unable to fetch plugin from Github: {exc}'
146+
f'Unable to fetch plugin from Github: {exc}.'
147147
)
148148

149149
importlib.invalidate_caches()
150150
try:
151151
await self.load_plugin(*parsed_plugin)
152152
except DownloadError as exc:
153-
return await ctx.send(f'Unable to load plugin: `{exc}`')
153+
return await ctx.send(f'Unable to load plugin: `{exc}`.')
154154

155155
# if it makes it here, it has passed all checks and should
156156
# be entered into the config
@@ -204,7 +204,7 @@ def onerror(func, path, exc_info):
204204
async def plugin_update(self, ctx, *, plugin_name):
205205
"""Updates a certain plugin"""
206206
if plugin_name not in self.bot.config.plugins:
207-
return await ctx.send('Plugin not installed')
207+
return await ctx.send('Plugin not installed.')
208208

209209
async with ctx.typing():
210210
username, repo, name = self.parse_plugin(plugin_name)
@@ -217,7 +217,7 @@ async def plugin_update(self, ctx, *, plugin_name):
217217
)
218218
except subprocess.CalledProcessError as exc:
219219
err = exc.stderr.decode('utf8').strip()
220-
await ctx.send(f'Error while updating: {err}')
220+
await ctx.send(f'Error while updating: {err}.')
221221
else:
222222
output = cmd.stdout.decode('utf8').strip()
223223
await ctx.send(f'```\n{output}\n```')
@@ -230,7 +230,7 @@ async def plugin_update(self, ctx, *, plugin_name):
230230
try:
231231
await self.load_plugin(username, repo, name)
232232
except DownloadError as exc:
233-
await ctx.send(f'Unable to start plugin: `{exc}`')
233+
await ctx.send(f'Unable to start plugin: `{exc}`.')
234234

235235
@plugin.command(name='list', aliases=['show', 'view'])
236236
@checks.has_permissions(PermissionLevel.OWNER)
@@ -240,7 +240,7 @@ async def plugin_list(self, ctx):
240240
msg = '```\n' + '\n'.join(self.bot.config.plugins) + '\n```'
241241
await ctx.send(msg)
242242
else:
243-
await ctx.send('No plugins installed')
243+
await ctx.send('No plugins installed.')
244244

245245

246246
def setup(bot):

cogs/utility.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
logger = logging.getLogger('Modmail')
2929

3030

31-
class Utility:
31+
class Utility(commands.Cog):
3232
"""General commands that provide utility."""
3333

3434
def __init__(self, bot: Bot):
@@ -40,9 +40,10 @@ async def format_cog_help(self, ctx, cog):
4040
prefix = self.bot.prefix
4141

4242
fmts = ['']
43+
# TODO: Use Utility.get_commands() / Utility.walk_commands()
4344
for perm_level, cmd in sorted(((get_perm_level(c), c) for c in self.bot.commands),
4445
key=itemgetter(0)):
45-
if cmd.instance is cog and not cmd.hidden:
46+
if cmd.cog is cog and not cmd.hidden:
4647
if perm_level is PermissionLevel.INVALID:
4748
new_fmt = f'`{prefix + cmd.qualified_name}` '
4849
else:
@@ -90,6 +91,7 @@ async def format_command_help(self, cmd):
9091
else:
9192
perm_level = ''
9293

94+
# TODO: cmd.signature broken
9395
embed = Embed(
9496
title=f'`{prefix}{cmd.signature}`',
9597
color=self.bot.main_color,
@@ -148,6 +150,7 @@ async def format_not_found(self, ctx, command):
148150
async def help_(self, ctx, *, command: str = None):
149151
"""Shows the help message."""
150152

153+
# TODO: use https://gist.github.com/Rapptz/288294ca99fa1f042f0e39a92ddd88eb
151154
if command:
152155
cmd = self.bot.get_command(command)
153156
cog = self.bot.cogs.get(command)

core/clients.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
if prefix == 'NONE':
2020
prefix = ''
2121

22+
2223
class ApiClient:
2324
"""
2425
This class represents the general request class for all type of clients.
@@ -255,7 +256,7 @@ async def login(cls, bot: Bot) -> 'GitHub':
255256
return self
256257

257258

258-
class SelfHostedClient(UserClient, ApiClient):
259+
class DatabaseClient(UserClient, ApiClient):
259260

260261
def __init__(self, bot: Bot):
261262
super().__init__(bot)
@@ -308,14 +309,14 @@ async def create_log_entry(self, recipient, channel, creator):
308309
'id': str(recipient.id),
309310
'name': recipient.name,
310311
'discriminator': recipient.discriminator,
311-
'avatar_url': recipient.avatar_url,
312+
'avatar_url': str(recipient.avatar_url),
312313
'mod': False
313314
},
314315
'creator': {
315316
'id': str(creator.id),
316317
'name': creator.name,
317318
'discriminator': creator.discriminator,
318-
'avatar_url': creator.avatar_url,
319+
'avatar_url': str(creator.avatar_url),
319320
'mod': isinstance(creator, Member)
320321
},
321322
'closer': None,
@@ -363,7 +364,7 @@ async def append_log(self, message, channel_id='', type_='thread_message'):
363364
'id': str(message.author.id),
364365
'name': message.author.name,
365366
'discriminator': message.author.discriminator,
366-
'avatar_url': message.author.avatar_url,
367+
'avatar_url': str(message.author.avatar_url),
367368
'mod': not isinstance(message.channel, DMChannel),
368369
},
369370
'content': message.content,

core/thread.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,15 @@ async def _close(self, closer, silent=False, delete_channel=True,
216216
'id': str(closer.id),
217217
'name': closer.name,
218218
'discriminator': closer.discriminator,
219-
'avatar_url': closer.avatar_url,
219+
'avatar_url': str(closer.avatar_url),
220220
'mod': True
221221
}
222222
})
223223

224224
if log_data is not None and isinstance(log_data, dict):
225225
prefix = os.getenv('LOG_URL_PREFIX', '/logs')
226-
if prefix == 'NONE': prefix = ''
226+
if prefix == 'NONE':
227+
prefix = ''
227228
log_url = f"{self.bot.config.log_url.strip('/')}{prefix}/{log_data['key']}"
228229

229230
if log_data['messages']:
@@ -703,7 +704,6 @@ def _format_info_embed(self, user, log_url, log_count, color):
703704
"""Get information about a member of a server
704705
supports users from the guild or not."""
705706
member = self.bot.guild.get_member(user.id)
706-
avi = user.avatar_url
707707
time = datetime.utcnow()
708708

709709
# key = log_url.split('/')[-1]
@@ -742,7 +742,7 @@ def _format_info_embed(self, user, log_url, log_count, color):
742742

743743
footer = 'User ID: ' + str(user.id)
744744
embed.set_footer(text=footer)
745-
embed.set_author(name=str(user), icon_url=avi, url=log_url)
745+
embed.set_author(name=str(user), icon_url=user.avatar_url, url=log_url)
746746
# embed.set_thumbnail(url=avi)
747747

748748
if member:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
git+https://github.com/Rapptz/discord.py
1+
discord.py==1.1.1
22
colorama>=0.4.0
33
python-dateutil>=2.7.0
44
emoji>=0.2

0 commit comments

Comments
 (0)