This commit is contained in:
0xd3d0c3d 2022-08-25 18:06:41 -05:00
parent 5601c71e46
commit 0444fcbf16
5 changed files with 164 additions and 43 deletions

@ -45,7 +45,18 @@ telegram, discord and offers up a newer way of unifying those services in one co
```
---
## TODO
-
- convert escaped irc color codes back to terminal codes for ansi_plugin.py
## Changelog - v2.666-2
- plugins/ansi_plugin.py is an ansi recapture utility.. basically if someone is pumping ansi art into a
- channel this will copy it 1:1 but for the intent of using 'ansipants', converting the graphic to an image
- and then re-uploading the image rather than the ansi/utf8 to discord/matrix/telegram due to the fact they
- easily or properly display ansi graphics but they show images.
## Changelog - v2.666-1
- plugins/net_hydra_plugin.py is a multiband wrapper that i use as a headless hydra code/debug logic.
- meaning a core, that stripped of services will always be online, so no matter what a presensce is online.
- anything non core is a dupe, aka hydra.. one may run the ai one machine, and another may just be that im
- coding something and dont want service to go offline and yet i myself require them to code. so that is
- why and how this hydra logic is used, and it because of features of sasl authentication that it's done.
## Changelog - v2.666
- fixed bridge responses double echoing
- simplified the calling of some plugins
@ -141,7 +152,8 @@ export DISCORD__TOKEN=AT2Sh4g.G1M9vNTOXmIaQzdvn5b6QzQMTyTBX6COJONUIRjLWi5UX0j294
export TELEGRAM_TOKEN=AHh4DA9FgE3vs1SfAnx8975t85J30mU925GhJWcoUBBo7 # <- TELEGRAM API KEY
export HYDRA_DESIGNATION=dupe # <- DEBUG CORE OR DUPE
export HYDRA_HOME=#b0tsh0p # <- DEBUG HOME CHANNEL
export HYDRA_PURPOSE="this particular hydra head is for bla bla bla" # <- DEBUG HYDRA NOTES
export ANSI_HOME=#b0tsh0p # <- NETSPAN ART DEBUGGING
```
---
# Usage

96
plugins/ansi_plugin.py Normal file

@ -0,0 +1,96 @@
# -*- coding: utf-8 -*- ############################################################### SOF
from irc3.plugins.command import command
from irc3.plugins.cron import cron
from datetime import datetime
import irc3,re,os,asyncio
###########################################################################################
dr1p_home=os.environ['ANSI_HOME']
###########################################################################################
class EIO():
#######################################################################################
def __init__(self):
self.regex=re.compile("\x03(?:\d{1,2}(?:,\d{1,2})?)?",re.UNICODE)
self.buffering=False
self.count=0
self.lastcount=-1
self.cycle=0
self.sorted=[]
self.sorting=[]
#######################################################################################
def push(self,nick,channel,dataline,hexdataline):
###################################################################################
if self.buffering==False:
self.sorting.append([nick,True,channel,[datetime.now().timestamp()],[dataline],[hexdataline]])
self.buffering=True
###################################################################################
try:
for x in self.sorting:
if x[0]==nick:
if x[1]:
x[3].append(datetime.now().timestamp())
x[4].append(dataline)
x[5].append(hexdataline)
###################################################################################
except Exception as e:
pass
###########################################################################################
@irc3.plugin
class Plugin:
#######################################################################################
def __init__(self, bot):
self.bot=bot
self.bot.eio=EIO()
#######################################################################################
@irc3.event(irc3.rfc.PRIVMSG)
def on_privmsg(self,mask=None,event=None,target=None,data=None,**kw):
if mask.nick==self.bot.nick: return
hexdataline=''
inverse=self.bot.eio.regex.sub("",data)
if inverse!=data:
for c in data:
hexdataline+=hex(ord(c))[2:].upper()
self.bot.eio.push(mask.nick,target,data,hexdataline)
####################################################################################### EOF
@cron('* * * * * */1')
def eio_cron(bot):
eio=bot.eio
if bot.eio.buffering==True:
eio.cycle+=1
for z,entry in enumerate(eio.sorting):
if entry[1]:
timestamps=entry[3]
bot.eio.lastcount=bot.eio.count
bot.eio.count=len(timestamps)
if bot.eio.count!=bot.eio.lastcount:
return
timestamps.reverse()
distances=[]
for i in range(0,len(timestamps)-1):
distance=timestamps[i]-timestamps[i+1]
distances.append(distance)
longest_distance=max(distances)
timestamp=datetime.now().timestamp()
active_distance=timestamp-timestamps[0]
if active_distance>longest_distance*1.5:
eio.sorting[z][1]=False
nick=eio.sorting[z][0]
channel=eio.sorting[z][2]
eio.sorted.append([nick,channel,entry[4],entry[5]])
eio.sorting.remove(eio.sorting[z])
eio_sorted=eio.sorted[-1]
for dataline in eio_sorted[2]:
bot.privmsg(dr1p_home,dataline)
###################################################################################
SELF_DISABLE_FLAG=True
try:
for eio_sorting in eio.sorting:
for isnotdisabled in eio_sorting[1]:
if isnotdisabled: SELF_DISABLE_FLAG=False
###################################################################################
except:
pass
###################################################################################
if SELF_DISABLE_FLAG:
bot.privmsg(dr1p_home,'no more remaining anticipated control code buffers, disabling cleanup cronjob')
bot.eio.buffering=False
####################################################################################### EOF

