Support full text search for commands

This commit is contained in:
Luke Murphy 2021-01-18 20:48:01 +01:00
parent 46d054243c
commit 3584ce3460
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
4 changed files with 15 additions and 7 deletions

View File

@ -1,5 +1,9 @@
# xbotlib x.x.x (UNRELEASED)
# xbotlib 0.13.0 (2021-01-18)
- Allow commands to be detected in all parts of the message
# xbotlib 0.12.4 (2021-01-18)
- Allow `Bot.group` to respond to file uploads ([#32](https://git.autonomic.zone/decentral1se/xbotlib/issues/32))

View File

@ -148,6 +148,9 @@ There are also more general status commands which all bots respond to.
- `@bots`: status check on who is a bot in the group chat
These commands will be detected in any part of the message sent to the bot. So
you can write `echobot, can we see your @uptime`, or `I'd love to know which @bots are here.`
### Avatars
By default, `xbotlib` will look for an `avatar.png` (so far tested with `.png`

View File

@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"
[tool.poetry]
name = "xbotlib"
version = "0.12.4"
version = "0.13.0"
description = "XMPP bots for humans"
authors = ["decentral1se <lukewm@riseup.net>"]
maintainers = ["decentral1se <lukewm@riseup.net>"]

View File

@ -513,8 +513,9 @@ class Bot(ClientXMPP):
"""Handle group chat message events."""
message = SimpleMessage(message, self)
if message.text.startswith("@"):
return self.meta(message, room=message.room)
if "@" in message.text:
if self.meta(message, room=message.room):
return
miss = message.type not in self.GROUP_MESSAGE_TYPES
loop = message.nick == self.nick
@ -523,7 +524,7 @@ class Bot(ClientXMPP):
if miss or other or loop:
return
if message.content.startswith("@"):
if "@" in message.content:
if self.command(message, room=message.room):
return
@ -613,14 +614,14 @@ class Bot(ClientXMPP):
def meta(self, message, **kwargs):
"""Handle meta command invocations."""
if message.text.startswith("@bots"):
if "@bots" in message.text:
return self.reply("🖐️", **kwargs)
def command(self, message, **kwargs):
"""Handle command invocations."""
if message.content.startswith("@uptime"):
if "@uptime" in message.content:
return self.reply(self.uptime, **kwargs)
elif message.content.startswith("@help"):
elif "@help" in message.content:
try:
return self.reply(cleandoc(self.help), **kwargs)
except AttributeError: