This commit is contained in:
.[d]. 2023-03-26 15:08:10 -05:00
parent 6ddab36cce
commit 4fafc5484d
3 changed files with 9 additions and 153 deletions

View File

@ -1,149 +0,0 @@
# -*- coding: utf-8 -*- ############################################################### SOF
###########################################################################################
from irc3.plugins.command import command
import irc3
import sys
import inspect
###########################################################################################
###########################################################################################
@irc3.plugin
class Plugin:
#######################################################################################
#######################################################################################
def __init__(self, bot):
from tool_colors_plugin import colorform as print
from tool_colors_plugin import COLORFORM as INFO
self.bot = bot
self.bot.info=INFO(self)
###########################################################################################
###########################################################################################
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(data):
frame = inspect.currentframe().f_back
try:
codeobj = frame.f_code
try:
self_name = codeobj.co_varnames[0]
except IndexError:
self_name = None
caller = None
raise Exception()
try:
self_obj = frame.f_locals[self_name]
except KeyError:
caller = None
raise Exception()
self_type = type(self_obj)
func_name = codeobj.co_name
for cls in self_type.__mro__:
try:
method = vars(cls)[func_name]
except KeyError:
continue
try:
method = inspect.unwrap(method)
except ValueError:
pass
if getattr(method, '__code__', None) is codeobj:
caller = self_type.__name__
raise Exception()
caller = None
raise Exception()
except:
pass
finally:
del frame
###################################################################################
###################################################################################
self = None
###################################################################################
###################################################################################
the_caller_path_to_file=sys._getframe().f_code.co_filename
the_caller=the_caller_path_to_file.split('/')[-1].split('.')[0]
the_call=sys._getframe(1).f_code.co_name
the_function=sys._getframe().f_code.co_name
the_origin=codeobj.co_filename.split('/')[-1].replace('.py','')
the_origin="_"*(19-len(the_origin))+the_origin
try:
msg=f'{rgb(b=255)}<<<{rgb(g=255,b=255)} {the_origin} {rgb(b=255)}>>> '
except:
msg='break'
if self and data and caller:
the_class=""
the_class=type(self).__name__
if codeobj.co_filename==the_caller_path_to_file:
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{caller}.{the_class}.{the_call} {rgb(r=255)}]'
else:
origin=codeobj.co_filename.split('/')[-1].replace('.py','')
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{the_call}.{caller} {rgb(r=255)}]'
msg+=f'{rgb(b=255)} - '
msg+=f'{rgb(g=128,b=128,r=128)}{data}'
else:
try:
caller=str(self).split(f'<{__name__}.')[1].split()[0]
except:
caller=""
if not self_name and the_call=="<module>":
if codeobj.co_filename==the_caller_path_to_file:
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{__name__}.{caller}.{the_function} {rgb(r=255)}]'
else:
origin=codeobj.co_filename.split('/')[-1].replace('.py','')
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{origin} {rgb(r=255)}]'
else:
if codeobj.co_filename==the_caller_path_to_file:
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{the_call} {rgb(r=255)}]'
else:
caller=codeobj.co_filename.split('/')[-1].replace('.py','')
try:
the_origin=str(self_type).split("'")[1]
except:
pass
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{the_origin}.{the_call} {rgb(r=255)}]'.replace(f'plugins.{caller}.Plugin.','').replace(f'plugins.{caller}.','').replace(f'{caller}.','').replace('Plugin.','')
msg+=f'{rgb(b=255)} - '
msg+=f'{rgb(g=128,b=128,r=128)}{data}'
print(msg)
###########################################################################################
###########################################################################################
class COLORFORM:
def __init__(self,c):
c.bot.log.info=self.info
def info(self,s=None,cfg=None):
try:
s = s % cfg
except:
s = ""
msg=f'[ {s} ]'
globals()['colorform'](msg)
###########################################################################################
####################################################################################### EOF

View File

@ -34,7 +34,7 @@ if SERVICES_DISCORD:
#######################################################################################
#######################################################################################
from irc3.plugins.command import command
#######################################################################################
@ -102,7 +102,7 @@ if SERVICES_DISCORD:
####################
if SERVICES_DISCORD:
####################
intents=discord.Intents.default()
intents.members = True
intents.messages = True
@ -110,6 +110,8 @@ if SERVICES_DISCORD:
intents.message_content = True
client=discord.Client(intents=intents)
def __init__(self):
discord.gateway._log=print
discord.client._log=print
self.ircbot=guds.memory('ircbot')
self.dbname="discordchat"
self.db=self.ircbot.db.getlist(self.dbname)

View File

@ -122,8 +122,11 @@ def colorform(data):
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{the_call} {rgb(r=255)}]'
else:
caller=codeobj.co_filename.split('/')[-1].replace('.py','')
the_origin=str(self_type).split("'")[1]
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{the_origin}.{the_call} {rgb(r=255)}]'.replace(f'plugins.{caller}.Plugin.','').replace(f'plugins.{caller}.','')
try:
the_origin=str(self_type).split("'")[1]
except:
pass
msg+=f'{rgb(r=255)}[ {rgb(r=255,b=255)}{the_origin}.{the_call} {rgb(r=255)}]'.replace(f'plugins.{caller}.Plugin.','').replace(f'plugins.{caller}.','').replace(f'{caller}.','').replace('Plugin.','')
msg+=f'{rgb(b=255)} - '
msg+=f'{rgb(g=128,b=128,r=128)}{data}'
print(msg)