Reset record last_activity upon kick.

This commit is contained in:
Schimon Jehudah, Adv. 2024-07-30 18:12:16 +03:00
parent b03d082d96
commit b76e8313bb
3 changed files with 90 additions and 5 deletions

View file

@ -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"

View file

@ -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)

View file

@ -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]