Support invites
This commit is contained in:
parent
e3282a89bc
commit
1bbbbf9159
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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 <lukewm@riseup.net>"]
|
||||
maintainers = ["decentral1se <lukewm@riseup.net>"]
|
||||
|
17
xbotlib.py
17
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."""
|
||||
|
Reference in New Issue
Block a user