Correctly check for new blacklisted hashed JIDs.
This commit is contained in:
parent
a2e5f652da
commit
f167625765
4 changed files with 14 additions and 46 deletions
|
@ -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):
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
__version__ = '0.0.7'
|
||||
__version_info__ = (0, 0, 7)
|
||||
__version__ = '0.0.8'
|
||||
__version_info__ = (0, 0, 8)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue