maple/storage/bot/plugins/dsa_plugin.py
2023-03-27 07:26:58 -05:00

816 lines
41 KiB
Python

# -*- coding: utf-8 -*- ############################################################### SOF
###########################################################################################
"""
- spelling - `alternate ircnicks - direct reference` - done
- messages in instances - right now only a record of 1 is indicated and that is incorrect it's only referencing last_msg
- activity timestamps - `floored to hour so there are no morethan 24 per user per day`
"""
###########################################################################################
###########################################################################################
from irc3.plugins.command import command
import asyncio
import irc3
from tool_colors_plugin import colorform as print
import os
import re
from datetime import datetime, timedelta
import timeago
from irc3.plugins.cron import cron
from time import sleep
import sqlite3
import json
###########################################################################################
###########################################################################################
D="\x02\x0315"
G="\x02\x0314"
S="\x02\x0304"
P="\x02\x0305"
X="\x02\x0307"
R="\x02\x0302"
B="\x02\x0312"
###########################################################################################
###########################################################################################
class DBIO():
#######################################################################################
#######################################################################################
history_threshold=1
idle_threshold=1
faded_threshold=14
negated=['matrixbot','van']
lurkers=[]
verified=[]
hardchatters=[]
seen_users=[]
search_users=[]
channel_users=[]
channel=[]
LOG=[]
users=[]
scanning=False
scanning_operation=False
###########################################################################################
###########################################################################################
@irc3.plugin
class Plugin:
#######################################################################################
#######################################################################################
def __init__(self,bot):
print('[ loaded ]')
self.bot=bot
self.bot.dbio=DBIO()
###################################################################################
###################################################################################
try:
self.bot.dbio.hardchatters=self.bot.db.getlist("hardchatters", [])
print(f'[ loaded database ] - hardchatters')
except Exception as e:
print(f'[ __init__ ] - hardchatter storage database: {e}')
self.bot.dbio.hardchatters=[]
###################################################################################
###################################################################################
try:
self.bot.dbio.lurkers=self.bot.db.getlist("lurkers", [])
print(f'[ loaded database ] - lurkers')
except Exception as e:
print(f'[ __init__ ] - lurkers storage database: {e}')
self.bot.dbio.lurkers=[]
#######################################################################################
#######################################################################################
@classmethod
def reload(cls, old):
return cls(old.bot)
#######################################################################################
#######################################################################################
def before_reload(self):
pass
#######################################################################################
#######################################################################################
def after_reload(self):
pass
#######################################################################################
#######################################################################################
def log(self,s):
print(s)
self.bot.dbio.LOG.append(s)
#######################################################################################
#######################################################################################
@irc3.extend
def log_play(self,target):
for _ in self.bot.dbio.LOG:
self.bot.privmsg(target,_);
print(_)
self.bot.dbio.LOG=[]
#######################################################################################
#######################################################################################
def dbentry_add(self,database,record):
buffer=self.bot.db.getlist(database,[])
buffer.append(record)
buffer=list(set(buffer))
buffer.sort()
exec(f'self.bot.dbio.{database}=buffer')
self.bot.db.setlist(database,buffer)
self.bot.privmsg("#PalletTown",f'{X}[ {G}added {record} entry to {database} database {X}]')
#######################################################################################
#######################################################################################
def dbentry_remove(self,database,record):
buffer=self.bot.db.getlist(database,[])
status=False
if record in buffer:
buffer.remove(record)
status=True
buffer=list(set(buffer))
buffer.sort()
exec(f'self.bot.dbio.{database}=buffer')
self.bot.db.setlist(database,buffer)
self.bot.privmsg("#PalletTown",f'{X}[ {G}removed {record} entry from {database} database - status: {status} {X}]')
#######################################################################################
#######################################################################################
async def epochtimestamp(self,timestamp):
year,month,day=timestamp.split('T')[0].split('-')
hour,minute,second=timestamp.split('T')[1].split(':')
second,millisecond=second.split('.')
year,month,day,hour,minute,second,millisecond=[int(x) for x in [year,month,day,hour,minute,second,millisecond]]
epoch_timestamp_past=datetime(year,month,day,hour,minute,second,millisecond).timestamp()
return epoch_timestamp_past
#######################################################################################
#######################################################################################
async def epochdelta(self,timestamp):
year,month,day=timestamp.split('T')[0].split('-')
hour,minute,second=timestamp.split('T')[1].split(':')
second,millisecond=second.split('.')
year,month,day,hour,minute,second,millisecond=[int(x) for x in [year,month,day,hour,minute,second,millisecond]]
epoch_timestamp_past=datetime(year,month,day,hour,minute,second,millisecond).timestamp()
epoch_timestamp_present=datetime.now().timestamp()
epochdelta=epoch_timestamp_present-epoch_timestamp_past
distance=timeago.format(timedelta(seconds=epochdelta),datetime.now())
return distance
#######################################################################################
#######################################################################################
@irc3.event(irc3.rfc.NEW_NICK)
def on_nick_change_for_dsa_hardchatradar(self, nick, new_nick):
for _ in self.bot.channels.keys():
if _[0]=="#":
USER=str(new_nick).lower()
self.dsa_hardchatradar(USER,_)
#######################################################################################
#######################################################################################
@irc3.event(irc3.rfc.JOIN)
def on_channel_join_for_dsa_hardchatradar(self,mask,channel,**kw):
USER=str(mask.nick).lower
self.dsa_hardchatradar(mask.nick,channel)
#######################################################################################
#######################################################################################
def db_recurse(self):
dbname='databases/maple_db.sqlite'
con = sqlite3.connect(dbname)
cursor = con.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
self.bot.dbio.seen_users=[]
for i,_ in enumerate(tables):
print(f'{i} - {_[0]}')
cursor.execute("SELECT * FROM "+_[0]+";")
rows = cursor.fetchall()
k=[ x[0] for x in rows ]
for y in range(len(k)):
try:
if rows[y][0].startswith('last_msg_for_'):
self.bot.dbio.seen_users.append(rows[y][0].replace("last_msg_for_",""))
except:
pass
###################################################################################
###################################################################################
def dsa_hardchatradar(self, USER, channel):
"""radar for hardchatters who join a channel"""
###################################################################################
###################################################################################
try:
if not USER == self.bot.nick:
self.bot.dbio.LOG=[]
asyncio.set_event_loop(self.bot.loop)
asyncio.run_coroutine_threadsafe(self.bot._dsa_scan(USER,channel),self.bot.loop)
# while len(self.bot.dbio.LOG) > 0:
# self.bot.log_play("#pallettown")
except Exception as e:
msg=f'error: dsa_plugin:hardchat_radar - {e}'
print(msg); #self.bot.privmsg(channel,self.bot.emo(msg))
#######################################################################################
#######################################################################################
@command(permission='view')
def dsa_add_hardchatter(self, mask, target, args):
"""dsa_add_hardchatter
%%dsa_add_hardchatter <message>...
"""
try:
OP_FLAG=False
channel = self.bot.channels[target]
for _, nick in channel.modes.items():
for __ in _:
modes=["%","@","&","~"]
if __ in modes:
if mask.nick in nick:
OP_FLAG=True
if OP_FLAG:
user = ''.join(args['<message>'])
self.dbentry_add('hardchatters',user)
self.bot.privmsg(target, self.bot.emo(f'hardchatter: {user}'))
cmd=f"MODE {target} +v {user}"
self.bot.send(cmd)
else:
return
except Exception as e:
msg=f'error: dsa_plugin:dsa_add_hardchatter > {e}'
print(msg); #self.bot.privmsg(target,self.bot.emo(msg))
#######################################################################################
#######################################################################################
@command(permission='view')
def dsa_del_hardchatter(self, mask, target, args):
"""dsa_del_hardchatter
%%dsa_del_hardchatter <message>...
"""
user = ''.join(args['<message>'])
try:
OP_FLAG=False
channel = self.bot.channels[target]
for _, nick in channel.modes.items():
for __ in _:
modes=["%","@","&","~"]
if __ in modes:
if mask.nick in nick:
OP_FLAG=True
if OP_FLAG:
self.dbentry_remove('hardchatters',user)
self.bot.privmsg(target, self.bot.emo(f'softchatted: {user}'))
cmd=f"MODE {target} -v {user}"
self.bot.send(cmd)
else:
return
except Exception as e:
msg=f'error: dsa_plugin:dsa_del_hardchatter > {e}'
print(msg); #self.bot.privmsg(target,self.bot.emo(msg))
#######################################################################################
#######################################################################################
@command(permission='view')
def dsa_list_hardchatters(self, mask, target, args):
"""dsa_list_hardchatters
%%dsa_list_hardchatters
"""
try:
OP_FLAG=False
channel = self.bot.channels[target]
for _, nick in channel.modes.items():
for __ in _:
modes=["%","@","&","~"]
if __ in modes:
if mask.nick in nick:
OP_FLAG=True
if OP_FLAG:
if self.bot.dbio.hardchatters:
_msg = re.findall(r'.{1,400}(?:\s+|$)', f'{B}hardchatters: {X}{self.bot.dbio.hardchatters}')
for _ in _msg:
self.bot.privmsg(target,self.bot.emo(_))
else:
self.bot.privmsg(target,self.bot.emo(f"{R}no hardchatters"))
else:
return
except Exception as e:
msg=f'error: dsa_plugin:hardchatters > {e}'
print(msg); #self.bot.privmsg(target,self.bot.emo(msg))
#######################################################################################
#######################################################################################
@command(permission='view')
def dsa_list_lurkers(self, mask, target, args):
"""dsa_list_lurkers
%%dsa_list_lurkers
"""
try:
OP_FLAG=False
channel = self.bot.channels[target]
for _, nick in channel.modes.items():
for __ in _:
modes=["%","@","&","~"]
if __ in modes:
if mask.nick in nick:
OP_FLAG=True
if OP_FLAG:
if self.bot.dbio.lurkers:
_msg = re.findall(r'.{1,400}(?:\s+|$)', f'{B}lurkers: {X}{self.bot.dbio.lurkers}')
for _ in _msg:
self.bot.privmsg(target, self.bot.emo(_))
else:
self.bot.privmsg(target, self.bot.emo(f"{R}no lurkers"))
except Exception as e:
msg=f'error: dsa_plugin:dsa_list_lurkers > {e}'
print(msg); #self.bot.privmsg(target,self.bot.emo(msg))
#######################################################################################
#######################################################################################
@command(permission='admin', public=True, show_in_help_list=False)
def dsa_analyze(self,mask,target,args):
"""dsa_analyze
%%dsa_analyze <message>...
"""
self.db_recurse()
data=''.join(args['<message>']).strip()
###################################################################################
###################################################################################
nicks=[]; key=''; USER=data.lower(); SEARCH_FLAG=False
###################################################################################
###################################################################################
try:
key=self.bot.db.getlist(f'last_msg_for_{USER}')
except Exception as e:
print(f'error: dsa:nicks -> pulling db key for last_msg_for: {e}')
if len(USER) > 1:
if not key:
SEARCH_FLAG=True
self.bot.dbio.search_users=[]
IS_RUNNING=True
LOOP=1
if SEARCH_FLAG:
for _ in self.bot.dbio.seen_users:
if not _.find(USER)==-1:
self.bot.dbio.search_users.append(_.split('last_msg_for_')[-1].split('":')[0])
LOOP=len(self.bot.dbio.search_users)
for i in range(0,LOOP):
if SEARCH_FLAG:
try:
USER=self.bot.dbio.search_users[i]
key=self.bot.db.getlist(f'last_msg_for_{USER}')
except:
IS_RUNNING=False
msg=f"{B}< {R}no {G}{USER} {R}ircnick(s) or similar were found {B}>"
self.bot.privmsg(target,msg)
###############################################################################
###############################################################################
newnicks=0; privmsgs=0; lastmsg=[]; lasttime=[]
###############################################################################
###############################################################################
try:
for _ in key:
if _['type']=='newnick':
newnicks+=1
elif _['type']=='privmsg':
privmsgs+=1
lastmsg.append(_['msg'])
lasttime.append(_['time'])
except Exception as e:
print(f'error: dsa:nicks:search -> no items of a key means no db operation: {e}')
self.bot.privmsg("#PalletTown",f'{"#"*69}')
if newnicks>0 or privmsgs>0:
self.bot.privmsg("#PalletTown",f"{D}<<< {G}{USER} {B}- {G}ircnicks{B}: {D}{int(newnicks)+1} {B}- {G}messages{B}: {G}{privmsgs} {D}>>>")
if privmsgs>0:
for i in range(0,privmsgs):
self.bot.privmsg("#PalletTown",f'{"#"*69}')
self.bot.privmsg("#PalletTown",f'{G}{lasttime[i]} {B}> {R}{USER} {B}> {D}{lastmsg[i]}')
if newnicks==0:
self.bot.privmsg("#PalletTown",f'{"#"*69}');
self.bot.privmsg("#PalletTown",f"!!! no alternate ircnicks !!!")
# self.log_play(target)
if i==0 and not SEARCH_FLAG:
IS_RUNNING=False
return
elif i==LOOP and SEARCH_FLAG:
IS_RUNNING=False
return
self.bot.privmsg("#PalletTown",f'{"#"*69}')
while IS_RUNNING:
if not SEARCH_FLAG:
msg=f"{D}<<< {R}near region{D} >>>"
else:
msg=f"{D}<<< {R}near region - issues{D} >>>"
self.bot.privmsg("#PalletTown",msg); self.bot.privmsg("#PalletTown",f'{"#"*69}')
for _ in key:
if _['type']=='newnick':
f,t=_['msg'].split(' changed nick to ')
self.bot.privmsg("#PalletTown",f'{D}{_["time"]} {B}> {R}from ircnick {G}{f} {R}to ircnick {G}{t}')
nicks.append(f)
nicks=list(set(nicks))
if len(nicks)>0:
self.bot.privmsg("#PalletTown",f'{"#"*69}')
if not SEARCH_FLAG:
msg=f'{D}[ {G}{USER} {D}- {R}alternate ircnicks - direct reference{D}]{B}: {R}{" ".join(nicks)}'
else:
msg=f'{D}[ {G}{USER} {D}- {R}alternate ircnicks - keyworded{D}]{B}: {R}{" ".join(nicks)}'
self.bot.privmsg("#PalletTown",msg); self.bot.privmsg("#PalletTown",f'{"#"*69}'); self.bot.privmsg("#PalletTown",f"{D}<<< {R}distant region{D} >>>"); self.bot.privmsg("#PalletTown",f'{"#"*69}')
for _ in nicks:
self.bot.privmsg("#PalletTown",f'{B}[ {R}{_} {B}]')
try:
key=self.bot.db.getlist(f'last_msg_for_{_}')
for __ in key:
if __['type']=='privmsg':
self.bot.privmsg("#PalletTown",f'{D}{__["time"]} {B}> {R}{_} {B}> {D}{__["msg"]}"')
elif __['type']=='newnick':
f,t=__['msg'].split(' changed nick to ')
self.bot.privmsg("#PalletTown",f'{D}{__["time"]} {B}> {R}to ircnick {B}{t} {R}from ircnick {G}{f}')
oldkey=""
IS_OK=True
while IS_OK==True:
try:
keysub=self.bot.db.getlist(f'last_msg_for_{f}')
if oldkey==keysub:
break
oldkey=keysub
for ___ in keysub:
if ___['type']=='newnick':
f,t=___['msg'].split(' changed nick to ')
self.bot.privmsg("#PalletTown",f'{D}{___["time"]} {B}> {R}to ircnick {G}{t} {R}from ircnick {G}{f}"')
elif __['type']=='privmsg':
self.bot.privmsg("#PalletTown",f'{D}{__["time"]} {B}> {R}{_} {B}> {D}{__["msg"]}"')
except Exception as e:
IS_OK=False
print(f'error: dsa:dirties:IS_OK -> pulling db key for last_msg_for_{f}: {e}')
except Exception as e:
self.bot.privmsg("#PalletTown",f'{D}<{R}none{D}>')
print(f'error: dsa:dirties -> pulling db key for last_msg_for_{_}: {e}')
if SEARCH_FLAG:
self.bot.privmsg("#PalletTown",f'{B}<<< {R}total instances found{X}: {R}{LOOP} {B}>>>')
#self.log_play(target)
if SEARCH_FLAG:
try:
self.search_users.reverse()
self.pop()
self.search_users.reverse()
except:
IS_RUNNING=False
else:
IS_RUNNING=False
#######################################################################################
#######################################################################################
@irc3.extend
async def _dsa_scan(self,NICK,target):
###################################################################################
###################################################################################
self.bot.privmsg("#PalletTown",f'{"#"*69}');
msg=f'{G}<<< {S}analyzing {NICK} {G}>>>'
self.bot.privmsg("#PalletTown",msg)
_ = NICK
USER=_.lower()
self.dsa_analyze(mask=None,target=target,args={'<message>': [NICK]})
try:
key=self.bot.db.getlist(f'last_msg_for_{USER}')
if key==None:
self.bot.privmsg("#PalletTown",f'{"#"*69}')
if USER in self.bot.dbio.negated:
if not USER in self.bot.dbio.hardchatters:
self.dbentry_add('hardchatters',USER)
msg=f'{G}!!! whitelisted user - no record !!'
self.bot.privmsg(msg)
else:
msg=f'{G}!!! already in whitelisted db - no record !!!'
self.bot.privmsg("#PalletTown",msg)
else:
if not USER in self.bot.dbio.lurkers:
self.dbentry_add('lurkers',USER)
msg=f'{G}!!! given a lurker status - no record !!!'
self.bot.privmsg("#PalletTown",msg)
if USER in self.bot.dbio.hardchatters:
msg=f'{G}!!! has a hardchat override despite lurker status !!!'
self.bot.privmsg("#PalletTown",msg)
else:
msg=f'{G}!!! already in lurker db - no record !!!'
self.bot.privmsg("#PalletTown",msg)
if USER in self.bot.dbio.hardchatters:
msg=f'{G}!!! has a hardchat override despite lurker status !!!'
self.bot.privmsg("#PalletTown",msg)
if not USER in self.bot.dbio.hardchatters:
cmd=f"MODE {target} -v {USER}"
else:
cmd=f"MODE {target} +v {USER}"
self.bot.send(cmd)
else:
self.bot.privmsg("#PalletTown",f'{"#"*69}')
records=len(key)
records_timestamps=[]
records_privmsgs=[]
records_newnicks=[]
activities=0
activities_total_words=0
activities_total_msgs=0
newnicks=0
for _key in key:
if _key['type']=='privmsg':
try:
timestamp=await self.epochdelta(_key[-1]['time'])
records_timestamps.append(_key[-1]['time'])
records_privmsgs.append(timestamp)
except:
timestamp=await self.epochdelta(_key['time'])
records_timestamps.append(_key['time'])
records_privmsgs.append(timestamp)
elif _key['type']=='activity':
activities+=1
# MSGSCOUNT
try:
try:
activities_total_msgs+=int(_key[-1]['msgs'])
timestamp=await self.epochdelta(_key[-1]['time']+"T00:00:00.000000")
records_timestamps.append(_key[-1]['time']+"T00:00:00.000000")
records_privmsgs.append(timestamp)
except:
activities_total_msgs+=int(_key['msgs'])
timestamp=await self.epochdelta(_key['time']+"T00:00:00.000000")
records_timestamps.append(_key['time']+"T00:00:00.000000")
records_privmsgs.append(timestamp)
except:
pass
# WORDCOUNT
try:
try:
activities_total_words+=int(_key[-1]['msg'])
timestamp=await self.epochdelta(_key[-1]['time']+"T00:00:00.000000")
records_timestamps.append(_key[-1]['time']+"T00:00:00.000000")
records_privmsgs.append(timestamp)
except:
activities_total_words+=int(_key['msg'])
timestamp=await self.epochdelta(_key['time']+"T00:00:00.000000")
records_timestamps.append(_key['time']+"T00:00:00.000000")
records_privmsgs.append(timestamp)
except:
pass
else:
newnicks+=1
try:
timestamp=await self.epochdelta(_key[-1]['time'])
records_timestamps.append(_key[-1]['time'])
records_newnicks.append(timestamp)
except:
timestamp=await self.epochdelta(_key['time'])
records_timestamps.append(_key['time'])
records_newnicks.append(timestamp)
records_timestamps.sort()
faded_timestamp=await self.epochtimestamp(records_timestamps[-1])
newest_timestamp=await self.epochdelta(records_timestamps[-1])
records_timestamps.reverse()
oldest_timestamp=await self.epochdelta(records_timestamps[-1])
oldest_timestamp_epoch=await self.epochtimestamp(records_timestamps[-1])
history_timestamp=datetime.now().timestamp()-oldest_timestamp_epoch
faded_status=False
idle_status=False
idler_status=False
lurker_status=False
history_status=False
rando_status=False
hardchat_status=False
faded_threshold=int(self.bot.dbio.faded_threshold)*24*(60*60)
idle_threshold=int(self.bot.dbio.idle_threshold)*(60*60)
faded_time=datetime.now().timestamp()-faded_timestamp
idle_time=datetime.now().timestamp()-faded_timestamp
if history_timestamp>=int(self.bot.dbio.history_threshold)*24*(60*60):
history_status=True
if faded_time >= faded_threshold:
faded_status=True
if idle_time >= idle_threshold:
idle_status=True
if USER in self.bot.dbio.hardchatters:
hardchat_status=True
if USER in self.bot.dbio.lurkers:
lurker_status=True
if records_privmsgs==0:
self.dbentry_add('lurkers',USER)
lurker_status=True
msg=f'{D}history{R}: {G}{history_status}';
if not history_status:
msg+=f"{D} - {D}oldest interaction {S}< {D}30 days"
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}historicals{R}: {G}{records}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}nickchanges{R}: {G}{newnicks}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}activity days{R}: {G}{activities}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}msgscount total{R}: {G}{activities_total_msgs}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}wordcount total{R}: {G}{activities_total_words}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}last time spoken{R}: {G}{records_privmsgs[-1]}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}oldest interaction{R}: {G}{oldest_timestamp}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}newest interaction{R}: {G}{newest_timestamp}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}idle{R}: {G}{idle_status}'
if idle_status: msg+=f' {R}> {G}1 hour'
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}faded{R}: {G}{faded_status}'
if faded_status: msg+=f' {R}> {G}2 weeks'
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}lurker{R}: {G}{lurker_status}'; self.bot.privmsg("#PalletTown",msg)
if not history_status and not hardchat_status and activities_total_words<25:
rando_status=True
msg=f'{D}rando{R}: {G}{rando_status}';
if rando_status:
msg+=f"{G} - {S}no {R}history status {G}and {S}no {R}hardchat_status {G}and {R}wordcount total {S}< {R}25"
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}hardchatter{R}: {G}{hardchat_status}'; self.bot.privmsg("#PalletTown",msg)
else:
try:
if USER in self.bot.dbio.lurkers:
if not USER in self.bot.dbio.hardchatters:
msg=f'{G}{USER} {B}- {S}has a lurker status'
self.bot.privmsg("#PalletTown",msg)
lurker_status=False
self.dbentry_remove('lurkers',USER)
msg=f'{S}removed lurker status - record'
self.bot.privmsg("#PalletTown",msg)
if USER in self.bot.dbio.hardchatters:
msg=f'{S}has a lurker status yet a hardchatter'
self.bot.privmsg("#PalletTown",msg)
lurker_status=False
self.dbentry_remove('lurkers',USER)
msg=f'{S}removed lurker status - record'
self.bot.privmsg("#PalletTown",msg)
else:
if not USER in self.bot.dbio.hardchatters:
if history_status:
self.dbentry_add('hardchatters',USER)
hardchat_status=True
cmd=f"MODE {target} +v {USER}"
self.bot.send(cmd)
else:
cmd=f"MODE {target} +v {USER}"
self.bot.send(cmd)
msg=f'{D}history{R}: {G}{history_status}';
if not history_status:
msg+=f"{D} - {R}oldest interaction {S}< {R}30 days"
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}historicals{R}: {G}{records}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}nickchanges{R}: {G}{newnicks}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}activity days{R}: {G}{activities}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}msgscount total{R}: {G}{activities_total_msgs}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}wordcount total{R}: {G}{activities_total_words}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}last time spoken{R}: {G}{records_privmsgs[-1]}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}oldest interaction{R}: {G}{oldest_timestamp}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}newest interaction{R}: {G}{newest_timestamp}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}idle{R}: {G}{idle_status}'
if idle_status: msg+=f' {R}> {G}1 hour'
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}faded{R}: {G}{faded_status}'
if faded_status: msg+=f' {R}> {G}2 weeks'
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}lurker{R}: {G}{lurker_status}'; self.bot.privmsg("#PalletTown",msg)
msg=f'{D}idler{R}: {G}{idler_status}'; self.bot.privmsg("#PalletTown",msg)
if not history_status and not hardchat_status and activities_total_words<25:
rando_status=True
msg=f'{D}rando{R}: {G}{rando_status}'
if rando_status:
msg+=f"{G} - {S}no {R}history status {G}and {S}no {R}hardchat_status {G}and {R}wordcount total {S}< {R}25"
self.bot.privmsg("#PalletTown",msg)
msg=f'{D}hardchatter{R}: {G}{hardchat_status}'; self.bot.privmsg("#PalletTown",msg)
except Exception as e:
msg=f'error: dsa_plugin:hardchattting > {e}'
self.bot.privmsg("#PalletTown",msg)
except Exception as e:
msg=f'error: dsa:lurkers > {e}'
print(msg)
self.bot.privmsg("#PalletTown",msg)
#######################################################################################
#######################################################################################
@command(permission='admin', public=True, show_in_help_list=False)
@irc3.extend
def dsa_scan(self,mask,target,args):
"""tool to scan and designate
%%dsa_scan
"""
OP_FLAG=False
CHANNEL="#tcpdirect"
self.bot.dbio.LOG=[]
channel=self.bot.channels[CHANNEL]
if not mask.nick==self.bot.nick:
for _, nick in channel.modes.items():
for __ in _:
modes=["%","@","&","~"]
if __ in modes:
if mask.nick in nick:
OP_FLAG=True
else:
OP_FLAG=True
if OP_FLAG:
msg=f'{G}<<< {S}analyzing {CHANNEL} users {G}>>>'
self.bot.privmsg("#PalletTown",msg)
if not target in self.bot.dbio.channel:
self.bot.dbio.channel.append(target)
self.bot.dbio.channel_users.append(channel)
else:
index=self.bot.dbio.channel.index(target)
self.bot.dbio.channel_users[index]=self.bot.channels[target]
self.bot.dbio.users=list([ x for x in channel ])
asyncio.set_event_loop(self.bot.loop)
for _ in self.bot.dbio.users:
asyncio.run_coroutine_threadsafe(self.bot._dsa_scan(_,"#tcpdirect"),self.bot.loop)
asyncio.run_coroutine_threadsafe(asyncio.sleep(0.5),self.bot.loop)
# while len(self.bot.dbio.LOG) > 0:
# self.bot.log_play("#pallettown")
#######################################################################################
#######################################################################################
@command(permission='admin', public=True, show_in_help_list=True)
def dsa_set_threshold_history(self,mask,target,args):
"""dsa_set_threshold_history - sets a threshold by distance in days - if there is no record within that amount of time then they fall below this threshold and will be marked with no history, this is used to indicate if a user is a rando or a known user. default value is 30 days. 90 day threshold example: ?dsa_set_threshold_history 90
%%dsa_set_threshold_history <message>...
"""
data=''.join(args['<message>']).strip()
try:
self.bot.dbio.history_threshold=int(data)
msg=f'{R}{mask.nick}{B}: {R}dsa_plugin:dsa_history_threshold set to {B}{data} days'
except Exception as e:
msg=f'{mask.nick}: error - dsa_plugin:dsa_history_threshold > {e}'
print(msg); self.bot.privmsg(target,self.bot.emo(msg))
#######################################################################################
#######################################################################################
@command(permission='admin', public=True, show_in_help_list=True)
def dsa_set_threshold_faded(self,mask,target,args):
"""dsa_set_threshold_faded - sets a threshold by distance in days to mark a user awol - if there is no record within that amount of time then they fall below this threshold and will be marked awol. default value is 14 days. 90 day threshold example: ?dsa_set_threshold_faded 90
%%dsa_set_threshold_faded <message>...
"""
data=''.join(args['<message>']).strip()
try:
self.bot.dbio.faded_threshold=int(data)
msg=f'{R}{mask.nick}{B}: {R}dsa_plugin:dsa_faded_threshold set to {B}{data} days'
except Exception as e:
msg=f'{mask.nick}: error - dsa_plugin:dsa_faded_threshold > {e}'
print(msg); self.bot.privmsg(target,self.bot.emo(msg))
#######################################################################################
#######################################################################################
@command(permission='admin', public=True, show_in_help_list=True)
def dsa_set_threshold_idle(self,mask,target,args):
"""dsa_set_threshold_idle - sets a threshold by distance in hours - if there is no record within that amount of time then they fall below this threshold and will be marked idle. default value is 1 hour. 3 hour threshold example: ?dsa_set_threshold_idle 3
%%dsa_set_threshold_idle <message>...
"""
data=''.join(args['<message>']).strip()
try:
self.bot.dbio.history_threshold=int(data)
msg=f'{R}{mask.nick}{B}: {R}dsa_plugin:dsa_history_threshold set to {B}{data} days'
except Exception as e:
msg=f'{mask.nick}: error - dsa_plugin:dsa_history_threshold > {e}'
print(msg); self.bot.privmsg(target,self.bot.emo(msg))
###########################################################################################
####################################################################################### EOF