revision 2
This commit is contained in:
parent
d243206439
commit
0d06c6ae6e
10
Pipfile
10
Pipfile
@ -1,7 +1,7 @@
|
||||
[[source]]
|
||||
url = "https://git.tcp.direct/decoded/maple_netspan"
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "maple_netspan"
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
irc3 = "*"
|
||||
@ -18,9 +18,11 @@ lxml = "*"
|
||||
python-twitter = "*"
|
||||
googlesearch-python = "*"
|
||||
pyfiglet = "*"
|
||||
openai = "*"
|
||||
simplematrixbotlib = "*"
|
||||
ipdb = "*"
|
||||
openai = "*"
|
||||
matrix-nio = "*"
|
||||
discord = "*"
|
||||
python-telegram-bot = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
64
bot.py
64
bot.py
@ -3,61 +3,81 @@ import irc3,os,threading,asyncio,ipdb
|
||||
from time import sleep
|
||||
from plugins.tool_dims_plugin import dims
|
||||
from plugins.tool_guds_plugin import guds
|
||||
from plugins.net_irc_plugin import config_ircbot
|
||||
from plugins.net_irc_plugin import start_ircbot
|
||||
from plugins.net_matrix_plugin import start_matrixbot
|
||||
from plugins.net_irc_plugin import config_ircbot, start_ircbot
|
||||
from plugins.tool_bus_plugin import BUS
|
||||
from nio import AsyncClient, MatrixRoom, RoomMessageText
|
||||
from plugins.net_matrix_plugin import start_matrixbot
|
||||
from plugins.net_discord_plugin import start_discordbot
|
||||
# from plugins.net_irc_plugin import d_irc_msg
|
||||
# from plugins.net_matrix_plugin import d_matrix_msg
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
##################################################channel##################################
|
||||
class BOTIO:
|
||||
#######################################################################################
|
||||
verbosity=True
|
||||
log_exit_level=[]
|
||||
loop=asyncio.get_event_loop()
|
||||
#######################################################################################
|
||||
def __init__(self):
|
||||
print(f'<<< ________botio_class >>> [ instantiated ]')
|
||||
self.ircbot=config_ircbot()
|
||||
self._bio=guds.memory('__main__.bio')
|
||||
self.net_irc=[]
|
||||
self.net_matrix=[]
|
||||
self.net_discord=[]
|
||||
print(f'<<< ________botio_class >>> [ ircbot configured ]')
|
||||
#######################################################################################
|
||||
def __boot__irc(self):
|
||||
print('<<< system_status__info >>> [ booting connection: irc ]')
|
||||
print('<<< system_status__info >>> [ booting connection ] - irc')
|
||||
self=start_ircbot(self)
|
||||
#######################################################################################
|
||||
def __boot__matrix(self):
|
||||
print('<<< system_status__info >>> [ booting connection: matrix ]')
|
||||
self=start_matrixbot(self)
|
||||
print('<<< system_status__info >>> [ booting connection ] - matrix')
|
||||
self=start_matrixbot(self)
|
||||
#######################################################################################
|
||||
def __boot__discord(self):
|
||||
print('<<< system_status__info >>> [ booting connection ] - discord')
|
||||
self=start_discordbot(self)
|
||||
#######################################################################################
|
||||
def __boot__empty(self):
|
||||
print('<<< system_status__info >>> [ booting connection: empty ]')
|
||||
print('<<< system_status__info >>> [ booting connection ] - empty')
|
||||
#######################################################################################
|
||||
def __main__(self,index):
|
||||
counter=0
|
||||
if index==0:
|
||||
t=threading.Thread(target=self.__boot__irc)
|
||||
print(f'<<< system_status__info >>> [ irc thread setup ]')
|
||||
print(f'<<< system_status__info >>> [ thread setup ] - irc')
|
||||
t.start()
|
||||
print(f'<<< system_status__info >>> [ irc thread started ]')
|
||||
print(f'<<< system_status__info >>> [ thread started ] - irc')
|
||||
elif index==1:
|
||||
t=threading.Thread(target=self.__boot__matrix)
|
||||
print(f'<<< system_status__info >>> [ matrix thread setup ]')
|
||||
print(f'<<< system_status__info >>> [ thread setup ] - matrix')
|
||||
t.start()
|
||||
t.join()
|
||||
print(f'<<< system_status__info >>> [ matrix thread started ]')
|
||||
# elif index==2:
|
||||
# print(f'<<< system_status__info >>> [ empty thread setup ]')
|
||||
# t=threading.Thread(target=self.__boot__empty)
|
||||
# t.start()
|
||||
# print(f'<<< system_status__info >>> [ empty thread started ]')
|
||||
print(f'<<< system_status__info >>> [ thread started ] - matrix')
|
||||
elif index==2:
|
||||
t=threading.Thread(target=self.__boot__discord)
|
||||
print(f'<<< system_status__info >>> [ thread setup ] - discord')
|
||||
t.start()
|
||||
t.join()
|
||||
print(f'<<< system_status__info >>> [ thread started ] - discord')
|
||||
elif index==3:
|
||||
t=threading.Thread(target=self.__boot__empty)
|
||||
print(f'<<< system_status__info >>> [ thread setup ] - empty')
|
||||
t.start()
|
||||
print(f'<<< system_status__info >>> [ thread started ] - empty')
|
||||
###########################################################################################
|
||||
if __name__ == '__main__':
|
||||
print('<<< system_status__info >>> [ main startup ]')
|
||||
guds.add_credentials("@maple.or.g1mp:matrix.org")
|
||||
guds.add_credentials("@maple:pcriot.org")
|
||||
print('<<< system_status__info >>> [ main loop ] - startup')
|
||||
bio=BOTIO()
|
||||
globals()['guds'].memories.append([bio,'maple:__main__.bio'])
|
||||
for i in range(3):
|
||||
bio.log_exit_level.append(bio.__main__(i))
|
||||
counter=0
|
||||
while True:
|
||||
if bio.verbosity: print('<<< system_status__info >>> [ eventloop idler thread ]')
|
||||
sleep(1)
|
||||
####################################################################################### EOF
|
||||
counter+=1
|
||||
if counter<=15:
|
||||
print(f'<<< system_status__info >>> [ eventloop idler thread ] - not ready - system locked for {str(counter).zfill(2)}/15 seconds')
|
||||
if counter==16:
|
||||
print(f'<<< system_status__info >>> [ eventloop idler thread ] - system ready')
|
||||
sleep(1)
|
@ -8,7 +8,9 @@ from glob import glob
|
||||
from typing import Type
|
||||
import random
|
||||
import string
|
||||
import os
|
||||
import os,ipdb
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
from plugins.tool_dims_plugin import dims
|
||||
########################################################################## THE ASCII LOGO TO BE USED
|
||||
MOTD="""
|
||||
_________ _________ _________ ___ ___ _________ _________ ____ ____
|
||||
@ -384,26 +386,32 @@ class Plugin:
|
||||
class BOOMBOX_CONFIG:
|
||||
################################################################### BOOMBOX CONFIG INIT
|
||||
def __init__(self,bot):
|
||||
self.bot=bot
|
||||
self.db=[]
|
||||
self.bot.bbdb=[]
|
||||
self.database_names=['bbs_data','bbs_last','bbs_nicks','bbs_sites','bbs_token','bbs_tokenmirror']
|
||||
print(f'<<< _____boombox_plugin >>> [ database diagnostics ]')
|
||||
for index,database in enumerate(self.database_names):
|
||||
db=self.bot.db.getlist(database)
|
||||
if not db:
|
||||
print(f'<<< _____boombox_plugin >>> [ {" "*19}{index+1}/{len(self.database_names)} ] - [ missing database: {self.database_names[index]} ]')
|
||||
self.db_diagnostics(database)
|
||||
else:
|
||||
print(f'<<< _____boombox_plugin >>> [ {index+1}/{len(self.database_names)} ] - [ located database: {self.database_names[index]} ]')
|
||||
#print(f'{"#"*80} SOF')
|
||||
#print(f' pre - a database name: {database}')
|
||||
#print(f' pre - database memory: \n{self.db}')
|
||||
#print(f' pre - a datbase entry: \n{db}')
|
||||
#print(f'post - database merged: \n{db}')
|
||||
#print(f'{"#"*80} EOF')
|
||||
for _ in self.database_names:
|
||||
self.bot.bbdb.append(self.bot.db.getlist(_))
|
||||
try:
|
||||
bool(dims.checked)
|
||||
except:
|
||||
dims.checked=True
|
||||
if dims.checked:
|
||||
self.bot=bot
|
||||
self.db=[]
|
||||
self.bot.bbdb=[]
|
||||
self.database_names=['bbs_data','bbs_last','bbs_nicks','bbs_sites','bbs_token','bbs_tokenmirror']
|
||||
print(f'<<< _____boombox_plugin >>> [ database diagnostics ]')
|
||||
for index,database in enumerate(self.database_names):
|
||||
db=self.bot.db.getlist(database)
|
||||
if not db:
|
||||
print(f'<<< _____boombox_plugin >>> [ {" "*19}{index+1}/{len(self.database_names)} ] - [ missing database: {self.database_names[index]} ]')
|
||||
self.db_diagnostics(database)
|
||||
else:
|
||||
print(f'<<< _____boombox_plugin >>> [ {index+1}/{len(self.database_names)} ] - [ located database: {self.database_names[index]} ]')
|
||||
#print(f'{"#"*80} SOF')
|
||||
#print(f' pre - a database name: {database}')
|
||||
#print(f' pre - database memory: \n{self.db}')
|
||||
#print(f' pre - a datbase entry: \n{db}')
|
||||
#print(f'post - database merged: \n{db}')
|
||||
#print(f'{"#"*80} EOF')
|
||||
for _ in self.database_names:
|
||||
self.bot.bbdb.append(self.bot.db.getlist(_))
|
||||
dims.checked=False
|
||||
############################################################ BOOMBOX CONFIG COLOR CODES
|
||||
def color(self,c):
|
||||
try:
|
||||
|
@ -1,6 +1,10 @@
|
||||
# -*- coding: utf-8 -*- ############################################################### SOF
|
||||
from irc3.plugins.command import command
|
||||
import irc3,ipdb
|
||||
from plugins.tool_dims_plugin import dims
|
||||
import irc3,asyncio,ipdb
|
||||
from plugins.tool_guds_plugin import guds
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
from plugins.tool_bus_plugin import BUS
|
||||
###########################################################################################
|
||||
@irc3.plugin
|
||||
class Plugin:
|
||||
@ -8,39 +12,32 @@ class Plugin:
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
#######################################################################################
|
||||
@irc3.extend
|
||||
@command(permission='view')
|
||||
def dr1pjack(self, mask, target, args):
|
||||
"""dr1pjack
|
||||
%%dr1pjack <message>...
|
||||
async def listrooms(self,sender_netroomchan,sender_user,target,arg):
|
||||
"""listrooms - lists rooms/channels/groups this bot is currently in
|
||||
%%listrooms
|
||||
"""
|
||||
message=' '.join(args['<message>'])
|
||||
ipdb.set_trace()
|
||||
try:
|
||||
bio=globals()['dug'].memories[2][0]
|
||||
bio.motapi
|
||||
bio.roomid
|
||||
msg=f'bio.motapi:{bio.motapi}->{bio.roomid}->rebouncing<-message'
|
||||
bio.motapi(bio.roomid,msg)
|
||||
except Exception as e:
|
||||
print(f'dr1p_plugin:error - {e}')
|
||||
results=[]
|
||||
result=dims.list_channels()
|
||||
for _ in result:
|
||||
if _.startswith('!'):
|
||||
room=f'matrix: {_}'
|
||||
elif _.startswith('#'):
|
||||
room=f'___irc: {_}'
|
||||
msg=f'<<< _____cmd_irc_plugin >>> [ ({sender_netroomchan})({sender_user})(listrooms)({arg})->({target}) ] - {room}'
|
||||
print(msg)
|
||||
results.append(room)
|
||||
return results
|
||||
###################################################################### NET IRC - MAIN [4/4]
|
||||
async def _d_cmd_irc(sender_netroomchan,sender_user,target,cmd,arg,) -> None:
|
||||
#######################################################################################
|
||||
@command(permission='view')
|
||||
def dr1p(self, mask, target, args):
|
||||
"""dr1p
|
||||
%%dr1p
|
||||
"""
|
||||
ipdb.set_trace()
|
||||
msg=''
|
||||
self.bot.privmsg(target, msg)
|
||||
#######################################################################################
|
||||
@command(permission='view')
|
||||
def list_rooms(self, mask, target, args):
|
||||
"""list_rooms
|
||||
%%list_rooms
|
||||
"""
|
||||
msg=f'{mask.nick}: [ list_rooms_plugin ] - api calling'
|
||||
self.bot.privmsg(target, self.bot.emo(msg))
|
||||
from plugins.net_matrix_plugin import joined_rooms as matrix_list_rooms
|
||||
result=matrix_list_rooms()
|
||||
result=(await eval(f"guds.memory('ircbot').{cmd}")(sender_netroomchan,sender_user,target,arg))
|
||||
#######################################################################################
|
||||
bridgedbus=(BUS(['#b0tsh0p','!OftXgmqAFOPEatmvLU:pcriot.org']))
|
||||
await bridgedbus.output([sender_netroomchan,sender_user],result)
|
||||
###########################################################################################
|
||||
def d_cmd_irc(sender_netroomchan,sender_user,target,cmd,arg,):
|
||||
self=guds.memory('ircbot')
|
||||
asyncio.run_coroutine_threadsafe(_d_cmd_irc(sender_netroomchan,sender_user,target,cmd,arg),self.loop)
|
||||
####################################################################################### EOF
|
52
plugins/net_discord_plugin.py
Normal file
52
plugins/net_discord_plugin.py
Normal file
@ -0,0 +1,52 @@
|
||||
#-*- coding: utf-8 -*- ############################################################### SOF
|
||||
import irc3,asyncio,os,re,ipdb
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord import Client
|
||||
from discord.ext import tasks
|
||||
from plugins.tool_dims_plugin import dims
|
||||
from plugins.tool_guds_plugin import guds
|
||||
from irc3.plugins.command import command
|
||||
from plugins.tool_bus_plugin import BUS as bus
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
###########################################################################################
|
||||
DISCORD__SCHAN=int(os.environ['DISCORD__SCHAN'])
|
||||
DISCORD__DCODE=int(os.environ['DISCORD__DCODE'])
|
||||
DISCORD__MAPLE=int(os.environ['DISCORD__MAPLE'])
|
||||
DISCORD__TOKEN=str(os.environ['DISCORD__TOKEN'])
|
||||
###########################################################################################
|
||||
global client
|
||||
##########################################################################################
|
||||
def start_discordbot(self):
|
||||
print(f'<<< _net_discord_plugin >>> [ discordbot started ]')
|
||||
self.discordbot=DISCORDBOT()
|
||||
asyncio.set_event_loop(self.loop)
|
||||
asyncio.run_coroutine_threadsafe(self.discordbot.client.start(DISCORD__TOKEN),self.loop)
|
||||
return self
|
||||
class DISCORDBOT:
|
||||
#######################################################################################
|
||||
intents=discord.Intents.default()
|
||||
intents.members = True
|
||||
client=discord.Client(intents=intents)
|
||||
def __init__(self):
|
||||
pass
|
||||
#######################################################################################
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print(f'<<< _net_discord_plugin >>> [ discordbot connection made as {globals()["DISCORDBOT"].client.user.name} ]')
|
||||
#######################################################################################
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
###################################################################################
|
||||
client=globals()['DISCORDBOT'].client
|
||||
if message.author.name == client.user.name:
|
||||
return
|
||||
msg=f'<<< _net_discord_plugin >>> [ (d)({message.channel.id})(#{message.channel.name}) ] > {str(message.author)}: {message.content}'
|
||||
print(msg)
|
||||
await message.channel.send(msg)
|
||||
###################################################################################
|
||||
async def send_dm(msg):
|
||||
client=globals()['DISCORDBOT'].client
|
||||
channel = client.get_channel(DISCORD__SCHAN)
|
||||
await channel.send(msg)
|
||||
####################################################################################### EOF
|
@ -1,11 +1,12 @@
|
||||
# -*- coding: utf-8 -*- ############################################################### SOF
|
||||
import irc3,os,ipdb
|
||||
import simplematrixbotlib as botlib
|
||||
from plugins.tool_dims_plugin import dims
|
||||
from plugins.tool_guds_plugin import guds
|
||||
import irc3,os,ipdb,asyncio
|
||||
from irc3.testing import ini2config
|
||||
from irc3.plugins.command import command
|
||||
from nio import AsyncClient, MatrixRoom, RoomMessageText
|
||||
from plugins.tool_dims_plugin import dims
|
||||
from plugins.tool_guds_plugin import guds
|
||||
from plugins.tool_bus_plugin import BUS
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
################################### NET IRC - SERVER CREDENTIALS FOR SASL OR NICKSERV [1/4]
|
||||
BOT_SASL_USERNAME=os.environ['BOT_SASL_USERNAME']
|
||||
BOT_SASL_PASSWORD=os.environ['BOT_SASL_PASSWORD']
|
||||
@ -40,6 +41,7 @@ def config_ircbot():
|
||||
plugins.sasl_custom_plugin
|
||||
plugins.net_irc_plugin
|
||||
plugins.net_matrix_plugin
|
||||
plugins.net_discord_plugin
|
||||
plugins.cmd_irc_plugin
|
||||
plugins.storage_plugin
|
||||
plugins.base_plugin
|
||||
@ -118,107 +120,121 @@ def config_ircbot():
|
||||
return ircbot
|
||||
############################################################### NET IRC - BOT STARTUP [3/4]
|
||||
def start_ircbot(self):
|
||||
globals()['guds'].memories.append([self,'net_irc_plugin:start_ircbot.self'])
|
||||
ircbot=guds.memories[2][0]._BOTIO__boot__ircbot=self.ircbot
|
||||
print(f'<<< _____net_irc_plugin >>> [ ircbot started ]')
|
||||
self.ircbot.loop=self.loop
|
||||
self.ircbot.run(forever=True)
|
||||
return self
|
||||
###################################################################### NET IRC - MAIN [4/4]
|
||||
async def _d_irc_msg(target,msg,) -> None:
|
||||
ircbot=guds.memory('ircbot')
|
||||
await ircbot.privmsg(
|
||||
target,
|
||||
msg,
|
||||
) #target="#tcpdirect",msg="test"
|
||||
###########################################################################################
|
||||
def d_irc_msg(target,msg,):
|
||||
self=guds.memory('ircbot')
|
||||
asyncio.run_coroutine_threadsafe(_d_irc_msg(target,msg),self.loop)
|
||||
###########################################################################################
|
||||
@irc3.plugin
|
||||
class Plugin:
|
||||
###########################################################################################
|
||||
def __init__(self,bot):
|
||||
self.ircbot=bot
|
||||
print(f'<<< _____net_irc_plugin >>> [ plugin loaded ]')
|
||||
guds.memories.append([self,'net_irc_plugin:__init__.self'])
|
||||
###########################################################################################
|
||||
def connection_made(self):
|
||||
print(f'<<< _____net_irc_plugin:event >>> [ connection made ]')
|
||||
###########################################################################################
|
||||
def server_ready(self):
|
||||
print(f'<<< _____net_irc_plugin:event >>> [ server ready ]')
|
||||
###########################################################################################
|
||||
def connection_lost(self):
|
||||
print(f'<<< _____net_irc_plugin:event >>> [ connection lost ]')
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.PRIVMSG)
|
||||
async def on_privmsg(self, mask=None, target=None, data=None, **kw):
|
||||
msg=f"{mask.nick}: target: {target} - event: privmsg - data: {data}"
|
||||
if not mask.nick==self.config['nick']: # user
|
||||
netschanlist=dims.list_channels()
|
||||
matrixbot=guds.memories[2][0]._BOTIO__boot__matrix
|
||||
oldbot=guds.memories[2][0]._BOTIO__boot__irc
|
||||
ircbot=self
|
||||
if oldbot==ircbot: # no variance, no problem
|
||||
bridgedbus=(BUS(netschanlist,matrixbot,ircbot))
|
||||
def __init__(self,bot):
|
||||
self.bot=bot
|
||||
print(f'<<< _____net_irc_plugin >>> [ plugin loaded ]')
|
||||
globals()['guds'].memories.append([self.bot,'net_irc_plugin:start_ircbot.self'])
|
||||
#######################################################################################
|
||||
def connection_made(self):
|
||||
print(f'<<< _____net_irc_plugin >>> [ event: ircbot connection made ]')
|
||||
#######################################################################################
|
||||
def server_ready(self):
|
||||
print(f'<<< _____net_irc_plugin >>> [ event: ircbot server ready ]')
|
||||
#######################################################################################
|
||||
def connection_lost(self):
|
||||
print(f'<<< _____net_irc_plugin >>> [ event: ircbot connection lost ]')
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.PRIVMSG)
|
||||
async def on_privmsg(self, mask=None, target=None, data=None, **kw):
|
||||
msg=f"<<< _____net_irc_plugin >>> [ (i)({self.bot.config['host']})({target}) ] > {mask.nick}: {data}"
|
||||
print(msg)
|
||||
if not mask.nick==self.bot.config['nick']: # user
|
||||
if mask.nick.startswith('maple[m]'): return
|
||||
netschanlist=dims.list_channels_bridged(target)
|
||||
bridgedbus=(BUS(netschanlist))
|
||||
await bridgedbus.input(target,f'{mask.nick}: {data}')
|
||||
else: # variance
|
||||
pass # exposing variance, <research>
|
||||
else: # bot
|
||||
pass
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.JOIN_PART_QUIT)
|
||||
def on_join_part_quit(self,mask=None,target=None,data=None,**kw):
|
||||
target=kw['channel']
|
||||
###################################################################################
|
||||
if not mask.nick==self.config['nick']: # this section is the user
|
||||
msg=f"{mask.nick}: target: {target} - event: join_part_quit:{kw['event']} - data: {data}"
|
||||
self.privmsg(target,msg); print(msg)
|
||||
###################################################################################
|
||||
else: # this section is the bot
|
||||
###############################################################################
|
||||
if kw['event']=='JOIN':
|
||||
result,i,ii=dims.ischannel(target)
|
||||
if not result:
|
||||
dims.__create__('irc',target)
|
||||
print(f"<<< ___tool_dims_plugin:event:join >>> [ dims.__create__(irc,{target}) ] - active channel record created")
|
||||
###############################################################################
|
||||
elif kw['event']=='PART':
|
||||
###########################################################################
|
||||
result,i,ii=dims.ischannel(target)
|
||||
###########################################################################
|
||||
dims.__delete__('irc',i)
|
||||
print(f"<<< ___tool_dims_plugin:event:part >>> [ dims.__delete__(irc,{target}) ] - active channel record deleted")
|
||||
###############################################################################
|
||||
elif kw['event']=='QUIT':
|
||||
###########################################################################
|
||||
result,i,ii=dims.ischannel(target)
|
||||
###########################################################################
|
||||
dims.__delete__('irc',i)
|
||||
print(f"<<< ___tool_dims_plugin:event:quit >>> [ dims.__delete__(irc,{target}) ] - active channel record deleted")
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.TOPIC)
|
||||
def on_topic(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: topic - data: {data}"
|
||||
self.privmsg(target,msg); print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.INVITE)
|
||||
def on_invite(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: invite - data: {data}"
|
||||
self.privmsg(target,msg); print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.KICK)
|
||||
def on_kick(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: kick - data: {data}"
|
||||
self.privmsg(target,msg); print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.MODE)
|
||||
def on_mode(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: mode - data: {data}"
|
||||
self.privmsg(target,msg); print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.NEW_NICK)
|
||||
def on_new_kick(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: new_nick - data: {data}"
|
||||
self.privmsg(target,msg); print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
###########################################################################################
|
||||
@irc3.event(irc3.rfc.CTCP)
|
||||
def on_ctcp(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: ctcp - data: {data}"
|
||||
self.privmsg(target,msg); print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
####################################################################################### EOF
|
||||
else: # bot
|
||||
pass
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.JOIN_PART_QUIT)
|
||||
def on_join_part_quit(self,mask=None,target=None,data=None,**kw):
|
||||
target=kw['channel']
|
||||
###################################################################################
|
||||
if not mask.nick==self.bot.config['nick']: # this section is the user
|
||||
msg=f'<<< _____net_irc_plugin >>> [ event: join_part_quit ] - nick: {mask.nick} - target: {target} - event: {kw["event"]} - data: {data}'
|
||||
print(msg)
|
||||
###################################################################################
|
||||
else: # this section is the bot
|
||||
###############################################################################
|
||||
if kw['event']=='JOIN':
|
||||
result,i,ii=dims.ischannel(target)
|
||||
guds.mask=mask
|
||||
if not result:
|
||||
msg=f'<<< _____net_irc_plugin >>> [ event: join_part_quit ] - nick: {mask.nick} - target: {target} - event: {kw["event"]} - data: {data}'
|
||||
print(msg)
|
||||
dims.__create__('irc',target)
|
||||
print(f"<<< ___tool_dims_plugin >>> [ event: join ] - dims.__create__(irc,{target}) - active channel record created")
|
||||
###############################################################################
|
||||
elif kw['event']=='PART':
|
||||
###########################################################################
|
||||
result,i,ii=dims.ischannel(target)
|
||||
###########################################################################
|
||||
msg=f'<<< _____net_irc_plugin >>> [ event: join_part_quit ] - nick: {mask.nick} - target: {target} - event: {kw["event"]} - data: {data}'
|
||||
print(msg)
|
||||
dims.__delete__('irc',i)
|
||||
print(f"<<< ___tool_dims_plugin >>> [ event: part ] - dims.__delete__(irc,{target}) - active channel record deleted")
|
||||
###############################################################################
|
||||
elif kw['event']=='QUIT':
|
||||
###########################################################################
|
||||
result,i,ii=dims.ischannel(target)
|
||||
###########################################################################
|
||||
msg=f'<<< _____net_irc_plugin >>> [ event: join_part_quit ] - nick: {mask.nick} - target: {target} - event: {kw["event"]} - data: {data}'
|
||||
print(msg)
|
||||
dims.__delete__('irc',i)
|
||||
print(f"<<< ___tool_dims_plugin >>> [ event: quit ] - dims.__delete__(irc,{target}) - active channel record deleted")
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.TOPIC)
|
||||
def on_topic(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.bot.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: topic - data: {data}"
|
||||
print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.INVITE)
|
||||
def on_invite(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.bot.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: invite - data: {data}"
|
||||
print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.KICK)
|
||||
def on_kick(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.bot.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: kick - data: {data}"
|
||||
print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.MODE)
|
||||
def on_mode(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.bot.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: mode - data: {data}"
|
||||
print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.NEW_NICK)
|
||||
def on_new_kick(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.bot.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: new_nick - data: {data}"
|
||||
print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
#######################################################################################
|
||||
@irc3.event(irc3.rfc.CTCP)
|
||||
def on_ctcp(self,mask=None,target=None,data=None,**kw):
|
||||
if not mask.nick==self.bot.config['nick']:
|
||||
msg=f"{mask.nick}: target: {target} - event: ctcp - data: {data}"
|
||||
print("<<< _____net_irc_plugin >>> [ "+msg+" ]")
|
||||
####################################################################################### EOF
|
@ -1,67 +1,86 @@
|
||||
# -*- coding: utf-8 -*- ############################################################### SOF
|
||||
import irc3,os,re,ipdb
|
||||
import simplematrixbotlib as botlib
|
||||
import irc3,asyncio,os,re,ipdb
|
||||
from nio import AsyncClient, MatrixRoom, RoomMessageText
|
||||
from plugins.tool_dims_plugin import dims
|
||||
from plugins.tool_guds_plugin import guds
|
||||
from irc3.plugins.command import command
|
||||
from plugins.tool_bus_plugin import BUS as bus
|
||||
from plugins.tool_bus_plugin import BUS
|
||||
from datetime import datetime
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
###########################################################################################
|
||||
MATRIX_HOMESERVER=os.environ['MATRIX_HOMESERVER']
|
||||
MATRIX___USERNAME=os.environ['MATRIX___USERNAME']
|
||||
MATRIX___PASSWORD=os.environ['MATRIX___PASSWORD']
|
||||
###########################################################################################
|
||||
matrix_bot_credentials=[]
|
||||
###########################################################################################
|
||||
creds=botlib.Creds(MATRIX_HOMESERVER,MATRIX___USERNAME,MATRIX___PASSWORD)
|
||||
matrixbot=botlib.Bot(creds)
|
||||
def add_credentials(credential):
|
||||
matrix_bot_credentials.append(credential)
|
||||
print(f'<<< __net_matrix_plugin >>> [ add_credentials ] - added {credential} credentials to net_matrix_plugin.matrix_bot_credentials')
|
||||
###########################################################################################
|
||||
def check_credentials(self,against_credential):
|
||||
flag_match=False
|
||||
for credential in matrix_bot_credentials:
|
||||
if not credential.find(against_credential):
|
||||
flag_match=True
|
||||
print(f'<<< __net_matrix_plugin >>> [ check_credentials ] - found {credential} against {against_credential}')
|
||||
#######################################################################################
|
||||
if not flag_match:
|
||||
print(f'<<< __net_matrix_plugin >>> [ check_credentials ] - no credentials found matching {against_credential}')
|
||||
#######################################################################################
|
||||
return flag_match
|
||||
###########################################################################################
|
||||
def start_matrixbot(self):
|
||||
globals()['guds'].memories.append([self,'net_matrix_plugin:start_matrixbot.self'])
|
||||
ircbot=guds.memories[2][0]._BOTIO__boot__ircbot=self.ircbot
|
||||
guds.memories[2][0]._BOTIO__boot__irc=ircbot
|
||||
guds.memories[2][0]._BOTIO__boot__matrix=matrixbot
|
||||
matrixbot.run()
|
||||
print(f'<<< __net_matrix_plugin >>> [ matrixbot started ]')
|
||||
add_credentials("@maple.or.g1mp:matrix.org")
|
||||
add_credentials("@maple:pcriot.org")
|
||||
self.matrixbot=MATRIXBOT()
|
||||
self.matrixbot.loop=self.loop
|
||||
asyncio.set_event_loop(self.loop)
|
||||
asyncio.run_coroutine_threadsafe(self.matrixbot.main(),self.loop)
|
||||
self.matrixbot.client=AsyncClient(MATRIX_HOMESERVER, MATRIX___USERNAME)
|
||||
return self
|
||||
###########################################################################################
|
||||
@irc3.plugin
|
||||
class Plugin:
|
||||
#######################################################################################
|
||||
def __init__(self,bot):
|
||||
self.bot=bot
|
||||
async def _d_matrix_msg(target,msg,) -> None:
|
||||
matrixbot=guds.memory('matrixbot')
|
||||
await matrixbot.client.room_send(
|
||||
room_id=target,
|
||||
message_type="m.room.message",
|
||||
content={"msgtype":"m.text","body":msg},
|
||||
)
|
||||
###########################################################################################
|
||||
def d_matrix_msg(target,msg,):
|
||||
matrixbot=guds.memory('matrixbot')
|
||||
asyncio.run_coroutine_threadsafe(_d_matrix_msg(target,msg),matrixbot.loop)
|
||||
###########################################################################################
|
||||
class MATRIXBOT:
|
||||
def __init__(self):
|
||||
print(f'<<< __net_matrix_plugin >>> [ plugin loaded ]')
|
||||
globals()['guds'].memories.append([self,'net_matrix_plugin:__init__.self'])
|
||||
@matrixbot.listener.on_message_event
|
||||
async def scan(room,message):
|
||||
bridgedbus=''
|
||||
print('<<< __net_matrix_plugin >>> [ event: listener ]')
|
||||
bio=guds.memories[2][0]
|
||||
dims.__create__('matrix',room)
|
||||
m_message=message.source['content']['body']
|
||||
m_sender=message.sender
|
||||
print(f"{m_sender}: {m_message}")
|
||||
############################################################# MESSAGE SENDER FILTER
|
||||
trigger_command="??"
|
||||
if not guds.check_credentials(message.sender):
|
||||
####################################################################### TRIGGER
|
||||
if m_message.lower().startswith(trigger_command):
|
||||
commands=['d_breakpoint','d_listrooms']
|
||||
################################################################## COMMANDS
|
||||
if m_message.lower().split()[0][len(trigger_command):] in commands:
|
||||
command=m_message.lower().split()[0][len(trigger_command):]
|
||||
#######################################################################
|
||||
if command==commands[0]: # ??d_breakpoint - triggered message
|
||||
if m_sender=="@d:tcp.direct":
|
||||
ipdb.set_trace()
|
||||
#######################################################################
|
||||
if command==commands[1]: # ??d_listrooms - triggered message
|
||||
if m_sender=="@d:tcp.direct":
|
||||
await joined_rooms(room.room_id)
|
||||
#######################################################################
|
||||
else:
|
||||
pass
|
||||
msg=f'{m_sender}: {m_message} - triggered message but with a non-listed command'
|
||||
print(msg)
|
||||
###########################################################################
|
||||
else:
|
||||
msg=f'{m_sender}: {m_message} - message not prefixed with a {trigger_command} trigger'
|
||||
globals()['guds'].memories.append([self,'net_matrix_plugin:start_matrixbot.self'])
|
||||
#######################################################################################
|
||||
async def message_callback(self,room: MatrixRoom, event: RoomMessageText) -> None:
|
||||
if guds.timestamp_check('matrix_boot')==False:
|
||||
return
|
||||
print(f"<<< __net_matrix_plugin >>> [ (m)({room.room_id})({room.display_name}) ] > {room.user_name(event.sender)}: {event.body}")
|
||||
if event.sender==self.client.user_id or event.sender=="@ircd_maple:tcp.direct":
|
||||
return # ignore messages from self, e.g. @maple:pcriot.org
|
||||
if event.body.startswith("?"):
|
||||
from plugins.cmd_irc_plugin import d_cmd_irc
|
||||
d_cmd_irc(room.room_id,event.sender,'!OftXgmqAFOPEatmvLU:pcriot.org','listrooms','')
|
||||
#######################################################################################
|
||||
async def main(self,) -> None:
|
||||
self.client.add_event_callback(self.message_callback,RoomMessageText)
|
||||
await self.client.login(MATRIX___PASSWORD)
|
||||
guds.timestamp_alarm('matrix_boot',15)
|
||||
joined_rooms=(await self.client.joined_rooms())
|
||||
for _room in joined_rooms.rooms:
|
||||
result,i,ii=dims.isroom(_room)
|
||||
if not result:
|
||||
msg=f'<<< __net_matrix_plugin >>> [ event: join ] - user_id: {self.client.user_id} - target: {_room}'
|
||||
print(msg)
|
||||
dims.__create__('matrix',_room)
|
||||
print(f"<<< ___tool_dims_plugin >>> [ event: join ] - dims.__create__(matrix,{_room}) - active room record created")
|
||||
###################################################################################
|
||||
print(f'<<< __net_matrix_plugin >>> [ await client.sync_forever(timeout=5000) ]')
|
||||
await self.client.sync_forever(timeout=5000) # milliseconds
|
||||
####################################################################################### EOF
|
33
plugins/net_telegram_plugin.py
Normal file
33
plugins/net_telegram_plugin.py
Normal file
@ -0,0 +1,33 @@
|
||||
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
||||
import telegram
|
||||
import ipdb
|
||||
from telegram import ChatAction, ParseMode
|
||||
from functools import wraps
|
||||
import configparser
|
||||
import logging
|
||||
import random
|
||||
import re,os
|
||||
TELEGRAM_TOKEN=os.environ['TELEGRAM_TOKEN']
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
def start(update, context):
|
||||
update.message.reply_text('Hi!')
|
||||
def help(update, context):
|
||||
update.message.reply_text('Help!')
|
||||
def echo(update, context):
|
||||
GROUP=telegram.Bot.get_chat(update.message.bot,update.message.chat_id.real)
|
||||
print(f'[net:telegram|group:{GROUP.title}] - {update.message.from_user.username}: {update.message.text}')
|
||||
update.message.reply_text(update.message.text)
|
||||
def error(update, context):
|
||||
logger.warning('Update "%s" caused error "%s"', update, context.error)
|
||||
def main():
|
||||
updater = Updater(TELEGRAM_TOKEN, use_context=True)
|
||||
dp = updater.dispatcher
|
||||
dp.add_handler(CommandHandler("start", start))
|
||||
dp.add_handler(CommandHandler("help", help))
|
||||
dp.add_handler(MessageHandler(Filters.text, echo))
|
||||
dp.add_error_handler(error)
|
||||
updater.start_polling()
|
||||
updater.idle()
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*- ########################################################## SOF
|
||||
import irc3,os,base64
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
######################################################################################
|
||||
BOT_SASL_USERNAME=os.environ['BOT_SASL_USERNAME']
|
||||
BOT_SASL_PASSWORD=os.environ['BOT_SASL_PASSWORD']
|
||||
|
@ -1,39 +1,119 @@
|
||||
# -*- coding: utf-8 -*- ############################################################### SOF
|
||||
global bus, dims, matrixbot, ircbot
|
||||
from async_timeout import timeout
|
||||
from plugins.tool_dims_plugin import dims
|
||||
from plugins.tool_guds_plugin import guds
|
||||
import asyncio, ipdb
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
import ipdb
|
||||
###########################################################################################
|
||||
class BUS:
|
||||
#######################################################################################
|
||||
results=[]
|
||||
#######################################################################################
|
||||
def __init__(self,bridged_network_roomchans,matrixbot=None,ircbot=None):
|
||||
def __init__(self,bridged_network_roomchans=[]):
|
||||
self.bridged_network_roomchans=bridged_network_roomchans
|
||||
print(f'<<< ____tool_bus_plugin:BUS.__init__ >>> [ BUS.bridged_network_roomchans={self.bridged_network_roomchans} ]')
|
||||
self.list_of_tasks=[]
|
||||
self.matrixbot=matrixbot
|
||||
print(f'<<< ____tool_bus_plugin:BUS.__init__ >>> [ BUS.matrixbot={self.matrixbot} ]')
|
||||
self.ircbot=ircbot
|
||||
print(f'<<< ____tool_bus_plugin:BUS.__init__ >>> [ BUS.ircbot={self.ircbot} ]')
|
||||
self.matrixbot=guds.memory('matrixbot')
|
||||
self.ircbot=guds.memory('ircbot')
|
||||
print(f'<<< ____tool_bus_plugin >>> [ BUS.__init__ ] - BUS.bridged_network_roomchans={self.bridged_network_roomchans}')
|
||||
print(f'<<< ____tool_bus_plugin >>> [ BUS.__init__ ] - BUS.matrixbot={self.matrixbot}')
|
||||
print(f'<<< ____tool_bus_plugin >>> [ BUS.__init__ ] - BUS.ircbot={self.ircbot}')
|
||||
#######################################################################################
|
||||
async def input(self,network_chanroom_src,data):
|
||||
def sortnet(self,s):
|
||||
if s.startswith('!'):
|
||||
return '(m)'
|
||||
elif s.startswith('#'):
|
||||
return '(i)'
|
||||
#######################################################################################
|
||||
async def output(self,netschanroom_src,data):
|
||||
from plugins.net_irc_plugin import d_irc_msg
|
||||
from plugins.net_matrix_plugin import d_matrix_msg
|
||||
###################################################################################
|
||||
chanroom=netschanroom_src[0]; usernick=netschanroom_src[1]
|
||||
if type(self.bridged_network_roomchans)==list:
|
||||
targets=self.bridged_network_roomchans
|
||||
for target in targets:
|
||||
if type(data)==list:
|
||||
if target.startswith('!'):
|
||||
for _data in data:
|
||||
d_matrix_msg(target,_data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {_data}'
|
||||
elif target.startswith('#'):
|
||||
for _data in data:
|
||||
d_irc_msg(target,_data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {_data}'
|
||||
###########################################################################
|
||||
else:
|
||||
if target.startswith('!'):
|
||||
d_matrix_msg(target,data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {data}'
|
||||
elif target.startswith('#'):
|
||||
d_irc_msg(target,data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {data}'
|
||||
print(msg)
|
||||
else:
|
||||
target=self.bridged_network_roomchans
|
||||
if type(data)==list:
|
||||
if target.startswith('!'):
|
||||
for _data in data:
|
||||
d_matrix_msg(target,_data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {_data}'
|
||||
elif target.startswith('#'):
|
||||
for msg in data:
|
||||
d_irc_msg(target,_data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {_data}'
|
||||
###############################################################################
|
||||
else:
|
||||
if target.startswith('!'):
|
||||
d_matrix_msg(target,data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {data}'
|
||||
elif target.startswith('#'):
|
||||
d_irc_msg(target,data)
|
||||
msg=f'<<< ____tool_bus_plugin >>> [ BUS.output ] - {self.sortnet(chanroom)}({chanroom})({usernick})->{self.sortnet(target)}({target}) > {data}'
|
||||
print(msg)
|
||||
#######################################################################################
|
||||
async def input(self,network_chanroom_user_src,data):
|
||||
prefix_src=""
|
||||
if network_chanroom_user_src.startswith('!'): prefix_src="m"
|
||||
elif network_chanroom_user_src.startswith('#'): prefix_src="i"
|
||||
if prefix_src=="": return
|
||||
for network_chanroom_dest in self.bridged_network_roomchans:
|
||||
if not str(network_chanroom_src)==network_chanroom_dest:
|
||||
#################################################################### MATRIX
|
||||
if network_chanroom_dest.startswith('!'):
|
||||
#######################################################################
|
||||
msg=(f"m{str(network_chanroom_src)}> ")
|
||||
print('here is the error. press n to step the next line')
|
||||
ipdb.set_trace()
|
||||
task=(await self.matrixbot.api.send_text_message(
|
||||
network_chanroom_dest,str(f'{msg}{data}')))
|
||||
loop=self.ircbot.loop
|
||||
asyncio.ensure_future(task,loop=loop)
|
||||
####################################################################### IRC
|
||||
elif network_chanroom_dest.startswith('#'):
|
||||
msg=(f"i{str(network_chanroom_src)}> ")
|
||||
await self.ircbot.privmsg(
|
||||
network_chanroom_dest,str(f'{msg}{data}'))
|
||||
####################################################################################### EOF
|
||||
if not str(network_chanroom_user_src)==str(network_chanroom_dest) or len(self.bridged_network_roomchans)==1:
|
||||
from plugins.net_irc_plugin import d_irc_msg
|
||||
from plugins.net_matrix_plugin import d_matrix_msg
|
||||
#################################################################### ROUTER
|
||||
brindicator=data[0]
|
||||
user_src=f'({data[1]})'
|
||||
data=data[2]
|
||||
if type(data)==list:
|
||||
for _data in data:
|
||||
############################################################ MATRIX
|
||||
if network_chanroom_dest.startswith('!'):
|
||||
if brindicator:
|
||||
msg=f'({prefix_src})({network_chanroom_user_src}){user_src} > {_data}'
|
||||
else:
|
||||
msg=f'{_data}'
|
||||
d_matrix_msg(network_chanroom_dest,msg)
|
||||
############################################################### IRC
|
||||
elif network_chanroom_dest.startswith('#'):
|
||||
if brindicator:
|
||||
msg=f'({prefix_src})({network_chanroom_user_src}){user_src} > {_data}'
|
||||
else:
|
||||
msg=f'{_data}'
|
||||
d_irc_msg(network_chanroom_dest,msg)
|
||||
############################################################# LOCAL
|
||||
else:
|
||||
################################################################ MATRIX
|
||||
if network_chanroom_dest.startswith('!'):
|
||||
if brindicator:
|
||||
msg=f'({prefix_src})({network_chanroom_user_src}){user_src} > {data}'
|
||||
else:
|
||||
msg=f'{data}'
|
||||
d_matrix_msg(network_chanroom_dest,msg)
|
||||
################################################################### IRC
|
||||
elif network_chanroom_dest.startswith('#'):
|
||||
if brindicator:
|
||||
msg=f'({prefix_src})({network_chanroom_user_src}){user_src} > {data}'
|
||||
else:
|
||||
msg=f'{data}'
|
||||
d_irc_msg(network_chanroom_dest,msg)
|
||||
################################################################# LOCAL
|
||||
####################################################################################### EOF
|
59
plugins/tool_colors_plugin.py
Normal file
59
plugins/tool_colors_plugin.py
Normal file
@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*- ############################################################### SOF
|
||||
###########################################################################################
|
||||
def rgb(r=0,g=0,b=0):return f"\033[38;2;{r};{g};{b}m"
|
||||
###########################################################################################
|
||||
def rgbe():return f"\033[38;2;255;255;255m"
|
||||
###########################################################################################
|
||||
def rgbt(t='',r=0,g=0,b=0):return f"\033[38;2;{r};{g};{b}m{t}\033[38;2;255;255;255m"
|
||||
###########################################################################################
|
||||
###########################################################################################
|
||||
def colorform(s):
|
||||
#######################################################################################
|
||||
try:
|
||||
between_gtlts=s.split(' >>> ')[0].split('<<< ')[1]
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
between_brackets=s.split(' >>> [ ')[1].split(' ]')[0]
|
||||
if s[:-2].endswith(between_brackets):
|
||||
FLAG_A=False
|
||||
else:
|
||||
FLAG_A=True
|
||||
except:
|
||||
FLAG_A=True
|
||||
try:
|
||||
if FLAG_A:
|
||||
everything_past_brackets=s.split(' >>> [ ')[1].split(' ] ')[1]
|
||||
except:
|
||||
pass
|
||||
#######################################################################################
|
||||
s=f"{rgb(b=255)}<<<{rgb(g=255,b=255)} {between_gtlts} {rgb(b=255)}>>> {rgb(r=255)}"
|
||||
if between_brackets.startswith('('):
|
||||
s+=f"[{rgb(b=255)} {between_brackets} {rgb(r=255)}]"
|
||||
else:
|
||||
s+=f"[{rgb(r=255,g=255)} {between_brackets} {rgb(r=255)}]"
|
||||
#######################################################################################
|
||||
maybe_delimited=""
|
||||
try:
|
||||
if maybe_delimited=="":
|
||||
if FLAG_A:
|
||||
if everything_past_brackets.startswith('-'):
|
||||
maybe_delimited=f" {rgb(b=255)}- "
|
||||
everything_past_brackets=everything_past_brackets[2:].replace(' - ',f' {rgb(b=255)}- {rgb(r=255,b=255)}')
|
||||
elif everything_past_brackets.startswith('>'):
|
||||
maybe_delimited=f" {rgb(b=255)}> "
|
||||
everything_past_brackets=everything_past_brackets[2:].replace(":",f"{rgb(b=255)}:{rgb(g=255)}",1)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if len(everything_past_brackets)>0:
|
||||
s+=f"{maybe_delimited}{rgb(r=255,b=255)}{everything_past_brackets}"
|
||||
print(s)
|
||||
return
|
||||
else:
|
||||
print(s)
|
||||
return
|
||||
except:
|
||||
print(s)
|
||||
return
|
||||
####################################################################################### EOFs
|
@ -7,9 +7,9 @@
|
||||
# flows: d.irc[n].channels[n].bridge.[irc,matrix]_[channels,rooms]_[inbound,outbound]
|
||||
# flows: d.matrix[n].rooms[n] [lots of attributes pertaining to rooms on the index ]
|
||||
# flows: d.matrix[n].rooms[n].bridge.[irc,matrix]_[channels,rooms]_[inbound,outbound]
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
from plugins.tool_guds_plugin import guds
|
||||
global dims
|
||||
global guds
|
||||
import ipdb
|
||||
###########################################################################################
|
||||
class DIMS:
|
||||
#######################################################################################
|
||||
@ -21,14 +21,18 @@ class DIMS:
|
||||
###########################################################################
|
||||
def __init__(self,room):
|
||||
self.matrix_rooms_outbound=[]
|
||||
self.matrix_rooms_inbound=[]
|
||||
#self.matrix_rooms_inbound=[]
|
||||
self.irc_channels_outbound=[]
|
||||
self.irc_channels_inbound=[]
|
||||
#self.irc_channels_inbound=[]
|
||||
###############################################################################
|
||||
def __init__(self,room):
|
||||
room_flag=False
|
||||
if len(dir(room))>1:
|
||||
room_flag=True
|
||||
try:
|
||||
if room.startswith('!'):
|
||||
pass
|
||||
except:
|
||||
room_flag=True
|
||||
for _ in ['canonical_alias','creator','display_name','encrypted',
|
||||
'federate','fully_read_marker','gen_avatar_url','history_visibility',
|
||||
'invited_count','invited_users','is_group','is_named','join_rule',
|
||||
@ -38,7 +42,7 @@ class DIMS:
|
||||
'typing_users','unread_highlights','unread_notifications','users']:
|
||||
if room_flag:
|
||||
exec(f'self.{_}=room.{_}')
|
||||
print(f"room.{_}->{eval(f'self.{_}')}")
|
||||
# print(f"room.{_}->{eval(f'self.{_}')}")
|
||||
self.bridge=self.__INIT_BRIDGE_MATRIX__(room.room_id)
|
||||
else:
|
||||
exec(f'self.{_}=""')
|
||||
@ -63,7 +67,7 @@ class DIMS:
|
||||
exec(f"self.matrix[{index}].rooms[0].{_}=room.{_}")
|
||||
cmdf=f"room.{_}"
|
||||
cmdt=f"self.matrix[{index}].rooms[0].{_}"
|
||||
print(f"literal: room.{_}->self.matrix[{index}].rooms[0].{_} - explicit: {eval(cmdf)}->{eval(cmdt)}")
|
||||
# print(f"literal: room.{_}->self.matrix[{index}].rooms[0].{_} - explicit: {eval(cmdf)}->{eval(cmdt)}")
|
||||
#######################################################################################
|
||||
def isroom(self,room):
|
||||
###################################################################################
|
||||
@ -76,7 +80,7 @@ class DIMS:
|
||||
except: pass
|
||||
###################################################################################
|
||||
return False,0,0
|
||||
#######################################################################################
|
||||
#######################################################################################
|
||||
class __INIT_IRC__:
|
||||
###################################################################################
|
||||
class __INIT_CHANNEL__:
|
||||
@ -85,9 +89,9 @@ class DIMS:
|
||||
###########################################################################
|
||||
def __init__(self,channel):
|
||||
self.irc_channels_outbound=[]
|
||||
self.irc_channels_inbound=[]
|
||||
#self.irc_channels_inbound=[]
|
||||
self.matrix_rooms_outbound=[]
|
||||
self.matrix_rooms_inbound=[]
|
||||
#self.matrix_rooms_inbound=[]
|
||||
###############################################################################
|
||||
def __init__(self,channel):
|
||||
self.channel=channel
|
||||
@ -112,7 +116,7 @@ class DIMS:
|
||||
###################################################################################
|
||||
return False,0,0
|
||||
#######################################################################################
|
||||
matrix=[]; irc=[]; netschanroom=[]
|
||||
matrix=[]; irc=[]; netschanroom=[]; netschanroom_bridged=[];
|
||||
#######################################################################################
|
||||
def __init__(self,net="",chanroom=""):
|
||||
###################################################################################
|
||||
@ -124,26 +128,28 @@ class DIMS:
|
||||
if net=='matrix':
|
||||
for i in range(len(self.matrix)):
|
||||
if self.matrix[i].rooms[0].room_id==chanroom.room_id:
|
||||
print(f'<<< ________dims_plugin >>> [ updating pre-existing matrix room data ]')
|
||||
# print(f'<<< ________dims_plugin >>> [ updating pre-existing matrix room data ]')
|
||||
dupe_flag=True; index=i; self.__update_matrix__(index,chanroom)
|
||||
if not dupe_flag:
|
||||
print(f'<<< ________dims_plugin >>> [ new matrix room data entry ]')
|
||||
# print(f'<<< ________dims_plugin >>> [ new matrix room data entry ]')
|
||||
self.matrix.append(self.__INIT_MATRIX__(chanroom))
|
||||
###################################################################################
|
||||
elif net=='irc':
|
||||
for i in range(len(self.irc)):
|
||||
if self.irc[i].channels[0].channel==chanroom:
|
||||
print(f'<<< ________dims_plugin >>> [ updating pre-existing irc channel data ]')
|
||||
# print(f'<<< ________dims_plugin >>> [ updating pre-existing irc channel data ]')
|
||||
dupe_flag=True; index=i; self.__update_irc__(index,chanroom)
|
||||
if not dupe_flag:
|
||||
print(f'<<< ________dims_plugin >>> [ new irc channel data entry ]')
|
||||
# print(f'<<< ________dims_plugin >>> [ new irc channel data entry ]')
|
||||
self.irc.append(self.__INIT_IRC__(chanroom))
|
||||
#######################################################################################
|
||||
def __create__(self,net="",chanroom=""):
|
||||
###################################################################################
|
||||
if net=='matrix': self.matrix.append(self.__INIT_MATRIX__(chanroom))
|
||||
if net=='matrix':
|
||||
self.matrix.append(self.__INIT_MATRIX__(chanroom))
|
||||
###################################################################################
|
||||
elif net=='irc': self.irc.append(self.__INIT_IRC__(chanroom))
|
||||
elif net=='irc':
|
||||
self.irc.append(self.__INIT_IRC__(chanroom))
|
||||
#######################################################################################
|
||||
def __delete__(self,net="",chanroom_index=-1):
|
||||
###################################################################################
|
||||
@ -151,21 +157,36 @@ class DIMS:
|
||||
###################################################################################
|
||||
elif net=='irc': self.irc.remove(self.irc[chanroom_index])
|
||||
#######################################################################################
|
||||
def list_channels(self):
|
||||
###################################################################################
|
||||
from plugins.tool_guds_plugin import guds
|
||||
matrixbot=guds.memories[2][0]._BOTIO__boot__matrix
|
||||
localchannels=[]
|
||||
def add_channel_bridge(self):
|
||||
self.irc[0].channels[0].bridge.irc_channels_outbound.append('#b0tsh0p')
|
||||
for i1,_irc in enumerate(self.irc):
|
||||
for i2,_channels in enumerate(_irc.channels):
|
||||
print(f'self.irc[{i1}].channels[{i2}].channel - {_channels.channel}')
|
||||
#######################################################################################
|
||||
def list_channels_bridged(self,chanroom):
|
||||
self.netschanroom_bridged=[]
|
||||
for _irc in self.irc:
|
||||
for _channels in _irc.channels:
|
||||
localchannels.append(_channels.channel)
|
||||
[ self.netschanroom.append(x) for x in matrixbot.async_client.rooms ]
|
||||
if _channels.channel==chanroom:
|
||||
if _channels.bridge.irc_channels_outbound: self.netschanroom_bridged.append(_channels.bridge.irc_channels_outbound[0])
|
||||
if _channels.bridge.matrix_rooms_outbound: self.netschanroom_bridged.append(_channels.bridge.matrix_rooms_outbound[0])
|
||||
for _matrix in self.matrix:
|
||||
for _rooms in _matrix.rooms:
|
||||
if _rooms.room_id==chanroom:
|
||||
if _rooms.bridge.irc_channels_outbound: self.netschanroom_bridged.append(_rooms.bridge.irc_channels_outbound[0])
|
||||
if _rooms.bridge.matrix_rooms_outbound: self.netschanroom_bridged.append(_rooms.bridge.matrix_rooms_outbound[0])
|
||||
return self.netschanroom_bridged
|
||||
#######################################################################################
|
||||
def list_channels(self):
|
||||
###################################################################################
|
||||
matrixbot=guds.memory('matrixbot')
|
||||
self.netschanroom=[]
|
||||
[ self.netschanroom.append(x) for x in matrixbot.client.rooms ]
|
||||
for _irc in self.irc:
|
||||
for _channels in _irc.channels:
|
||||
self.netschanroom.append(_channels.channel)
|
||||
###################################################################################
|
||||
return self.netschanroom
|
||||
###################################################################################
|
||||
###########################################################################################
|
||||
dims=DIMS()
|
||||
####################################################################################### EOF
|
@ -1,29 +1,58 @@
|
||||
# -*- coding: utf-8 -*- ############################################################### SOF
|
||||
import ipdb
|
||||
global dims
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
import timeago
|
||||
from plugins.tool_colors_plugin import colorform as print
|
||||
global guds # global unified data system 2 move instantiated data between processes/threads
|
||||
###########################################################################################
|
||||
class GUDS:
|
||||
#######################################################################################
|
||||
push_index=0; credentials=[]; memories=[];
|
||||
push_index=0; memories=[]; timestamped_alarm=[];
|
||||
#######################################################################################
|
||||
def __init__(self):
|
||||
pass
|
||||
#######################################################################################
|
||||
def add_credentials(self,credential):
|
||||
self.credentials.append(credential)
|
||||
print(f'<<< ________guds_plugin >>> [ added {credential} credentials to guds.credentials ]')
|
||||
def timestamp_alarm(self,reason,seconds):
|
||||
try:
|
||||
iseconds=int(seconds)
|
||||
timestamp=datetime.now().timestamp()
|
||||
timestamp+=iseconds
|
||||
self.timestamped_alarm.append([reason,False,timestamp])
|
||||
print(f'<<< ________guds_plugin >>> [ timestamp_alarm ] - active: {reason} - alarm: {timestamp} - now: {datetime.now().timestamp()}')
|
||||
except:
|
||||
print('<<< ________guds_plugin >>> [ timestamp_alarm ] - error')
|
||||
#######################################################################################
|
||||
def check_credentials(self,against_credential):
|
||||
flag_match=False
|
||||
for credential in self.credentials:
|
||||
if not credential.find(against_credential):
|
||||
flag_match=True
|
||||
print(f'<<< ________guds_plugin >>> [ found {credential} against {against_credential} ]')
|
||||
###################################################################################
|
||||
if not flag_match:
|
||||
print(f'<<< ________guds_plugin >>> [ no credentials found matching {against_credential} ]')
|
||||
return False
|
||||
def timestamp_check(self,reason):
|
||||
try:
|
||||
REASON_FLAG=True
|
||||
for i,_ in enumerate(self.timestamped_alarm):
|
||||
if _[0]==reason:
|
||||
if _[1]==True:
|
||||
return True
|
||||
else:
|
||||
REASON_FLAG=False
|
||||
if datetime.now().timestamp()>=_[2]:
|
||||
# print('times up')
|
||||
self.timestamped_alarm[i]=[_[0],True,_[2]]
|
||||
return True
|
||||
else:
|
||||
now=datetime.now().timestamp(); then=_[2];
|
||||
if int(then-now) <= 0:
|
||||
# print('times up noticed in failure before success')
|
||||
pass
|
||||
# print(f'timeleft on alarm: {timeago.format(then,now)} - {int(then-now)}')
|
||||
return False
|
||||
if REASON_FLAG:
|
||||
print('<<< ________guds_plugin >>> [ timestamp_check ] timestamped reason not found')
|
||||
return -1
|
||||
except:
|
||||
print('<<< ________guds_plugin >>> [ timestamp_check ] timestamp_check error')
|
||||
return -1
|
||||
#######################################################################################
|
||||
def memory(self,data):
|
||||
for _ in self.memories:
|
||||
if not _[1].find(data)==-1:
|
||||
return _[0]
|
||||
#######################################################################################
|
||||
def push(self,data):
|
||||
self.push_index+=1
|
||||
|
54
runbot.sh
54
runbot.sh
@ -1,4 +1,4 @@
|
||||
which python3 > /dev/null 2>&1
|
||||
which python3 > /dev/null 2>&1 ################################################################################################## SOF
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "<<< error: missing python3 >>> - to continue install python3 first; aborting"
|
||||
exit
|
||||
@ -108,11 +108,33 @@ if [ -f ".venv" ]; then
|
||||
echo "export ACCESS_TOKEN_SECRET=523490582034985203948520394804884820934850923485" >> .venv/bin/activate
|
||||
fi
|
||||
#####################################################################################################################
|
||||
cat .venv/bin/activate|grep DISCORD__MAPLE
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "export DISCORD__MAPLE=554444333322221111" >> .venv/bin/activate
|
||||
fi
|
||||
#####################################################################################################################
|
||||
cat .venv/bin/activate|grep DISCORD__SCHAN
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "export DISCORD__SCHAN=554444333322221111" >> .venv/bin/activate
|
||||
fi
|
||||
#####################################################################################################################
|
||||
cat .venv/bin/activate|grep DISCORD__TOKEN
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "export DISCORD__TOKEN=uNITCOR9MI2BTzQ11MIZQTTJvO-liCU9OGzahWdm2A5Nj.j4XXL.h6gN2RyS05QnvbXU61" >> .venv/bin/activate
|
||||
fi
|
||||
#####################################################################################################################
|
||||
cat .venv/bin/activate|grep TELEGRAM_TOKEN
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "export TELEGRAM_TOKEN=gmJA894hBfF5EcU2v5G39o8oxUnJ0s5HB:SD9tAh7AW371" >> .venv/bin/activate
|
||||
fi
|
||||
#####################################################################################################################
|
||||
cat .venv/bin/activate|grep PYTHONASYNCIODEBUG
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "export PYTHONASYNCIODEBUG=1" >> .venv/bin/activate
|
||||
fi
|
||||
#####################################################################################################################
|
||||
|
||||
|
||||
#############################################################################################################################
|
||||
else
|
||||
mv .venv .backup_venv
|
||||
@ -135,32 +157,4 @@ else
|
||||
fi
|
||||
#####################################################################################################################################
|
||||
pipenv run maple
|
||||
#####################################################################################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
################################################################################################################################# EOF
|
||||
|
Loading…
Reference in New Issue
Block a user