('pubsub_retract', self._retract),
('pubsub_publish', self._publish),
(f'muc::{self.bot.room}::presence', self.got_presence),
- (f'muc::{self.bot.room}::got_offline', self.got_offline),
(f'muc::{self.bot.room}::got_online', self.got_online)
]
self.add_handlers()
self.bot = bot
- self.participants = set()
self.moderator = False
self.blocklist: BL = None
self.hits = 0
- self.presences = {}
+ self.presences = bot.muc_presences
def _exit(self):
self.rm_handlers()
mess = f'Got {len(self.blocklist)} items in block list'
self.log.info(mess)
# Are current participants in the block list
- for jid in list(self.participants):
+ for jid in [pres['muc']['jid'] for pres in self.presences.values()]:
await self.rtbl_ban(jid)
async def _create(self):
return
self.blocklist.insert_item(msg['pubsub_event']['items']['item'])
# Are current participants in the block list
- for jid in list(self.participants):
+ for jid in [pres['muc']['jid'] for pres in self.presences.values()]:
await self.rtbl_ban(jid)
async def rtbl_ban(self, jid):
self.hits += 1
self.log.info(f'{jid} banned!')
- def got_offline(self, pres):
- """Handler method for leaving MUC participants"""
- fjid = pres['muc']['jid']
- user = fjid if fjid.full else pres['muc']['nick']
- try:
- self.participants.remove(user)
- self.presences.pop(pres['muc']['nick'])
- except KeyError:
- self.log.error('KeyError removing participant: "%s"', user)
- self.log.debug(f'participants: - {user} got offline (len:{len(self.participants)})')
-
def got_presence(self, pres):
"""Does bot have required permissions"""
if 110 in pres['muc']['status_codes']:
else:
self.log.info('Got moderator permissions.')
self.moderator = True
- nick = pres['muc']['nick']
- fjid = pres['muc']['jid']
- role = pres['muc']['role']
- affi = pres['muc']['affiliation']
- user = fjid if fjid.full else nick
- self.log.debug(f'participants: u {user}:{role}/{affi} (len:{len(self.participants)})')
- self.presences.update({nick: pres})
async def got_online(self, pres):
"""Handler method for new MUC participants"""
fjid = pres['muc']['jid']
nick = pres['muc']['nick']
- role = pres['muc']['role']
- affi = pres['muc']['affiliation']
user = fjid if fjid.full else nick
- self.participants.add(user)
- self.presences.update({nick: pres})
- self.log.debug(f'participants: + {user}:{role}/{affi} (len:{len(self.participants)})')
await self.rtbl_ban(user)
@botcmd(name="rtbl-info")