265 lines
11 KiB
Python
265 lines
11 KiB
Python
# -*- coding: utf-8 -*- ############################################################### SOF
|
|
###########################################################################################
|
|
|
|
???DISCORD???
|
|
???TELEGRAM???
|
|
???MATRIX???
|
|
|
|
###########################################################################################
|
|
###########################################################################################
|
|
|
|
import asyncio
|
|
|
|
###########################################################################################
|
|
###########################################################################################
|
|
|
|
import irc3
|
|
from irc3.plugins.command import command
|
|
|
|
###########################################################################################
|
|
###########################################################################################
|
|
|
|
from tool_bus_plugin import BUS
|
|
from tool_colors_plugin import colorform as print
|
|
from tool_dims_plugin import dims
|
|
from tool_guds_plugin import guds
|
|
|
|
###########################################################################################
|
|
###########################################################################################
|
|
|
|
@irc3.plugin
|
|
class Plugin:
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
def __init__(self, bot):
|
|
print('[ loaded ]')
|
|
self.bot = bot
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
@classmethod
|
|
def reload(cls, old):
|
|
return cls(old.bot)
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
def before_reload(self):
|
|
pass
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
def after_reload(self):
|
|
pass
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
@irc3.extend
|
|
@command(permission='admin', public=False, show_in_help_list=False)
|
|
async def listrooms(self,sender_netroomchan,sender_user,target,):
|
|
"""listrooms - lists rooms/channels/groups this bot is currently in
|
|
%%listrooms
|
|
"""
|
|
results=[]
|
|
result=dims.list_channels()
|
|
for _ in result:
|
|
|
|
#########################################
|
|
if SERVICES_MATRIX and _.startswith('!'):
|
|
#########################################
|
|
|
|
room=f'__matrix: {_}'
|
|
|
|
#######################
|
|
elif _.startswith('#'):
|
|
#######################
|
|
|
|
room=f'_____irc: {_}'
|
|
|
|
#############################################
|
|
elif SERVICES_TELEGRAM and _.startswith('$'):
|
|
#############################################
|
|
|
|
room=f'telegram: {_}'
|
|
|
|
############################################
|
|
elif SERVICES_DISCORD and _.startswith('^'):
|
|
############################################
|
|
|
|
room=f'_discord: {_}'
|
|
|
|
###############################################################################
|
|
###############################################################################
|
|
|
|
msg=f'[ ({sender_netroomchan})({sender_user})(listrooms)->({target}) ] - {room}'
|
|
print(msg)
|
|
results.append(room)
|
|
|
|
###################################################################################
|
|
###################################################################################
|
|
|
|
return results
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
@irc3.extend
|
|
@command(permission='admin', public=False, show_in_help_list=False)
|
|
async def listbridges(self,sender_netroomchan,sender_user,target,):
|
|
"""listbridges - lists rooms/channels/groups this bot is currently in
|
|
%%listbridges
|
|
"""
|
|
results=[]
|
|
result=dims.list_channels_bridged()
|
|
for _ in result:
|
|
msg=f'[ ({sender_netroomchan})({sender_user})(listbridges) ] - {_}'
|
|
print(msg)
|
|
if _[0]:
|
|
channel=_[0]
|
|
else:
|
|
channel=None
|
|
if _[1]:
|
|
inbound=_[1]
|
|
else:
|
|
inbound=None
|
|
if _[2]:
|
|
outbound=_[2]
|
|
else:
|
|
outbound=None
|
|
if inbound and outbound:
|
|
results.append(f"{channel} - inbound: {inbound} - outbound: {outbound}")
|
|
elif inbound:
|
|
results.append(f"{channel} - inbound: {inbound}")
|
|
elif outbound:
|
|
results.append(f"{channel} - outbound: {outbound}")
|
|
else:
|
|
results.append(f"{channel}")
|
|
return results
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
@irc3.extend
|
|
@command(permission='admin', public=False, show_in_help_list=False)
|
|
async def addbridge(self,mask,target,args):
|
|
"""addbridge - add a bridge rule for a netspan channel/room/group. use ?listrooms, ?listbridges for information. usage: ?addbridge #b0tsh0p ^χιϛ
|
|
%%addbridge <noise>...
|
|
"""
|
|
noise=' '.join(args['<noise>']).strip()
|
|
src_outbound=noise.split()[0]
|
|
dest_inbound=noise.split()[1]
|
|
results=[]
|
|
result=dims.bridge_routes(src_outbound,dest_inbound,"add")
|
|
if result[0]:
|
|
status="status: completed"
|
|
else:
|
|
status=f"status: failed - {result[1]}"
|
|
results.append(f"[ {src_outbound} -> {dest_inbound} ] - adding bridge - {status}")
|
|
msg=f'<<< ________dims_plugin >>> [ addbridge ] - {src_outbound} -> {dest_inbound} - {status}'
|
|
print(msg)
|
|
return results
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
@irc3.extend
|
|
@command(permission='admin', public=False, show_in_help_list=False)
|
|
async def delbridge(self,mask,target,args):
|
|
"""delbridge - delete a bridge rule for a netspan channel/room/group. use ?listrooms, ?listbridges for information. usage: ?delbridge #b0tsh0p ^χιϛ
|
|
%%delbridge <noise>...
|
|
"""
|
|
noise=' '.join(args['<noise>']).strip()
|
|
src_outbound=noise.split()[0]
|
|
dest_inbound=noise.split()[1]
|
|
results=[]
|
|
result=dims.bridge_routes(src_outbound,dest_inbound,"del")
|
|
if result[0]:
|
|
status="status: completed"
|
|
else:
|
|
status=f"status: failed - {result[1]}"
|
|
results.append(f"[ {src_outbound} -> {dest_inbound} ] - deleting bridge - {status}")
|
|
msg=f'<<< ________dims_plugin >>> [ addbridge ] - {src_outbound} -> {dest_inbound} - {status}'
|
|
print(msg)
|
|
return results
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
@irc3.extend
|
|
@command(permission='admin', public=False, show_in_help_list=False)
|
|
async def blackhole(self,mask,target,args):
|
|
"""blackhole - prevents maple from reverberating on bridges. usage: ?blackhole !asdfasdfasdfsad:pcriot.org add or ?blackhole !asdfasdfasd del
|
|
%%blackhole <noise>...
|
|
"""
|
|
noise=' '.join(args['<noise>']).strip()
|
|
if noise=="list":
|
|
self.blackhole=[]
|
|
ircbot=guds.memory('ircbot')
|
|
dbname="blackhole"
|
|
db=ircbot.db.getlist(dbname)
|
|
if db:
|
|
for entry in db:
|
|
self.blackhole.append(entry)
|
|
return self.blackhole
|
|
|
|
###################################################################################
|
|
###################################################################################
|
|
|
|
src_blackhole=noise.split()[0]
|
|
command=noise.split()[1]
|
|
results=[]
|
|
result=dims.blackholes(src_blackhole,command)
|
|
results.append(f"[ {src_blackhole} ] - adding blackhole")
|
|
msg=f'<<< ________dims_plugin >>> [ addblackhole ] - {src_blackhole}'
|
|
print(msg)
|
|
return results
|
|
|
|
#######################################################################################
|
|
#######################################################################################
|
|
|
|
@irc3.extend
|
|
@command(permission='admin', public=False, show_in_help_list=False)
|
|
async def purgebridges(self, mask=None, target=None, data=None, sender_user=None, sender_netroomchan=None, **kw):
|
|
"""purgebridges - erases channel/room message history across nets
|
|
%%purgebridges
|
|
"""
|
|
|
|
####################
|
|
if SERVICES_DISCORD:
|
|
####################
|
|
|
|
msg=f'[ ({mask.nick}{target}).purgebridges()->({target}) ] - purging'
|
|
print(msg)
|
|
from net_discord_plugin import d_discord_cmd
|
|
d_discord_cmd(target,"purgebridges")
|
|
|
|
#####
|
|
else:
|
|
#####
|
|
|
|
msg=f'[ ({mask.nick}{target}).purgebridges()->({target}) ] - command disabled, not servicing discord atm'
|
|
print(msg)
|
|
|
|
###################################################################### NET IRC - MAIN [4/4]
|
|
###################################################################### NET IRC - MAIN [4/4]
|
|
|
|
async def _d_cmd_irc(sender_netroomchan,sender_user,target,cmd,) -> None:
|
|
result=(await eval(f"guds.memory('ircbot').{cmd}")(sender_netroomchan=sender_netroomchan,sender_user=sender_user,target=target,cmd=cmd,))
|
|
bridgedbus=(BUS(['#b0tsh0p','!OftXgmqAFOPEatmvLU:pcriot.org'])) # hardcoded channel, audit - maybe from debugging
|
|
await bridgedbus.output([sender_netroomchan,sender_user],result) # hardcoded channel, audit - maybe from debugging
|
|
|
|
###########################################################################################
|
|
###########################################################################################
|
|
|
|
def d_cmd_irc(sender_netroomchan,sender_user,target,cmd,):
|
|
self=guds.memory('ircbot')
|
|
asyncio.run_coroutine_threadsafe(_d_cmd_irc(sender_netroomchan,sender_user,target,cmd,),self.loop)
|
|
|
|
###########################################################################################
|
|
####################################################################################### EOF
|