]> kaliko git repositories - sid.git/blobdiff - sid/rtbl.py
doc: Improve and update
[sid.git] / sid / rtbl.py
index 6b33344800fbbc0022d479d2af257171ab667c6d..1539b28a1273be86420c38b9df6d99c4dfc0f8c9 100644 (file)
@@ -1,7 +1,17 @@
 # -*- coding: utf-8 -*-
 # SPDX-FileCopyrightText: 2023 kaliko <kaliko@azylum.org>
 # SPDX-License-Identifier: GPL-3.0-or-later
-"""A Real Time Block List plugin"""
+"""A Real Time Block List plugin, cf https://xmppbl.org.
+
+>>> from sid.rtbl import RTBL, BL
+>>> RTBL.pubsub_server = 'xmppbl.org'
+>>> # Optional: Node to subcribe, defaults to 'muc_bans_sha256'
+>>> RTBL.node = 'muc_bans_sha256'
+>>> # Optional: Add this JID hash to the list, default is empty, usefull for test
+>>> BL.init = {'1312b8ca593cd074f39ef15cc8442cdf426b21480958836d9ab678ca45ed1312': 'Test!'}
+>>> # Optional: Set plugin log level, default inherit from the bot
+>>> RTBL.log_level = logging.DEBUG
+"""
 
 from hashlib import sha256
 from typing import Dict, Optional
@@ -52,7 +62,6 @@ class BL:
     def get_reason(self, jid: JID) -> Optional[str]:
         """Check the presence of the JID in the blocklist"""
         jidhash = jid_to_sha256(jid)
-        # Raises if item does not exist
         return self.sha256_jids[jidhash]
 
     def __len__(self):
@@ -146,9 +155,9 @@ class RTBL(Plugin):
         for jid in [pres['muc']['jid'] for pres in self.presences.values()]:
             await self.rtbl_ban(jid)
 
-    async def rtbl_ban(self, jid):
+    async def rtbl_ban(self, jid: JID):
         """Ban jid in RTBL"""
-        if not self.moderator:
+        if not self.moderator or not jid.bare:
             return
         if self.blocklist is None:
             self.log.info('Not checking %s, block list not populated yet', jid)
@@ -174,13 +183,12 @@ class RTBL(Plugin):
             else:
                 self.log.info('Got moderator permissions.')
                 self.moderator = True
+                #TODO: purge presences cache sid.MUCBot.muc_presences?
 
     async def got_online(self, pres):
         """Handler method for new MUC participants"""
         fjid = pres['muc']['jid']
-        nick = pres['muc']['nick']
-        user = fjid if fjid.full else nick
-        await self.rtbl_ban(user)
+        await self.rtbl_ban(fjid)
 
     @botcmd(name="rtbl-info")
     def rtbl_info(self, rcv, _):