Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_command(self, command):
if not isinstance(command, TwitchCommand):
raise TypeError('Commands passed my be a subclass of TwitchCommand.')
elif command.name in self.commands:
raise TwitchIOCommandError(f'Failed to load command <{command.name}>, a command with that name already exists')
elif not inspect.iscoroutinefunction(command._callback):
raise TwitchIOCommandError(f'Failed to load command <{command.name}>. Commands must be coroutines.')
self.commands[command.name] = command
if not command.aliases:
return
for alias in command.aliases:
if alias in self.commands:
del self.commands[command.name]
raise TwitchIOCommandError(
f'Failed to load command <{command.name}>, a command with that name/alias already exists.')
self._aliases[alias] = command.name
if not isinstance(command, TwitchCommand):
raise TypeError('Commands passed my be a subclass of TwitchCommand.')
elif command.name in self.commands:
raise TwitchIOCommandError(f'Failed to load command <{command.name}>, a command with that name already exists')
elif not inspect.iscoroutinefunction(command._callback):
raise TwitchIOCommandError(f'Failed to load command <{command.name}>. Commands must be coroutines.')
self.commands[command.name] = command
if not command.aliases:
return
for alias in command.aliases:
if alias in self.commands:
del self.commands[command.name]
raise TwitchIOCommandError(
f'Failed to load command <{command.name}>, a command with that name/alias already exists.')
self._aliases[alias] = command.name
def _init_methods(self):
commands = inspect.getmembers(self)
for name, obj in commands:
if not isinstance(obj, TwitchCommand):
continue
obj.instance = self
try:
self.add_command(obj)
except TwitchIOCommandError:
traceback.print_exc()
continue
def add_command(self, command):
if not isinstance(command, TwitchCommand):
raise TypeError('Commands passed my be a subclass of TwitchCommand.')
elif command.name in self.commands:
raise TwitchIOCommandError(f'Failed to load command <{command.name}>, a command with that name already exists')
elif not inspect.iscoroutinefunction(command._callback):
raise TwitchIOCommandError(f'Failed to load command <{command.name}>. Commands must be coroutines.')
self.commands[command.name] = command
if not command.aliases:
return
for alias in command.aliases:
if alias in self.commands:
del self.commands[command.name]
raise TwitchIOCommandError(
f'Failed to load command <{command.name}>, a command with that name/alias already exists.')
self._aliases[alias] = command.name