Skip to content

Commit b2341b7

Browse files
committed
Black Format
1 parent c16ac9e commit b2341b7

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

twitchio/ext/commands/bot.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
client_secret=client_secret,
6464
initial_channels=initial_channels,
6565
heartbeat=heartbeat,
66-
retain_cache = retain_cache,
66+
retain_cache=retain_cache,
6767
)
6868

6969
self._prefix = prefix
@@ -74,7 +74,6 @@ def __init__(
7474
else:
7575
self._commands = {}
7676
self._command_aliases = {}
77-
7877
self._modules: Dict[str, types.ModuleType] = {}
7978
self._cogs: Dict[str, Cog] = {}
8079
self._checks: List[Callable[[Context], Union[bool, Awaitable[bool]]]] = []
@@ -148,7 +147,6 @@ def __init__commands__(self):
148147
for _, obj in commands:
149148
if not isinstance(obj, Command):
150149
continue
151-
152150
obj._instance = self
153151

154152
try:
@@ -165,10 +163,8 @@ async def __get_prefixes__(self, message):
165163
ret = await self._prefix(self, message)
166164
else:
167165
ret = self._prefix(self, message)
168-
169166
if not isinstance(ret, (list, tuple, set, str)):
170167
raise TypeError(f"Prefix must be of either class <list, tuple, set, str> not <{type(ret)}>")
171-
172168
return ret
173169

174170
async def get_prefix(self, message):
@@ -200,19 +196,16 @@ def add_command(self, command: Command):
200196
)
201197
elif not inspect.iscoroutinefunction(command._callback):
202198
raise TwitchCommandError(f"Failed to load command <{command.name}>. Commands must be coroutines.")
203-
204199
self.commands[command.name] = command
205200

206201
if not command.aliases:
207202
return
208-
209203
for alias in command.aliases:
210204
if alias in self.commands:
211205
del self.commands[command.name]
212206
raise TwitchCommandError(
213207
f"Failed to load command <{command.name}>, a command with that name/alias already exists."
214208
)
215-
216209
self._command_aliases[alias] = command.name
217210

218211
def get_command(self, name: str) -> Optional[Command]:
@@ -253,7 +246,6 @@ def remove_command(self, name: str):
253246
for alias in list(self._command_aliases.keys()):
254247
if self._command_aliases[alias] == name:
255248
del self._command_aliases[alias]
256-
257249
try:
258250
del self._commands[name]
259251
except KeyError:
@@ -291,11 +283,9 @@ async def get_context(self, message, *, cls=None):
291283
"""
292284
if not cls:
293285
cls = Context
294-
295286
prefix = await self.get_prefix(message)
296287
if not prefix:
297288
return cls(message=message, prefix=prefix, valid=False, bot=self)
298-
299289
content = message.content[len(prefix) : :].lstrip() # Strip prefix and remainder whitespace
300290
view = StringParser()
301291
parsed = view.process_string(content) # Return the string as a dict view
@@ -308,12 +298,10 @@ async def get_context(self, message, *, cls=None):
308298

309299
self.run_event("command_error", context, error)
310300
return context
311-
312301
try:
313302
command_ = self._command_aliases[command_]
314303
except KeyError:
315304
pass
316-
317305
if command_ in self.commands:
318306
command_ = self.commands[command_]
319307
else:
@@ -322,7 +310,6 @@ async def get_context(self, message, *, cls=None):
322310

323311
self.run_event("command_error", context, error)
324312
return context
325-
326313
context = cls(message=message, bot=self, prefix=prefix, command=command_, valid=True, view=view)
327314

328315
return context
@@ -350,7 +337,6 @@ async def invoke(self, context):
350337
# TODO Docs
351338
if not context.prefix or not context.is_valid:
352339
return
353-
354340
self.run_event("command_invoke", context)
355341
await context.command(context)
356342

@@ -364,7 +350,6 @@ def load_module(self, name: str) -> None:
364350
"""
365351
if name in self._modules:
366352
raise ValueError(f"Module <{name}> is already loaded")
367-
368353
module = importlib.import_module(name)
369354

370355
if hasattr(module, "prepare"):
@@ -373,7 +358,6 @@ def load_module(self, name: str) -> None:
373358
del module
374359
del sys.modules[name]
375360
raise ImportError(f"Module <{name}> is missing a prepare method")
376-
377361
self._modules[name] = module
378362

379363
def unload_module(self, name: str) -> None:
@@ -386,23 +370,19 @@ def unload_module(self, name: str) -> None:
386370
"""
387371
if name not in self._modules:
388372
raise ValueError(f"Module <{name}> is not loaded")
389-
390373
module = self._modules.pop(name)
391374

392375
if hasattr(module, "breakdown"):
393376
try:
394377
module.breakdown(self) # type: ignore
395378
except:
396379
pass
397-
398380
to_delete = [cog_name for cog_name, cog in self._cogs.items() if cog.__module__ == module.__name__]
399381
for name in to_delete:
400382
self.remove_cog(name)
401-
402383
to_delete = [name for name, cmd in self._commands.items() if cmd._callback.__module__ == module.__name__]
403384
for name in to_delete:
404385
self.remove_command(name)
405-
406386
to_delete = [
407387
x
408388
for y in self._events.items()
@@ -411,7 +391,6 @@ def unload_module(self, name: str) -> None:
411391
]
412392
for event in to_delete:
413393
self.remove_event(event)
414-
415394
for m in list(sys.modules.keys()):
416395
if m == module.__name__ or m.startswith(module.__name__ + "."):
417396
del sys.modules[m]
@@ -431,7 +410,6 @@ def reload_module(self, name: str):
431410
"""
432411
if name not in self._modules:
433412
raise ValueError(f"Module <{name}> is not loaded")
434-
435413
module = self._modules[name]
436414

437415
modules = {
@@ -464,10 +442,8 @@ def add_cog(self, cog: Cog):
464442
"""
465443
if not isinstance(cog, Cog):
466444
raise InvalidCog('Cogs must derive from "commands.Cog".')
467-
468445
if cog.name in self._cogs:
469446
raise InvalidCog(f'Cog "{cog.name}" has already been loaded.')
470-
471447
cog._load_methods(self)
472448
self._cogs[cog.name] = cog
473449

@@ -480,7 +456,6 @@ def remove_cog(self, cog_name: str):
480456
"""
481457
if cog_name not in self._cogs:
482458
raise InvalidCog(f"Cog '{cog_name}' not found")
483-
484459
cog = self._cogs.pop(cog_name)
485460
cog._unload_methods(self)
486461

@@ -571,7 +546,6 @@ async def event_message(self, message: Message) -> None:
571546
"""
572547
if message.echo:
573548
return
574-
575549
await self.handle_commands(message)
576550

577551
def command(
@@ -630,6 +604,5 @@ def decorator(func: Callable):
630604
def check(self, func: Callable[[Context], bool]) -> Callable:
631605
if func in self._checks:
632606
raise ValueError("The function is already registered as a bot check")
633-
634607
self._checks.append(func)
635608
return func

0 commit comments

Comments
 (0)