aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNCPlayz <[email protected]>2019-02-25 18:25:38 +0000
committerRapptz <[email protected]>2019-02-26 08:41:00 -0500
commit11a00982699ab593e4b09600bdf1d4c1f770684e (patch)
tree4cf25d64accb310b119f0aef88ff81afd6f697d4
parentUpdate Japanese .po files. (diff)
downloaddiscord.py-11a00982699ab593e4b09600bdf1d4c1f770684e.tar.xz
discord.py-11a00982699ab593e4b09600bdf1d4c1f770684e.zip
Add new cog methods
Added two new arguments to the parser, and updated defunct cog code. Remove debug remove print statement
-rw-r--r--discord/__main__.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/discord/__main__.py b/discord/__main__.py
index 698211c7..495f8b61 100644
--- a/discord/__main__.py
+++ b/discord/__main__.py
@@ -95,7 +95,7 @@ cog_template = '''# -*- coding: utf-8 -*-
from discord.ext import commands
import discord
-class {name}:
+class {name}(commands.Cog{attrs}):
"""The description for {name} goes here."""
def __init__(self, bot):
@@ -106,31 +106,31 @@ def setup(bot):
'''
cog_extras = '''
- def __unload(self):
+ def cog_unload(self):
# clean up logic goes here
pass
- async def __local_check(self, ctx):
+ async def cog_check(self, ctx):
# checks that apply to every command in here
return True
- async def __global_check(self, ctx):
+ async def bot_check(self, ctx):
# checks that apply to every command to the bot
return True
- async def __global_check_once(self, ctx):
+ async def bot_check_once(self, ctx):
# check that apply to every command but is guaranteed to be called only once
return True
- async def __error(self, ctx, error):
+ async def cog_command_error(self, ctx, error):
# error handling to every command in here
pass
- async def __before_invoke(self, ctx):
+ async def cog_before_invoke(self, ctx):
# called before a command is called here
pass
- async def __after_invoke(self, ctx):
+ async def cog_after_invoke(self, ctx):
# called after a command is called here
pass
@@ -230,6 +230,7 @@ def newcog(parser, args):
directory = directory.with_suffix('.py')
try:
with open(str(directory), 'w', encoding='utf-8') as fp:
+ attrs = ''
extra = cog_extras if args.full else ''
if args.class_name:
name = args.class_name
@@ -239,7 +240,12 @@ def newcog(parser, args):
name = name.replace('-', ' ').title().replace(' ', '')
else:
name = name.title()
- fp.write(cog_template.format(name=name, extra=extra))
+
+ if args.display_name:
+ attrs += ', name="{}"'.format(args.display_name)
+ if args.hide_commands:
+ attrs += ', command_attrs=dict(hidden=True)'
+ fp.write(cog_template.format(name=name, extra=extra, attrs=attrs))
except OSError as exc:
parser.error('could not create cog file ({})'.format(exc))
else:
@@ -262,6 +268,8 @@ def add_newcog_args(subparser):
parser.add_argument('name', help='the cog name')
parser.add_argument('directory', help='the directory to place it in (default: cogs)', nargs='?', default=Path('cogs'))
parser.add_argument('--class-name', help='the class name of the cog (default: <name>)', dest='class_name')
+ parser.add_argument('--display-name', help='the cog name (default: <name>)')
+ parser.add_argument('--hide-commands', help='whether to hide all commands in the cog', action='store_true')
parser.add_argument('--full', help='add all special methods as well', action='store_true')
def parse_args():