]> kaliko git repositories - sid.git/blobdiff - sid/rtbl.py
rtbl: Fixed rtbl_ban call
[sid.git] / sid / rtbl.py
index 44f5ca4bb0d11b26519df43f7a924204edd5c406..e5e4e6f933e1fbd093380a36f0a05e34d2a0fa42 100644 (file)
@@ -1,6 +1,5 @@
 # -*- coding: utf-8 -*-
-# SPDX-FileCopyrightText: 2014, 2020, 2023 kaliko <kaliko@azylum.org>
-# SPDX-FileCopyrightText: 2007-2012 Thomas Perl <thp.io/about>
+# SPDX-FileCopyrightText: 2023 kaliko <kaliko@azylum.org>
 # SPDX-License-Identifier: GPL-3.0-or-later
 """A Real Time Block List plugin"""
 
@@ -20,7 +19,8 @@ def jid_to_sha256(jid: JID) -> str:
 
 
 class BL:
-    """Plain object to keep track of block list items"""
+    """Plain object to keep track of block list items.
+    Only used in RTBL plugin."""
 
     def __init__(self, initial_bl):
         self.sha256_jids: Dict[str, Optional[str]] = {}
@@ -59,9 +59,11 @@ class BL:
 
 
 class RTBL(Plugin):
-    """Spam guard for MUC
+    """Spam guard plugin for MUC.
     """
+    #: Pubsub server
     pubsub_server = 'example.org'
+    #: Pubsub server node to subscribe to
     node = 'muc_bans_sha256'
 
     def __init__(self, bot):
@@ -106,6 +108,9 @@ class RTBL(Plugin):
         self.blocklist = BL(node_blocklist['pubsub']['items'])
         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):
+            await self.rtbl_ban(jid)
 
     async def _create(self):
         """Try to create node"""
@@ -136,8 +141,8 @@ class RTBL(Plugin):
             return
         self.blocklist.insert_item(msg['pubsub_event']['items']['item']['id'])
         # Are current participants in the block list
-        for jid in self.participants:
-            self.rtbl_ban(jid)
+        for jid in list(self.participants):
+            await self.rtbl_ban(jid)
 
     async def rtbl_ban(self, jid):
         """Ban jid in RTBL"""
@@ -154,7 +159,7 @@ class RTBL(Plugin):
             await self.ban(jid.bare, reason=reason)
 
     def got_offline(self, pres):
-        """Handler method for laving MUC participants"""
+        """Handler method for leaving MUC participants"""
         fjid = pres['muc']['jid']
         user = fjid if fjid.full else pres['muc']['nick']
         try: