Skip to content

Commit e8eff73

Browse files
committed
v1.1.1 supported help command
1 parent 41142a1 commit e8eff73

File tree

8 files changed

+140
-150
lines changed

8 files changed

+140
-150
lines changed

bot.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from core.changelog import Changelog
4949
from core.clients import DatabaseClient, PluginDatabaseClient
5050
from core.config import ConfigManager
51-
from core.utils import info, error
51+
from core.utils import info, error, human_join
5252
from core.models import Bot, PermissionLevel
5353
from core.thread import ThreadManager
5454
from core.time import human_timedelta
@@ -167,8 +167,6 @@ async def get_prefix(self, message=None):
167167

168168
def _load_extensions(self):
169169
"""Adds commands automatically"""
170-
self.remove_command('help')
171-
172170
logger.info(LINE)
173171
logger.info(info('┌┬┐┌─┐┌┬┐┌┬┐┌─┐┬┬'))
174172
logger.info(info('││││ │ │││││├─┤││'))
@@ -834,13 +832,6 @@ async def on_error(self, event_method, *args, **kwargs):
834832
logger.error(error('Unexpected exception:'), exc_info=sys.exc_info())
835833

836834
async def on_command_error(self, ctx, exception):
837-
838-
def human_join(strings):
839-
if len(strings) <= 2:
840-
return ' or '.join(strings)
841-
else:
842-
return ', '.join(strings[:len(strings)-1]) + ' or ' + strings[-1]
843-
844835
if isinstance(exception, commands.BadUnionArgument):
845836
msg = 'Could not find the specified ' + human_join([c.__name__ for c in exception.converters])
846837
await ctx.trigger_typing()
@@ -855,12 +846,17 @@ def human_join(strings):
855846
color=discord.Color.red(),
856847
description=str(exception)
857848
))
858-
elif isinstance(exception, commands.MissingRequiredArgument):
859-
await ctx.invoke(self.get_command('help'),
860-
command=str(ctx.command))
861849
elif isinstance(exception, commands.CommandNotFound):
862850
logger.warning(error('CommandNotFound: ' + str(exception)))
851+
elif isinstance(exception, commands.MissingRequiredArgument):
852+
await ctx.send_help(ctx.command)
863853
elif isinstance(exception, commands.CheckFailure):
854+
for check in ctx.command.checks:
855+
if not await check(ctx) and hasattr(check, 'fail_msg'):
856+
await ctx.send(embed=discord.Embed(
857+
color=discord.Color.red(),
858+
description=check.fail_msg
859+
))
864860
logger.warning(error('CheckFailure: ' + str(exception)))
865861
else:
866862
logger.error(error('Unexpected exception:'), exc_info=exception)
@@ -975,9 +971,5 @@ async def metadata_loop(self):
975971

976972

977973
if __name__ == '__main__':
978-
if os.name != 'nt':
979-
import uvloop
980-
981-
uvloop.install()
982974
bot = ModmailBot()
983975
bot.run()

cogs/modmail.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,10 @@ async def snippets_remove(self, ctx, *, name: str.lower):
147147

148148
@commands.command()
149149
@checks.has_permissions(PermissionLevel.MODERATOR)
150+
@checks.thread_only()
150151
async def move(self, ctx, *, category: discord.CategoryChannel):
151152
"""Moves a thread to a specified category."""
152153
thread = ctx.thread
153-
if not thread:
154-
embed = discord.Embed(
155-
title='Error',
156-
description='This is not a Modmail thread.',
157-
color=discord.Color.red()
158-
)
159-
return await ctx.send(embed=embed)
160-
161154
await thread.channel.edit(category=category, sync_permissions=True)
162155
await ctx.message.add_reaction('✅')
163156

@@ -820,10 +813,11 @@ async def delete(self, ctx, message_id: Optional[int] = None):
820813
if linked_message_id is None:
821814
return await ctx.send(
822815
embed=discord.Embed(
823-
title='Failed',
824-
description='Cannot find a message to delete.',
825-
color=discord.Color.red()
826-
))
816+
title='Failed',
817+
description='Cannot find a message to delete.',
818+
color=discord.Color.red()
819+
)
820+
)
827821

828822
await thread.delete_message(linked_message_id)
829823
await ctx.message.add_reaction('✅')

cogs/plugins.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ async def load_plugin(self, username, repo, plugin_name):
121121
@checks.has_permissions(PermissionLevel.OWNER)
122122
async def plugin(self, ctx):
123123
"""Plugin handler. Controls the plugins in the bot."""
124-
cmd = self.bot.get_command('help')
125-
await ctx.invoke(cmd, command='plugin')
124+
await ctx.send_help(ctx.command)
126125

127126
@plugin.command(name='add')
128127
@checks.has_permissions(PermissionLevel.OWNER)

0 commit comments

Comments
 (0)