# -*- 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
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):
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)
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, _):