From b76e8313bbfaf9fb5d7dd428d4838cc7ead4b05b Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Tue, 30 Jul 2024 18:12:16 +0300 Subject: [PATCH] Reset record last_activity upon kick. --- kaikout/assets/rtbl.toml | 2 +- kaikout/xmpp/client.py | 33 +++++++++++++++++++--- kaikout/xmpp/commands.py | 60 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/kaikout/assets/rtbl.toml b/kaikout/assets/rtbl.toml index 6827dc8..ffc1734 100644 --- a/kaikout/assets/rtbl.toml +++ b/kaikout/assets/rtbl.toml @@ -2,6 +2,6 @@ # See file /usr/share/kaikout/rtbl.toml [[sources]] -description = "A general block list focussing on spam and service abuse." +description = "A general block list focusing on spam and service abuse." jabber_id = "xmppbl.org" node_id = "muc_bans_sha256" diff --git a/kaikout/xmpp/client.py b/kaikout/xmpp/client.py index bf42a84..3a22c6d 100644 --- a/kaikout/xmpp/client.py +++ b/kaikout/xmpp/client.py @@ -419,10 +419,35 @@ class XmppClient(slixmpp.ClientXMPP): noticed_jids = self.settings[room]['inactivity_notice'] if result == 'Inactivity': if jid_bare in noticed_jids: noticed_jids.remove(jid_bare) - await XmppCommands.kick(self, room, alias, reason) - message_to_participant = ( - 'You were expelled from groupchat {} due to ' - 'being inactive for {} days.'.format(room, span)) + # FIXME Counting and creating of key entry "score_inactivity" appear not to occur. + score_inactivity = XmppCommands.raise_score_inactivity(self, room, jid_bare, db_file) + if score_inactivity > 10: + jid_bare = await XmppCommands.outcast(self, room, alias, reason) + # admins = await XmppMuc.get_affiliation_list(self, room, 'admin') + # owners = await XmppMuc.get_affiliation_list(self, room, 'owner') + moderators = await XmppMuc.get_role_list( + self, room, 'moderator') + # Report to the moderators. + message_to_moderators = ( + 'Participant {} ({}) has been banned from ' + 'groupchat {} due to being inactive for over {} times.'.format( + alias, jid_bare, room, score_inactivity)) + for alias in moderators: + # jid_full = presence['muc']['jid'] + jid_full = XmppMuc.get_full_jid(self, room, alias) + XmppMessage.send(self, jid_full, message_to_moderators, 'chat') + # Inform the subject. + message_to_participant = ( + 'You were banned from groupchat {} due to being ' + 'inactive for over {} times. Please contact the ' + ' moderators if you think this was a mistake' + .format(room, score_inactivity)) + else: + await XmppCommands.kick(self, room, alias, reason) + message_to_participant = ( + 'You were expelled from groupchat {} due to ' + 'being inactive for over {} days.'.format(room, span)) + XmppCommands.remove_last_activity(self, room, jid_bare, db_file) elif result == 'Warning' and jid_bare not in noticed_jids: noticed_jids.append(jid_bare) time_left = int(span) diff --git a/kaikout/xmpp/commands.py b/kaikout/xmpp/commands.py index 72474df..f9c3d62 100644 --- a/kaikout/xmpp/commands.py +++ b/kaikout/xmpp/commands.py @@ -410,6 +410,66 @@ class XmppCommands: Toml.update_jid_settings(self, room, db_file, 'last_activity', activity) + def remove_last_activity(self, room, jid_bare, db_file): + """ + Remove last message activity. + + Parameters + ---------- + room : str + Jabber ID. + db_file : str + Database filename. + jid_bare : str + Jabber ID. + + Returns + ------- + result. + + """ + activity = self.settings[room]['last_activity'] if 'last_activity' in self.settings[room] else {} + del activity[jid_bare] + Toml.update_jid_settings(self, room, db_file, 'last_activity', activity) + + + def raise_score_inactivity(self, room, alias, db_file): + """ + Raise score by one. + + Parameters + ---------- + room : str + Jabber ID. + alias : str + Alias. + db_file : str + Database filename. + + Returns + ------- + result. + + """ + status_message = '✒️ Writing a score against {} for {}'.format(alias, 'inactivity') + self.action_count += 1 + task_number = self.action_count + if room not in self.actions: self.actions[room] = {} + self.actions[room][task_number] = status_message + XmppStatus.send_status_message(self, room) + scores_inactivity = self.settings[room]['scores_inactivity'] if 'scores_inactivity' in self.settings[room] else {} + jid_full = XmppMuc.get_full_jid(self, room, alias) + if jid_full: + jid_bare = jid_full.split('/')[0] + scores_inactivity[jid_bare] = scores_inactivity[jid_bare] + 1 if jid_bare in scores_inactivity else 1 + Toml.update_jid_settings(self, room, db_file, 'scores_inactivity', scores_inactivity) + time.sleep(5) + del self.actions[room][task_number] + XmppStatus.send_status_message(self, room) + result = scores_inactivity[jid_bare] if jid_full and jid_bare else 0 + return result + + async def restore_default(self, room, db_file, key=None): if key: value = self.defaults[key]