Flattened code a bit
parent
e7637a1bce
commit
5648f1a9de
|
@ -88,7 +88,10 @@ class Frank(discord.Client):
|
|||
except ValueError:
|
||||
return
|
||||
|
||||
if cmd and cmd[0] == self.PREFIX:
|
||||
# Exit if no commands are given or prefix is wrong
|
||||
if not (cmd and cmd[0] == self.PREFIX):
|
||||
return
|
||||
|
||||
module = next((mod for mod in self._loaded_modules
|
||||
if mod.match(cmd[1])), None)
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class RegexCommand(Command):
|
|||
|
||||
class Daemon(Simple):
|
||||
"""
|
||||
Represents a daemon aka a background process.
|
||||
Represents a daemon a.k.a. a background process.
|
||||
"""
|
||||
|
||||
def __init__(self, func: callable, interval: Union[int, float] = 0):
|
||||
|
@ -122,6 +122,7 @@ class Daemon(Simple):
|
|||
if interval > 0:
|
||||
async def loop(self, *args, **kwargs):
|
||||
while True:
|
||||
# TODO: does this make func and sleep run at the same time?
|
||||
await func(self, *args, **kwargs)
|
||||
|
||||
await asyncio.sleep(interval)
|
||||
|
@ -131,7 +132,7 @@ class Daemon(Simple):
|
|||
|
||||
class Default(Simple):
|
||||
"""
|
||||
Represents a default command (a.k.a. when the module is called without a
|
||||
Represents a default command a.k.a. when the module is called without a
|
||||
command.
|
||||
"""
|
||||
|
||||
|
|
|
@ -100,7 +100,10 @@ class Module(ModuleMeta):
|
|||
func = next((func for func in self.commands
|
||||
if func.match(cmd[0])), None)
|
||||
|
||||
if func:
|
||||
# Throw error if no function is found
|
||||
if not func:
|
||||
raise InvalidCommand(f'Unknown command: {cmd}')
|
||||
|
||||
# A RegexCommand can use the prefix, as it's not a fixed string
|
||||
if isinstance(func, RegexCommand):
|
||||
await func(prefix=cmd[0], cmd=cmd[1:], author=author,
|
||||
|
@ -110,9 +113,6 @@ class Module(ModuleMeta):
|
|||
await func(cmd=cmd[1:], author=author, channel=channel,
|
||||
mid=mid)
|
||||
|
||||
else:
|
||||
raise InvalidCommand(f'Unknown command: {cmd}')
|
||||
|
||||
elif self.default:
|
||||
await self.default(author=author, channel=channel, mid=mid)
|
||||
|
||||
|
@ -125,12 +125,12 @@ class Module(ModuleMeta):
|
|||
prefix: prefix to check
|
||||
"""
|
||||
|
||||
if cls.PREFIX:
|
||||
# Always return False if there's no PREFIX defined
|
||||
if not cls.PREFIX:
|
||||
return False
|
||||
|
||||
if isinstance(cls.PREFIX, list):
|
||||
return prefix in cls.PREFIX
|
||||
|
||||
else:
|
||||
return prefix == cls.PREFIX
|
||||
|
||||
else:
|
||||
return False
|
||||
|
|
Reference in New Issue