2023-12-28 15:50:23 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
1) Send message to inviter that bot has joined to groupchat.
|
|
|
|
|
|
|
|
2) If groupchat requires captcha, send the consequent message.
|
|
|
|
|
|
|
|
3) If groupchat error is received, send that error message to inviter.
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
FIXME
|
|
|
|
|
|
|
|
1) Save name of groupchat instead of jid as name
|
2024-01-26 12:34:07 +01:00
|
|
|
|
2023-12-28 15:50:23 +01:00
|
|
|
"""
|
2024-01-03 11:37:33 +01:00
|
|
|
import logging
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
class XmppGroupchat:
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-03-27 17:20:32 +01:00
|
|
|
async def join(self, jid, alias=None, password=None):
|
2024-02-07 01:26:42 +01:00
|
|
|
# token = await initdb(
|
|
|
|
# muc_jid,
|
2024-02-16 13:12:06 +01:00
|
|
|
# sqlite.get_setting_value,
|
2024-02-07 01:26:42 +01:00
|
|
|
# "token"
|
|
|
|
# )
|
|
|
|
# if token != "accepted":
|
|
|
|
# token = randrange(10000, 99999)
|
|
|
|
# await initdb(
|
|
|
|
# muc_jid,
|
2024-02-16 13:12:06 +01:00
|
|
|
# sqlite.update_setting_value,
|
2024-02-07 01:26:42 +01:00
|
|
|
# ["token", token]
|
|
|
|
# )
|
|
|
|
# self.send_message(
|
|
|
|
# mto=inviter,
|
|
|
|
# mfrom=self.boundjid.bare,
|
|
|
|
# mbody=(
|
|
|
|
# "Send activation token {} to groupchat xmpp:{}?join."
|
|
|
|
# ).format(token, muc_jid)
|
|
|
|
# )
|
|
|
|
logging.info('Joining groupchat\n'
|
|
|
|
'JID : {}\n'
|
2024-03-27 17:20:32 +01:00
|
|
|
.format(jid))
|
2024-03-12 18:13:01 +01:00
|
|
|
jid_from = str(self.boundjid) if self.is_component else None
|
2024-03-27 17:20:32 +01:00
|
|
|
if alias == None: self.alias
|
2024-03-26 17:23:22 +01:00
|
|
|
await self.plugin['xep_0045'].join_muc_wait(jid,
|
2024-03-27 17:20:32 +01:00
|
|
|
alias,
|
2024-03-26 17:23:22 +01:00
|
|
|
presence_options = {"pfrom" : jid_from},
|
2024-03-27 17:20:32 +01:00
|
|
|
password=password)
|
2024-02-07 01:26:42 +01:00
|
|
|
|
|
|
|
|
2024-02-14 18:09:54 +01:00
|
|
|
def leave(self, jid):
|
2024-03-26 17:23:22 +01:00
|
|
|
jid_from = str(self.boundjid) if self.is_component else None
|
2024-02-12 20:01:28 +01:00
|
|
|
message = ('This news bot will now leave this groupchat.\n'
|
|
|
|
'The JID of this news bot is xmpp:{}?message'
|
2024-02-14 18:09:54 +01:00
|
|
|
.format(self.boundjid.bare))
|
2024-02-12 20:01:28 +01:00
|
|
|
status_message = ('This bot has left the group. '
|
|
|
|
'It can be reached directly via {}'
|
2024-02-14 18:09:54 +01:00
|
|
|
.format(self.boundjid.bare))
|
|
|
|
self.send_message(mto=jid,
|
|
|
|
mfrom=self.boundjid,
|
2024-02-12 20:01:28 +01:00
|
|
|
mbody=message,
|
|
|
|
mtype='groupchat')
|
2024-02-14 18:09:54 +01:00
|
|
|
self.plugin['xep_0045'].leave_muc(jid,
|
2024-02-07 01:26:42 +01:00
|
|
|
self.alias,
|
2024-02-12 20:01:28 +01:00
|
|
|
status_message,
|
2024-03-26 17:23:22 +01:00
|
|
|
jid_from)
|