2024-06-29 23:16:03 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2024-11-21 20:00:13 +01:00
|
|
|
from kaikout.xmpp.message import XmppMessage
|
2024-06-29 23:16:03 +02:00
|
|
|
from kaikout.xmpp.muc import XmppMuc
|
|
|
|
from kaikout.xmpp.status import XmppStatus
|
2024-11-21 20:00:13 +01:00
|
|
|
from kaikout.utilities import Toml
|
2024-06-29 23:16:03 +02:00
|
|
|
from kaikout.log import Logger, Message
|
2024-11-21 11:11:11 +01:00
|
|
|
import random
|
2024-06-29 23:16:03 +02:00
|
|
|
|
|
|
|
logger = Logger(__name__)
|
|
|
|
|
|
|
|
class XmppGroupchat:
|
|
|
|
|
2024-11-21 20:00:13 +01:00
|
|
|
async def join(self, room):
|
|
|
|
result = await XmppMuc.join(self, room)
|
|
|
|
if result == 'ban':
|
|
|
|
message_body = '{} is banned from {}'.format(self.alias, room)
|
|
|
|
jid_bare = message['from'].bare
|
|
|
|
XmppMessage.send(self, jid_bare, message_body, 'chat')
|
|
|
|
logger.warning(message_body)
|
|
|
|
elif result == 'conflict':
|
|
|
|
while result == 'conflict':
|
|
|
|
number = str(random.randrange(1000, 5000))
|
|
|
|
print(f'Conflict. Atempting to join to {room} as {self.alias} #{number}')
|
|
|
|
result = await XmppMuc.join(self, room, f'{self.alias} #{number}')
|
|
|
|
else:
|
|
|
|
#self.bookmarks.append({'jid' : room, 'lang' : '', 'pass' : ''})
|
|
|
|
if room not in self.bookmarks: self.bookmarks.append(room)
|
|
|
|
Toml.save_file(self.filename_bookmarks, self.data_bookmarks)
|
|
|
|
return result
|
|
|
|
|
|
|
|
async def autojoin(self):
|
|
|
|
mucs_joined = []
|
|
|
|
for room in self.bookmarks:
|
|
|
|
alias = self.alias
|
|
|
|
print(f'Joining to MUC {room} ...')
|
|
|
|
#Message.printer(f'Joining to MUC {room} ...')
|
|
|
|
result = await XmppMuc.join(self, room)
|
|
|
|
if result == 'ban':
|
|
|
|
if room in self.bookmarks: self.bookmarks.remove(room)
|
|
|
|
Toml.save_file(self.filename_bookmarks, self.data_bookmarks)
|
|
|
|
logger.warning(f'{alias} is banned from {room}')
|
|
|
|
logger.warning(f'Groupchat {room} has been removed from bookmarks')
|
|
|
|
elif result == 'conflict':
|
|
|
|
while result == 'conflict':
|
2024-11-21 11:11:11 +01:00
|
|
|
number = str(random.randrange(1000, 5000))
|
2024-11-21 20:00:13 +01:00
|
|
|
print(f'Conflict. Atempting to join to {room} as {self.alias} #{number}')
|
|
|
|
result = await XmppMuc.join(self, room, f'{alias} #{number}')
|
|
|
|
else:
|
|
|
|
mucs_joined.append(room)
|
|
|
|
return mucs_joined
|