From 1bbbbf91593276b94e8a0672e34cfe1b23682c04 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 13 Jan 2021 22:49:52 +0100 Subject: [PATCH] Support invites --- CHANGELOG.md | 4 ++++ README.md | 1 - pyproject.toml | 2 +- xbotlib.py | 17 +++++++---------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4f5e0..952bd53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # xbotlib x.x.x (UNRELEASED) +# xbotlib 0.7.0 (2021-01-13) + +- Remove `room` as configuration and support arbitrary invite acceptance ([#15](https://git.autonomic.zone/decentral1se/xbotlib/issues/15)) + # xbotlib 0.6.0 (2021-01-13) - Implement direct/group API ([#13](https://git.autonomic.zone/decentral1se/xbotlib/issues/13)) diff --git a/README.md b/README.md index 81a7d95..228c96a 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ You can pass the `--no-input` option to your script invocation (e.g. `python bot - **XBOT_JID**: The username of the bot account - **XBOT_PASSWORD**: The password of the bot account -- **XBOT_ROOM**: The room that the bot can join - **XBOT_NICK**: The nickname that the bot uses ## Roadmap diff --git a/pyproject.toml b/pyproject.toml index 9503107..444f1ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "xbotlib" -version = "0.6.0" +version = "0.7.0" description = "XMPP bots for humans" authors = ["decentral1se "] maintainers = ["decentral1se "] diff --git a/xbotlib.py b/xbotlib.py index f84ec49..210af62 100644 --- a/xbotlib.py +++ b/xbotlib.py @@ -86,14 +86,11 @@ class Bot(ClientXMPP): password = ( getpass("Password (e.g. my-cool-password): ") or "my-cool-password" ) - room = input("XMPP room (e.g. foo@muc.bar.com): ") nick = input("Nickname (e.g. lurkbot): ") config = ConfigParser() config["bot"] = {"jid": jid, "password": password} - if room: - config["bot"]["room"] = room if nick: config["bot"]["nick"] = nick @@ -105,7 +102,6 @@ class Bot(ClientXMPP): self.config["bot"] = {} self.config["bot"]["jid"] = environ.get("XBOT_JID") self.config["bot"]["password"] = environ.get("XBOT_PASSWORD") - self.config["bot"]["room"] = environ.get("XBOT_ROOM", "") self.config["bot"]["nick"] = environ.get("XBOT_NICK", "") def init_bot(self): @@ -117,6 +113,7 @@ class Bot(ClientXMPP): def register_xmpp_event_handlers(self): """Register functions against specific XMPP event handlers.""" self.add_event_handler("session_start", self.session_start) + self.add_event_handler("groupchat_invite", self.group_invite) self.add_event_handler("message", self.direct_message) self.add_event_handler("groupchat_message", self.group_message) @@ -125,16 +122,16 @@ class Bot(ClientXMPP): if message["type"] in ("chat", "normal"): self.direct(SimpleMessage(message)) - def session_start(self, event): + def session_start(self, message): """Handle session_start event.""" self.send_presence() self.get_roster() - room = self.config["bot"].get("room") - nick = self.config["bot"].get("nick") - - if room and nick: - self.plugin["xep_0045"].join_muc(room, nick) + def group_invite(self, message): + """Accept invites to group chats.""" + self.plugin["xep_0045"].join_muc( + message["from"], self.config["bot"]["nick"] + ) def group_message(self, message): """Handle groupchat_message event."""