Support @ commands for direct messages
This commit is contained in:
parent
fd2134f914
commit
aa64a1a68e
34
xbotlib.py
34
xbotlib.py
@ -217,11 +217,8 @@ class Bot(ClientXMPP):
|
|||||||
if message["type"] in ("chat", "normal"):
|
if message["type"] in ("chat", "normal"):
|
||||||
_message = SimpleMessage(message)
|
_message = SimpleMessage(message)
|
||||||
|
|
||||||
if _message.body.startswith("/"):
|
if "@" in _message.body:
|
||||||
self.meta(_message, to=_message.sender)
|
self.direct_command(_message)
|
||||||
|
|
||||||
if _message.body.startswith("!"):
|
|
||||||
self.command(_message, to=_message.sender)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.direct(_message)
|
self.direct(_message)
|
||||||
@ -264,7 +261,7 @@ class Bot(ClientXMPP):
|
|||||||
if message["mucnick"] != self.config.nick:
|
if message["mucnick"] != self.config.nick:
|
||||||
_message = SimpleMessage(message)
|
_message = SimpleMessage(message)
|
||||||
|
|
||||||
if _message.body.startswith("/"):
|
if _message.body.startswith("@"):
|
||||||
self.meta(_message, room=_message.room)
|
self.meta(_message, room=_message.room)
|
||||||
|
|
||||||
if f"{self.nick}:!" in _message.body:
|
if f"{self.nick}:!" in _message.body:
|
||||||
@ -327,24 +324,17 @@ 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 command(self, message, **kwargs):
|
def direct_command(self, message):
|
||||||
"""Handle "!" style commands with built-in responses."""
|
"""Handle commands in direct messages."""
|
||||||
command = message.body.split("!")[-1]
|
if "@uptime" in message.body:
|
||||||
|
self.reply(self.uptime, to=message.sender)
|
||||||
if command == "uptime":
|
elif "@help" in message.body:
|
||||||
self.reply(self.uptime, **kwargs)
|
|
||||||
elif command == "help":
|
|
||||||
try:
|
try:
|
||||||
self.reply(self.help, **kwargs)
|
self.reply(cleandoc(self.help), to=message.sender)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.reply("No help found 🤔️", **kwargs)
|
self.reply("No help found 🤔️", to=message.sender)
|
||||||
|
else:
|
||||||
def meta(self, message, **kwargs):
|
self.log.info(f"'{message.body}' not handled")
|
||||||
"""Handle "/" style commands with built-in responses."""
|
|
||||||
command = message.body.split("/")[-1]
|
|
||||||
|
|
||||||
if command == "bots":
|
|
||||||
self.reply("🖐️", **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class EchoBot(Bot):
|
class EchoBot(Bot):
|
||||||
|
Reference in New Issue
Block a user