X-Git-Url: http://git.kaliko.me/?p=sid.git;a=blobdiff_plain;f=sid%2Frtbl.py;fp=sid%2Frtbl.py;h=6b33344800fbbc0022d479d2af257171ab667c6d;hp=99095eacf679244a2b221afe8f2905e3fe916206;hb=6bd74a49f0c0a599423d52cb0d59b0620b00118d;hpb=fc68fb05af319202cb18fba36dd8f95d77673cda diff --git a/sid/rtbl.py b/sid/rtbl.py index 99095ea..6b33344 100644 --- a/sid/rtbl.py +++ b/sid/rtbl.py @@ -77,16 +77,14 @@ class RTBL(Plugin): ('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() @@ -113,7 +111,7 @@ class RTBL(Plugin): 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): @@ -145,7 +143,7 @@ class RTBL(Plugin): 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): @@ -164,17 +162,6 @@ class RTBL(Plugin): 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']: @@ -187,24 +174,12 @@ class RTBL(Plugin): 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")