seen/spokendayandwordcount

This commit is contained in:
0xd3d0c3d 2022-07-27 07:40:41 -05:00
parent 228b32dc2a
commit cf045ef0d2

View File

@ -18,6 +18,12 @@ class Plugin:
#######################################################################################
@irc3.event(irc3.rfc.NEW_NICK)
def on_nick_change_for_seen(self, nick, new_nick):
# record of nickchanges, these are kept
# "5": {
# "msg": "_d changed nick to d",
# "time": "2021-10-03T00:24:03.040916",
# "type": "newnick"
# },
new_key = "last_msg_for_{}".format(new_nick).lower()
msg_list = self.bot.db.getlist(new_key)
if not msg_list:
@ -35,6 +41,35 @@ class Plugin:
if data.startswith("?"): return # no ?
if mask.lnick == self.bot.get_nick().lower(): return # Ignore ourseves
key = "last_msg_for_{}".format(mask.nick).lower()
messages = self.bot.db.getlist(key)
# record of did a user speak this today and if so how many words spoken
# record created:
# "41": {
# "msg": 3,
# "time": "2022-07-27",
# "type": "activity"
# },
words_count=0
if not messages:
messages = []
else:
for count, msg in enumerate(messages):
if msg.get("type") == "activity":
if msg.get("time") == datetime.now().isoformat().split('T')[0]:
words_count+=int(msg.get('msg'))
del(messages[count])
activity_msg = { "type": "activity",
"time": datetime.now().isoformat().split('T')[0],
"msg": len(data.split())+words_count }
messages.append(activity_msg)
self.bot.db.setlist(key, messages)
# all historical privmsg destroyed, and only one retained for seen
# "42": {
# "msg": "a b c d e",
# "time": "2022-07-27T07:26:41.937448",
# "type": "privmsg"
# },
key = "last_msg_for_{}".format(mask.nick).lower()
priv_msg = { "type": "privmsg",
"time": datetime.now().isoformat(),
"msg": data }