pass botcom

This commit is contained in:
deathbybandaid 2019-06-28 14:59:58 -04:00
parent a375c6238d
commit 1ebf73f155
15 changed files with 65 additions and 26 deletions

View File

@ -12,7 +12,7 @@ import datetime
import spicemanip import spicemanip
from .Tools import command_permissions_check from .Tools import command_permissions_check, class_create
from .Commands import commands as botcommands from .Commands import commands as botcommands
from .Database import db as botdb from .Database import db as botdb
from .Channels import channels as botchannels from .Channels import channels as botchannels
@ -27,6 +27,8 @@ def prerun(t_command_type='module', t_command_subtype=None):
@functools.wraps(function) @functools.wraps(function)
def internal_prerun(bot, trigger, *args, **kwargs): def internal_prerun(bot, trigger, *args, **kwargs):
botcom = class_create('botcom')
if t_command_type == "nickname": if t_command_type == "nickname":
check_nick = spicemanip.main(trigger.args[1], 1).lower() check_nick = spicemanip.main(trigger.args[1], 1).lower()
if check_nick != str(bot.nick).lower(): if check_nick != str(bot.nick).lower():
@ -91,7 +93,7 @@ def prerun(t_command_type='module', t_command_subtype=None):
if not trigger.sb["hyphen_arg"]: if not trigger.sb["hyphen_arg"]:
# check if anything prohibits the nick from running the command # check if anything prohibits the nick from running the command
if trigger_runstatus(bot, trigger): if trigger_runstatus(bot, trigger):
function(bot, trigger, *args, **kwargs) function(bot, trigger, botcom, *args, **kwargs)
else: else:
trigger_hyphen_arg_handler(bot, trigger) trigger_hyphen_arg_handler(bot, trigger)
botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) botmessagelog.messagelog_exit(bot, argsdict_default["log_id"])
@ -107,6 +109,8 @@ def prerun_query(t_command_type='module', t_command_subtype=None):
@functools.wraps(function) @functools.wraps(function)
def internal_prerun(bot, trigger, *args, **kwargs): def internal_prerun(bot, trigger, *args, **kwargs):
botcom = class_create('botcom')
if t_command_type == "nickname": if t_command_type == "nickname":
check_nick = spicemanip.main(trigger.args[1], 1).lower() check_nick = spicemanip.main(trigger.args[1], 1).lower()
if check_nick != str(bot.nick).lower(): if check_nick != str(bot.nick).lower():
@ -155,7 +159,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None):
# check if anything prohibits the nick from running the command # check if anything prohibits the nick from running the command
if trigger_runstatus_query(bot, trigger): if trigger_runstatus_query(bot, trigger):
function(bot, trigger, *args, **kwargs) function(bot, trigger, botcom, *args, **kwargs)
botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) botmessagelog.messagelog_exit(bot, argsdict_default["log_id"])
return internal_prerun return internal_prerun

View File

@ -86,6 +86,41 @@ def command_permissions_check(bot, trigger, privslist):
return True return True
"""
Classes
"""
def class_create(classname):
compiletext = """
def __init__(self):
self.default = str(self.__class__.__name__)
def __repr__(self):
return repr(self.default)
def __str__(self):
return str(self.default)
def __iter__(self):
return str(self.default)
pass
"""
exec(compile("class class_" + str(classname) + ": " + compiletext, "", "exec"))
newclass = eval('class_'+classname+"()")
return newclass
def class_directory(inputclass):
# make sure input is a class
# if not isinstance(inputclass, class):
# return []
classdirlistfull, classdirlistclean = dir(inputclass), []
for classdiritem in classdirlistfull:
if not classdiritem.startswith("_"):
classdirlistclean.append(classdiritem)
return classdirlistclean
""" """
Time Time
""" """

View File

@ -11,7 +11,7 @@ import spicemanip
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('ai') @sopel.module.nickname_commands('ai')
def ai_trigger(bot, trigger): def ai_trigger(bot, trigger, botcom):
availablecomsnum = SpiceBot.botai.dict['patterncounts'] availablecomsnum = SpiceBot.botai.dict['patterncounts']
availablecomsfiles = SpiceBot.botai.dict['filecounts'] availablecomsfiles = SpiceBot.botai.dict['filecounts']
displayval = "There are " + str(availablecomsnum) + " AI pattern matches available in " + str(availablecomsfiles) + " files." displayval = "There are " + str(availablecomsnum) + " AI pattern matches available in " + str(availablecomsfiles) + " files."

