revert lists
This commit is contained in:
parent
38d4c0ec1b
commit
507b413cd1
@ -32,13 +32,9 @@ import aiohttp
|
|||||||
import platform
|
import platform
|
||||||
|
|
||||||
def show_version():
|
def show_version():
|
||||||
entries = [
|
entries = []
|
||||||
'- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(
|
|
||||||
sys.version_info
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
|
entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info))
|
||||||
version_info = discord.version_info
|
version_info = discord.version_info
|
||||||
entries.append('- discord.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info))
|
entries.append('- discord.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info))
|
||||||
if version_info.releaselevel != 'final':
|
if version_info.releaselevel != 'final':
|
||||||
@ -55,7 +51,7 @@ def core(parser, args):
|
|||||||
if args.version:
|
if args.version:
|
||||||
show_version()
|
show_version()
|
||||||
|
|
||||||
_bot_template = """#!/usr/bin/env python3
|
bot_template = """#!/usr/bin/env python3
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import discord
|
import discord
|
||||||
@ -68,10 +64,10 @@ class Bot(commands.{base}):
|
|||||||
try:
|
try:
|
||||||
self.load_extension(cog)
|
self.load_extension(cog)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(f'Could not load extension {{cog}} due to {{exc.__class__.__name__}}: {{exc}}')
|
print('Could not load extension {{0}} due to {{1.__class__.__name__}}: {{1}}'.format(cog, exc))
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print(f'Logged on as {{self.user}} (ID: {{self.user.id}})')
|
print('Logged on as {{0}} (ID: {{0.id}})'.format(self.user))
|
||||||
|
|
||||||
|
|
||||||
bot = Bot()
|
bot = Bot()
|
||||||
@ -81,7 +77,7 @@ bot = Bot()
|
|||||||
bot.run(config.token)
|
bot.run(config.token)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_gitignore_template = """# Byte-compiled / optimized / DLL files
|
gitignore_template = """# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
@ -111,7 +107,7 @@ var/
|
|||||||
config.py
|
config.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_cog_template = '''from discord.ext import commands
|
cog_template = '''from discord.ext import commands
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
class {name}(commands.Cog{attrs}):
|
class {name}(commands.Cog{attrs}):
|
||||||
@ -124,7 +120,7 @@ def setup(bot):
|
|||||||
bot.add_cog({name}(bot))
|
bot.add_cog({name}(bot))
|
||||||
'''
|
'''
|
||||||
|
|
||||||
_cog_extras = '''
|
cog_extras = '''
|
||||||
def cog_unload(self):
|
def cog_unload(self):
|
||||||
# clean up logic goes here
|
# clean up logic goes here
|
||||||
pass
|
pass
|
||||||
@ -174,7 +170,7 @@ _base_table = {
|
|||||||
# NUL (0) and 1-31 are disallowed
|
# NUL (0) and 1-31 are disallowed
|
||||||
_base_table.update((chr(i), None) for i in range(32))
|
_base_table.update((chr(i), None) for i in range(32))
|
||||||
|
|
||||||
_translation_table = str.maketrans(_base_table)
|
translation_table = str.maketrans(_base_table)
|
||||||
|
|
||||||
def to_path(parser, name, *, replace_spaces=False):
|
def to_path(parser, name, *, replace_spaces=False):
|
||||||
if isinstance(name, Path):
|
if isinstance(name, Path):
|
||||||
@ -186,7 +182,7 @@ def to_path(parser, name, *, replace_spaces=False):
|
|||||||
if len(name) <= 4 and name.upper() in forbidden:
|
if len(name) <= 4 and name.upper() in forbidden:
|
||||||
parser.error('invalid directory name given, use a different one')
|
parser.error('invalid directory name given, use a different one')
|
||||||
|
|
||||||
name = name.translate(_translation_table)
|
name = name.translate(translation_table)
|
||||||
if replace_spaces:
|
if replace_spaces:
|
||||||
name = name.replace(' ', '-')
|
name = name.replace(' ', '-')
|
||||||
return Path(name)
|
return Path(name)
|
||||||
@ -219,14 +215,14 @@ def newbot(parser, args):
|
|||||||
try:
|
try:
|
||||||
with open(str(new_directory / 'bot.py'), 'w', encoding='utf-8') as fp:
|
with open(str(new_directory / 'bot.py'), 'w', encoding='utf-8') as fp:
|
||||||
base = 'Bot' if not args.sharded else 'AutoShardedBot'
|
base = 'Bot' if not args.sharded else 'AutoShardedBot'
|
||||||
fp.write(_bot_template.format(base=base, prefix=args.prefix))
|
fp.write(bot_template.format(base=base, prefix=args.prefix))
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
parser.error(f'could not create bot file ({exc})')
|
parser.error(f'could not create bot file ({exc})')
|
||||||
|
|
||||||
if not args.no_git:
|
if not args.no_git:
|
||||||
try:
|
try:
|
||||||
with open(str(new_directory / '.gitignore'), 'w', encoding='utf-8') as fp:
|
with open(str(new_directory / '.gitignore'), 'w', encoding='utf-8') as fp:
|
||||||
fp.write(_gitignore_template)
|
fp.write(gitignore_template)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
print(f'warning: could not create .gitignore file ({exc})')
|
print(f'warning: could not create .gitignore file ({exc})')
|
||||||
|
|
||||||
@ -244,7 +240,7 @@ def newcog(parser, args):
|
|||||||
try:
|
try:
|
||||||
with open(str(directory), 'w', encoding='utf-8') as fp:
|
with open(str(directory), 'w', encoding='utf-8') as fp:
|
||||||
attrs = ''
|
attrs = ''
|
||||||
extra = _cog_extras if args.full else ''
|
extra = cog_extras if args.full else ''
|
||||||
if args.class_name:
|
if args.class_name:
|
||||||
name = args.class_name
|
name = args.class_name
|
||||||
else:
|
else:
|
||||||
@ -259,7 +255,7 @@ def newcog(parser, args):
|
|||||||
attrs += f', name="{args.display_name}"'
|
attrs += f', name="{args.display_name}"'
|
||||||
if args.hide_commands:
|
if args.hide_commands:
|
||||||
attrs += ', command_attrs=dict(hidden=True)'
|
attrs += ', command_attrs=dict(hidden=True)'
|
||||||
fp.write(_cog_template.format(name=name, extra=extra, attrs=attrs))
|
fp.write(cog_template.format(name=name, extra=extra, attrs=attrs))
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
parser.error(f'could not create cog file ({exc})')
|
parser.error(f'could not create cog file ({exc})')
|
||||||
else:
|
else:
|
||||||
|
@ -629,12 +629,10 @@ class BotBase(GroupMixin):
|
|||||||
|
|
||||||
# remove all the listeners from the module
|
# remove all the listeners from the module
|
||||||
for event_list in self.extra_events.copy().values():
|
for event_list in self.extra_events.copy().values():
|
||||||
remove = [
|
remove = []
|
||||||
index
|
for index, event in enumerate(event_list):
|
||||||
for index, event in enumerate(event_list)
|
if event.__module__ is not None and _is_submodule(name, event.__module__):
|
||||||
if event.__module__ is not None
|
remove.append(index)
|
||||||
and _is_submodule(name, event.__module__)
|
|
||||||
]
|
|
||||||
|
|
||||||
for index in reversed(remove):
|
for index in reversed(remove):
|
||||||
del event_list[index]
|
del event_list[index]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user