@ -8,45 +8,55 @@ from random import randint as rint
from random import shuffle
from datetime import datetime
###########################################################################################
class dr1p:
def __init__():
dr1p.designation=""
dr1p.enforcing=False
dr1p.purpose=""
dr1p.color=""
dr1p.token=""
dr1p.home=""
###########################################################################################
@irc3.plugin
class Plugin:
#######################################################################################
def __init__(self,bot):
self.bot=bot
token=""
self.color=""
dr1p.color=""
try:
self.mode=os.environ['HYDRA_DESIGNATION']
self.home=os.environ['HYDRA_HOME']
self.enforcing=False
dr1p.purpose=os.environ['HYDRA_PURPOSE']
dr1p.designation=os.environ['HYDRA_DESIGNATION']
dr1p.home=os.environ['HYDRA_HOME']
dr1p.enforcing=False
except:
self.mode="dupe"
self.enforcing=False
dr1p.designation="dupe"
dr1p.enforcing=False
return
if self.mode=="core": self.color="\x0304"
if dr1p.designation=="core": dr1p.color="\x0304"
for i in range(7): token+=hex(rint(0,255))[2:].zfill(2).upper()
token+=hex(int(datetime.now().timestamp()))[-4:].upper()
token=list(token)
shuffle(token)
self.token=''.join(token)
dr1p.token=''.join(token)
#######################################################################################
def server_ready(self):
if not self.mode=='core':
self.bot.privmsg("maple",f"[hydra:{self.token}] - dupe - connected")
if not dr1p.designation=='core':
self.bot.privmsg("maple",f"[hydra:{dr1p.token}] - dupe - connected")
else:
self.bot.privmsg("maple",f"core - connected")
#######################################################################################
@irc3.event(irc3.rfc.ERR_NICK)
def on_errnick(self,srv=None,retcode=None,me=None,nick=None,data=None):
###################################################################################
if not self.mode=='core': return
if not dr1p.designation=='core': return
msg=f'err_nick - srv:{srv} - retcode:{retcode} - me:{me} - nick:{nick} - data:{data}'
self.bot.privmsg("maple",msg.lower())
#######################################################################################
@irc3.event(irc3.rfc.NEW_NICK)
def on_newnick(self,nick=None,new_nick=None):
###################################################################################
if not self.mode=='core': return
if not dr1p.designation=='core': return
if nick==self.bot.config['nick'] or new_nick==self.bot.config['nick']:
msg=f'new_nick - nick:{nick} - new_nick:{new_nick}'
self.bot.privmsg("maple",msg.lower())
@ -54,58 +64,60 @@ class Plugin:
@irc3.event(irc3.rfc.CTCP)
def on_ctcp(self,mask=None,event=None,target=None,ctcp=None):
###################################################################################
if not self.mode=='core': return
if not dr1p.designation=='core': return
msg=f'ctcpd - mask:{mask} - event:{event} - target:{target} - ctcp:{ctcp}'
self.bot.privmsg("maple",msg.lower())
#######################################################################################
@irc3.event(irc3.rfc.INVITE)
def on_invite(self,mask=None,channel=None):
###################################################################################
if not self.mode=='core': return
if not dr1p.designation=='core': return
msg=f'invited - mask:{mask} - channel:{channel}'
self.bot.privmsg("maple",msg.lower())
#######################################################################################
@irc3.event(irc3.rfc.KICK)
def on_kick(self,mask=None,event=None,channel=None,target=None,data=None):
###################################################################################
if not self.mode=='core': return
if not dr1p.designation=='core': return
msg=f'kicked - mask:{mask} - event:{event} - target:{target} - data:{data}'
self.bot.privmsg("maple",msg)
#######################################################################################
@irc3.event(irc3.rfc.PRIVMSG)
def on_privmsg(self,mask=None,event=None,target=None,data=None,**kw):
###################################################################################
if self.enforcing==False: return
# if dr1p.enforcing==False: return
if target!=self.bot.config['nick'] and mask.nick==self.bot.nick: return
if mask.nick==self.bot.nick and target==self.bot.config['nick'] and self.mode=='core':
if mask.nick==self.bot.nick and target==self.bot.config['nick'] and dr1p.designation=='core':
if data.endswith('dupe - connected'):
_token=data.split("[hydra:")[1].split("]")[0]
_nekot=_token[::-1]
msg=f'[TOKEN:{_token}] - [NEKOT:{_nekot}] - COLOR:{rint(16,87)}'
self.bot.privmsg(self.bot.config['nick'],msg)
if mask.nick==self.bot.nick and target==self.bot.config['nick'] and self.mode=='dupe':
if mask.nick==self.bot.nick and target==self.bot.config['nick'] and dr1p.designation=='dupe':
if not data.find('NEKOT')==-1:
_token=data.split(":")[1].split("]")[0]
if _token.lower()==self.token.lower():
if _token.lower()==dr1p.token.lower():
if not data.find("] - [NEKOT:")==-1:
_nekot=data.split("] - [NEKOT:")[1].split("]")[0]
if _token.lower()==_nekot[::-1].lower():
_color=int(data.split(" - COLOR:")[1].strip())
if not self.color:
self.color=f"\x03{str(_color)}"
if self.mode=='core':
msg=f"{self.color}[maple:{self.token}] - "
if not dr1p.color:
dr1p.color=f"\x03{str(_color)}"
if dr1p.designation=='core':
msg=f"{dr1p.color}[maple:{dr1p.token}] - "
else:
try:
msg=f"{self.color}[hydra:{self.token}] - "
msg=f"{dr1p.color}[hydra:{dr1p.token}] - "
except:
self.color="\x0303"
msg=f"{self.color}[hydra:{self.token}] - "
dr1p.color="\x0303"
msg=f"{dr1p.color}[hydra:{dr1p.token}] - "
if mask.nick!=self.bot.config['nick']:
if target!=dr1p.home: return
if target==dr1p.home: return
msg+=f'event:{event} - mask:{mask} - target:{target} - data:'
msg+=f'{data}'
if kw: msg+=f" - kw:{kw}"
self.bot.privmsg(self.home,msg.lower())
self.bot.privmsg(dr1p.home,msg.lower())
#######################################################################################
@irc3.event(irc3.rfc.MY_PRIVMSG)
def on_my_privmsg(self,mask=None,event=None,target=None,data=None,**kw):
@ -120,27 +132,27 @@ class Plugin:
###############################################################################
if kw['event']=='JOIN':
self.bot.privmsg("maple",f"joined {target}".lower())
if target!=self.home:
if self.enforcing:
if target!=dr1p.home:
if dr1p.enforcing:
reason=".[d]."
self.bot.part(target,reason)
self.bot.privmsg("maple",f"parted {target} - {reason}".lower())
if self.mode=="core":
msg=f"[maple:{self.token}] - core - maple online"
self.bot.privmsg(self.home,msg)
if dr1p.designation=="core":
msg=f"[maple:{dr1p.token}] - core - maple online - purpose: {dr1p.purpose}"
self.bot.privmsg(dr1p.home,msg)
else:
msg=f"[hydra:{self.token}] - dupe - hydra online"
self.bot.privmsg(self.home,msg)
msg=f"[hydra:{dr1p.token}] - dupe - hydra online - purpose: {dr1p.purpose}"
self.bot.privmsg(dr1p.home,msg)
if kw['event']=='PART':
if self.mode=="core":
msg=f"[maple:{self.token}] -"
if dr1p.designation=="core":
msg=f"[maple:{dr1p.token}] -"
else:
msg=f"[hydra:{self.token}] -"
msg=f"[hydra:{dr1p.token}] -"
self.bot.privmsg("maple",msg+f"parted {target} - {data}")
if kw['event']=='QUIT':
if self.mode=="core":
msg=f"[maple:{self.token}] -"
if dr1p.designation=="core":
msg=f"[maple:{dr1p.token}] -"
else:
msg=f"[hydra:{self.token}] -"
msg=f"[hydra:{dr1p.token}] -"
self.bot.privmsg("maple",msg+f"quit {target} - {data}")
####################################################################################### EOF

@ -68,6 +68,7 @@ def config_ircbot():
plugins.whoami_plugin
plugins.joke_plugin
plugins.maple_plugin
plugins.ansi_plugin
#plugins.openai_plugin
autojoins =

@ -36,7 +36,7 @@ class TELEGRAMBOT:
self.ircbot=guds.memory('ircbot')
self.dbname="telegramchat"
self.db=self.ircbot.db.getlist(self.dbname)
if not self.db: self.db=[]
if not self.db: self.db=[]
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger=logging.getLogger(__name__)