View File

@ -11,13 +11,13 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('owners', 'owner') @sopel.module.nickname_commands('owners', 'owner')
def bot_command_owners(bot, trigger): def bot_command_owners(bot, trigger, botcom):
bot_command_process(bot, trigger) bot_command_process(bot, trigger)
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('admins', 'admin') @sopel.module.nickname_commands('admins', 'admin')
def bot_command_admins(bot, trigger): def bot_command_admins(bot, trigger, botcom):
bot_command_process(bot, trigger) bot_command_process(bot, trigger)

View File

@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED])
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('channels', 'channel') @sopel.module.nickname_commands('channels', 'channel')
def nickname_comand_channels(bot, trigger): def nickname_comand_channels(bot, trigger, botcom):
if not len(trigger.sb['args']): if not len(trigger.sb['args']):
commandused = 'list' commandused = 'list'

View File

@ -17,7 +17,7 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('commands', 'command') @sopel.module.nickname_commands('commands', 'command')
def nickname_comand_commands(bot, trigger): def nickname_comand_commands(bot, trigger, botcom):
if not len(trigger.sb['args']): if not len(trigger.sb['args']):
commandused = 'list' commandused = 'list'

View File

@ -14,14 +14,14 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('query') @sopel.module.nickname_commands('query')
def query_trigger(bot, trigger): def query_trigger(bot, trigger, botcom):
bot.osd("I have been programmed to help find new commands by using `?`.") bot.osd("I have been programmed to help find new commands by using `?`.")
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun_query('nickname', 'nickname') @SpiceBot.prerun_query('nickname', 'nickname')
@sopel.module.nickname_commands('(.*)') @sopel.module.nickname_commands('(.*)')
def query_detection_nick(bot, trigger): def query_detection_nick(bot, trigger, botcom):
# command issued, check if valid # command issued, check if valid
if not trigger.sb['com'] or not len(trigger.sb['com']): if not trigger.sb['com'] or not len(trigger.sb['com']):
@ -87,7 +87,7 @@ def query_detection_nick(bot, trigger):
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun_query('module', 'module') @SpiceBot.prerun_query('module', 'module')
@sopel.module.rule('^\?(.*)') @sopel.module.rule('^\?(.*)')
def query_detection(bot, trigger): def query_detection(bot, trigger, botcom):
# command issued, check if valid # command issued, check if valid
if not trigger.sb['com'] or not len(trigger.sb['com']): if not trigger.sb['com'] or not len(trigger.sb['com']):

View File

@ -17,7 +17,7 @@ from random import randint
@SpiceBot.prerun('module', 'dictcom') @SpiceBot.prerun('module', 'dictcom')
@sopel.module.commands('(.*)') @sopel.module.commands('(.*)')
def command_dictcom(bot, trigger): def command_dictcom(bot, trigger, botcom):
if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["dictcom"].keys()): if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["dictcom"].keys()):
return return

View File

@ -13,7 +13,7 @@ import spicemanip
@SpiceBot.prerun('module') @SpiceBot.prerun('module')
@sopel.module.commands('gif') @sopel.module.commands('gif')
def gif_trigger(bot, trigger): def gif_trigger(bot, trigger, botcom):
if not len(trigger.sb['args']): if not len(trigger.sb['args']):
return bot.osd("Please present a query to search.") return bot.osd("Please present a query to search.")
@ -32,7 +32,7 @@ def gif_trigger(bot, trigger):
@SpiceBot.prerun('module', "gif_prefix") @SpiceBot.prerun('module', "gif_prefix")
@sopel.module.commands('(.*)') @sopel.module.commands('(.*)')
def gifapi_triggers(bot, trigger): def gifapi_triggers(bot, trigger, botcom):
if trigger.sb['com'] not in list(SpiceBot.gif.valid_api.keys()): if trigger.sb['com'] not in list(SpiceBot.gif.valid_api.keys()):
return return

View File

@ -15,7 +15,7 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOGS]) @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOGS])
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('logs', 'debug') @sopel.module.nickname_commands('logs', 'debug')
def bot_command_logs(bot, trigger): def bot_command_logs(bot, trigger, botcom):
if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
bot.osd("I was unable to process this Bot Nick command due to privilege issues.") bot.osd("I was unable to process this Bot Nick command due to privilege issues.")

