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
|
2024-01-02 12:42:41 +01:00
|
|
|
|
import slixfeed.xmpp.process as process
|
2024-01-18 21:57:49 +01:00
|
|
|
|
from slixfeed.dt import current_time
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
2024-01-02 12:42:41 +01:00
|
|
|
|
# async def accept_muc_invite(self, message, ctr=None):
|
|
|
|
|
# # if isinstance(message, str):
|
|
|
|
|
# if not ctr:
|
|
|
|
|
# ctr = message["from"].bare
|
|
|
|
|
# jid = message['groupchat_invite']['jid']
|
|
|
|
|
# else:
|
|
|
|
|
# jid = message
|
|
|
|
|
async def accept_invitation(self, message):
|
|
|
|
|
# operator muc_chat
|
|
|
|
|
inviter = message["from"].bare
|
|
|
|
|
muc_jid = message['groupchat_invite']['jid']
|
|
|
|
|
await join(self, inviter, muc_jid)
|
|
|
|
|
|
|
|
|
|
|
2024-01-24 19:11:39 +01:00
|
|
|
|
async def autojoin(self):
|
2024-01-02 12:42:41 +01:00
|
|
|
|
result = await self.plugin['xep_0048'].get_bookmarks()
|
|
|
|
|
bookmarks = result["private"]["bookmarks"]
|
|
|
|
|
conferences = bookmarks["conferences"]
|
|
|
|
|
for conference in conferences:
|
|
|
|
|
if conference["autojoin"]:
|
|
|
|
|
muc_jid = conference["jid"]
|
2024-02-04 18:08:12 +01:00
|
|
|
|
logging.info(
|
|
|
|
|
'Autojoin groupchat\n'
|
|
|
|
|
'Name : {}\n'
|
|
|
|
|
'JID : {}\n'
|
|
|
|
|
'Alias : {}\n'
|
|
|
|
|
.format(
|
|
|
|
|
conference["name"],
|
|
|
|
|
muc_jid,
|
|
|
|
|
conference["nick"]
|
|
|
|
|
))
|
2024-01-02 12:42:41 +01:00
|
|
|
|
self.plugin['xep_0045'].join_muc(
|
|
|
|
|
muc_jid,
|
2024-01-24 19:11:39 +01:00
|
|
|
|
conference["nick"],
|
2024-01-02 12:42:41 +01:00
|
|
|
|
# If a room password is needed, use:
|
|
|
|
|
# password=the_room_password,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
async def join(self, inviter, muc_jid):
|
2023-12-28 15:50:23 +01:00
|
|
|
|
# token = await initdb(
|
|
|
|
|
# muc_jid,
|
|
|
|
|
# get_settings_value,
|
|
|
|
|
# "token"
|
|
|
|
|
# )
|
|
|
|
|
# if token != "accepted":
|
|
|
|
|
# token = randrange(10000, 99999)
|
|
|
|
|
# await initdb(
|
|
|
|
|
# muc_jid,
|
2024-01-14 13:46:38 +01:00
|
|
|
|
# update_settings_value,
|
2023-12-28 15:50:23 +01:00
|
|
|
|
# ["token", token]
|
|
|
|
|
# )
|
|
|
|
|
# self.send_message(
|
|
|
|
|
# mto=inviter,
|
2024-01-24 19:11:39 +01:00
|
|
|
|
# mfrom=self.boundjid.bare,
|
2023-12-28 15:50:23 +01:00
|
|
|
|
# mbody=(
|
|
|
|
|
# "Send activation token {} to groupchat xmpp:{}?join."
|
|
|
|
|
# ).format(token, muc_jid)
|
|
|
|
|
# )
|
2024-02-04 18:08:12 +01:00
|
|
|
|
logging.info(
|
|
|
|
|
'Joining groupchat\n'
|
|
|
|
|
'JID : {}\n'
|
|
|
|
|
'Inviter : {}\n'
|
|
|
|
|
.format(
|
|
|
|
|
muc_jid,
|
|
|
|
|
inviter
|
|
|
|
|
))
|
2023-12-28 15:50:23 +01:00
|
|
|
|
self.plugin['xep_0045'].join_muc(
|
|
|
|
|
muc_jid,
|
2024-01-24 19:11:39 +01:00
|
|
|
|
self.alias,
|
2023-12-28 15:50:23 +01:00
|
|
|
|
# If a room password is needed, use:
|
|
|
|
|
# password=the_room_password,
|
|
|
|
|
)
|
2024-01-02 12:42:41 +01:00
|
|
|
|
process.greet(self, muc_jid, chat_type="groupchat")
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
|
|
|
2024-01-02 12:42:41 +01:00
|
|
|
|
async def leave(self, muc_jid):
|
2023-12-28 15:50:23 +01:00
|
|
|
|
messages = [
|
|
|
|
|
"Whenever you need an RSS service again, "
|
|
|
|
|
"please don’t hesitate to contact me.",
|
|
|
|
|
"My personal contact is xmpp:{}?message".format(self.boundjid.bare),
|
|
|
|
|
"Farewell, and take care."
|
|
|
|
|
]
|
|
|
|
|
for message in messages:
|
|
|
|
|
self.send_message(
|
|
|
|
|
mto=muc_jid,
|
2024-01-24 19:11:39 +01:00
|
|
|
|
mfrom=self.boundjid.bare,
|
2023-12-28 15:50:23 +01:00
|
|
|
|
mbody=message,
|
|
|
|
|
mtype="groupchat"
|
|
|
|
|
)
|
|
|
|
|
self.plugin['xep_0045'].leave_muc(
|
|
|
|
|
muc_jid,
|
2024-01-24 19:11:39 +01:00
|
|
|
|
self.alias,
|
2023-12-28 15:50:23 +01:00
|
|
|
|
"Goodbye!",
|
|
|
|
|
self.boundjid.bare
|
|
|
|
|
)
|
|
|
|
|
|