From f16762576536039b627ec13a99b01e60d6365259 Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Thu, 21 Nov 2024 17:23:47 +0200 Subject: [PATCH] Correctly check for new blacklisted hashed JIDs. --- kaikout/utilities.py | 28 ---------------------------- kaikout/version.py | 4 ++-- kaikout/xmpp/client.py | 26 +++++++++++--------------- kaikout/xmpp/groupchat.py | 2 +- 4 files changed, 14 insertions(+), 46 deletions(-) diff --git a/kaikout/utilities.py b/kaikout/utilities.py index d481d05..63fa995 100644 --- a/kaikout/utilities.py +++ b/kaikout/utilities.py @@ -295,34 +295,6 @@ class BlockList: with open(filename, 'w') as f: f.write(content) return filename - - def add_entry_to_blocklist(self, jabber_id, node_id, item_id): - """ - Update blocklist file. - - Parameters - ---------- - jabber_id : str - Jabber ID. - node_id : str - Node name. - item_id : str - Item ID. - - Returns - ------- - None. - """ - if jabber_id not in self.blocklist['entries']: - self.blocklist['entries'][jabber_id] = {} - if node_id not in self.blocklist['entries'][jabber_id]: - self.blocklist['entries'][jabber_id][node_id] = [] - self.blocklist['entries'][jabber_id][node_id].append(item_id) - data = self.blocklist - content = tomli_w.dumps(data) - filename = BlockList.get_filename() - with open(filename, 'w') as f: f.write(content) - class String: def md5_hash(url): diff --git a/kaikout/version.py b/kaikout/version.py index 64ca029..224e2cb 100644 --- a/kaikout/version.py +++ b/kaikout/version.py @@ -1,2 +1,2 @@ -__version__ = '0.0.7' -__version_info__ = (0, 0, 7) +__version__ = '0.0.8' +__version_info__ = (0, 0, 8) diff --git a/kaikout/xmpp/client.py b/kaikout/xmpp/client.py index 09c44b3..fc99003 100644 --- a/kaikout/xmpp/client.py +++ b/kaikout/xmpp/client.py @@ -47,8 +47,8 @@ class XmppClient(slixmpp.ClientXMPP): self.data_accounts = Toml.open_file(filename_accounts) self.data_accounts_xmpp = self.data_accounts['xmpp'] # A handler for blocklist. - filename_blocklist = os.path.join(self.directory_shared, 'blocklist.toml') - self.blocklist = Toml.open_file(filename_blocklist) + self.filename_blocklist = os.path.join(self.directory_shared, 'blocklist.toml') + self.blocklist = Toml.open_file(self.filename_blocklist) # A handler for blocklist. filename_rtbl = os.path.join(self.directory_config, 'rtbl.toml') self.data_rtbl = Toml.open_file(filename_rtbl) @@ -345,21 +345,17 @@ class XmppClient(slixmpp.ClientXMPP): if subscribe['pubsub']['subscription']['subscription'] == 'subscribed': rtbl_list = await XmppPubsub.get_items(self, jabber_id, node_id) rtbl_items = rtbl_list['pubsub']['items'] + muc_bans_sha256 = self.blocklist['entries']['xmppbl.org']['muc_bans_sha256'] for item in rtbl_items: - exist = False item_id = item['id'] - for jid in self.blocklist['entries']: - for node in jid: - for item in node: - if item_id == item: - exist = True - break - if not exist: - # TODO Extract items item_payload.find(namespace + 'title') - # NOTE (Pdb) - # for i in item['payload'].iter(): i.attrib - # {'reason': 'urn:xmpp:reporting:abuse'} - BlockList.add_entry_to_blocklist(self, jabber_id, node_id, item_id) + if item_id not in muc_bans_sha256: muc_bans_sha256.append(item_id) + # TODO Extract items item_payload.find(namespace + 'title') + # NOTE (Pdb) + # for i in item['payload'].iter(): i.attrib + # {'reason': 'urn:xmpp:reporting:abuse'} + self.blocklist['entries']['xmppbl.org']['muc_bans_sha256'] = muc_bans_sha256 + Toml.save_file(self.filename_blocklist, self.blocklist) + del self.filename_blocklist # subscribe['from'] = xmppbl.org # subscribe['pubsub']['subscription']['node'] = 'muc_bans_sha256' subscriptions = await XmppPubsub.get_node_subscriptions(self, jabber_id, node_id) diff --git a/kaikout/xmpp/groupchat.py b/kaikout/xmpp/groupchat.py index 584b3d5..af3ef03 100644 --- a/kaikout/xmpp/groupchat.py +++ b/kaikout/xmpp/groupchat.py @@ -47,7 +47,7 @@ class XmppGroupchat: .format(room)) elif result == 'conflict': number = str(random.randrange(1000, 5000)) - await XmppMuc.join(self, room, alias + '_' + number) + await XmppMuc.join(self, room, alias + ' #' + number) else: mucs_join_success.append(room) logger.info('Autojoin groupchat\n'