View File

@ -11,19 +11,19 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('action') @sopel.module.nickname_commands('action')
def bot_command_action(bot, trigger): def bot_command_action(bot, trigger, botcom):
bot_command_process(bot, trigger) bot_command_process(bot, trigger)
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('notice') @sopel.module.nickname_commands('notice')
def bot_command_notice(bot, trigger): def bot_command_notice(bot, trigger, botcom):
bot_command_process(bot, trigger) bot_command_process(bot, trigger)
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('privmsg', 'say', 'msg') @sopel.module.nickname_commands('privmsg', 'say', 'msg')
def bot_command_privmsg(bot, trigger): def bot_command_privmsg(bot, trigger, botcom):
bot_command_process(bot, trigger) bot_command_process(bot, trigger)

View File

@ -11,7 +11,7 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('update') @sopel.module.nickname_commands('update')
def nickname_comand_update(bot, trigger): def nickname_comand_update(bot, trigger, botcom):
if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
bot.osd("I was unable to process this Bot Nick command due to privilege issues.") bot.osd("I was unable to process this Bot Nick command due to privilege issues.")
@ -42,7 +42,7 @@ def nickname_comand_update(bot, trigger):
@sopel.module.nickname_commands('restart') @sopel.module.nickname_commands('restart')
def nickname_comand_restart(bot, trigger): def nickname_comand_restart(bot, trigger, botcom):
if not trigger.admin: if not trigger.admin:
bot.osd("You are not authorized to perform this function.") bot.osd("You are not authorized to perform this function.")

View File

@ -12,7 +12,7 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('module') @SpiceBot.prerun('module')
@sopel.module.commands('search', 'find', 'google', 'lookup') @sopel.module.commands('search', 'find', 'google', 'lookup')
def search_main(bot, trigger): def search_main(bot, trigger, botcom):
searchterm = spicemanip.main(trigger.sb['args'], 0) or None searchterm = spicemanip.main(trigger.sb['args'], 0) or None
if not searchterm: if not searchterm:
@ -28,7 +28,7 @@ def search_main(bot, trigger):
@SpiceBot.prerun('module') @SpiceBot.prerun('module')
@sopel.module.commands("where", "whereis") @sopel.module.commands("where", "whereis")
def search_where(bot, trigger): def search_where(bot, trigger, botcom):
searchterm = spicemanip.main(trigger.sb['args'], 0) or None searchterm = spicemanip.main(trigger.sb['args'], 0) or None
if not searchterm: if not searchterm:
@ -44,7 +44,7 @@ def search_where(bot, trigger):
@SpiceBot.prerun('module') @SpiceBot.prerun('module')
@sopel.module.commands("what", "whatis") @sopel.module.commands("what", "whatis")
def search_what(bot, trigger): def search_what(bot, trigger, botcom):
searchterm = spicemanip.main(trigger.sb['args'], 0) or None searchterm = spicemanip.main(trigger.sb['args'], 0) or None
if not searchterm: if not searchterm:
@ -60,7 +60,7 @@ def search_what(bot, trigger):
@SpiceBot.prerun('module') @SpiceBot.prerun('module')
@sopel.module.commands("youtube", "video") @sopel.module.commands("youtube", "video")
def search_video(bot, trigger): def search_video(bot, trigger, botcom):
searchterm = spicemanip.main(trigger.sb['args'], 0) or None searchterm = spicemanip.main(trigger.sb['args'], 0) or None
if not searchterm: if not searchterm:

View File

@ -11,7 +11,7 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('module') @SpiceBot.prerun('module')
@sopel.module.commands('sherlock', 'username') @sopel.module.commands('sherlock', 'username')
def bot_command_sherlock(bot, trigger): def bot_command_sherlock(bot, trigger, botcom):
netlist = list(SpiceBot.sherlock.dict.keys()) netlist = list(SpiceBot.sherlock.dict.keys())

View File

@ -11,6 +11,6 @@ import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname') @SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('uptime') @sopel.module.nickname_commands('uptime')
def bot_command_uptime(bot, trigger): def bot_command_uptime(bot, trigger, botcom):
timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago."
bot.osd("I have been running since " + timesince) bot.osd("I have been running since " + timesince)