Merge command functions once more

This commit is contained in:
Luke Murphy 2021-01-16 13:14:42 +01:00
parent b1b9c0e701
commit ad3d77f5e1
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -220,7 +220,7 @@ class Bot(ClientXMPP):
_message = SimpleMessage(message) _message = SimpleMessage(message)
if "@" in _message.body: if "@" in _message.body:
self.direct_command(_message) self.command(_message, to=_message.sender)
try: try:
self.direct(_message) self.direct(_message)
@ -268,7 +268,7 @@ class Bot(ClientXMPP):
_message = SimpleMessage(message) _message = SimpleMessage(message)
if self.nick in _message.body and "@" in _message.body: if self.nick in _message.body and "@" in _message.body:
self.group_command(_message, room=_message.room) self.command(_message, room=_message.room)
try: try:
self.group(_message) self.group(_message)
@ -327,15 +327,15 @@ class Bot(ClientXMPP):
"""Time since the bot came up.""" """Time since the bot came up."""
return naturaldelta(self.start - dt.now()) return naturaldelta(self.start - dt.now())
def direct_command(self, message): def command(self, message, **kwargs):
"""Handle commands in direct messages.""" """Handle command invocations."""
if "@uptime" in message.body: if "@uptime" in message.body:
self.reply(self.uptime, to=message.sender) self.reply(self.uptime, **kwargs)
elif "@help" in message.body: elif "@help" in message.body:
try: try:
self.reply(cleandoc(self.help), to=message.sender) self.reply(cleandoc(self.help), **kwargs)
except AttributeError: except AttributeError:
self.reply("No help found 🤔️", to=message.sender) self.reply("No help found 🤔️", **kwargs)
else: else:
self.log.info(f"'{message.body}' not handled") self.log.info(f"'{message.body}' not handled")