diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index 096caa4..c818d79 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -15,8 +15,6 @@ import spicemanip from .Config import config as botconfig from .Events import events from .Logs import logs -from .Prerun import prerun -from .Tools import inlist, channel_privs class SpiceBot_Channels_MainSection(StaticSection): @@ -190,110 +188,3 @@ def trigger_channel_list_recurring(bot, trigger): if "*" in channels.dict['list'].keys(): del channels.dict['list']["*"] channels.bot_part_empty(bot) - - -@events.check_ready([events.BOT_LOADED]) -@prerun.prerun('nickname') -@sopel.module.nickname_commands('channels', 'channel') -def nickname_comand_channels(bot, trigger): - - if not len(trigger.sb['args']): - commandused = 'list' - else: - commandused = spicemanip.main(trigger.sb['args'], 1).lower() - - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') - - if commandused == 'list': - chanlist = spicemanip.main(bot.channels.keys(), 'andlist') - bot.osd("You can find me in " + chanlist) - return - - elif commandused == 'total': - botcount = len(bot.channels.keys()) - servercount = len(channels.dict['list'].keys()) - bot.osd("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.") - return - - elif commandused == 'random': - channel = spicemanip.main(channels.dict['list'], 'random') - topic = channels.dict['list'][channel]['topic'] - msg = ["Random channel for you: {}.".format(channels.dict['list'][channel]['name'])] - if topic and not topic.isspace(): - msg.append("The topic is: {}".format(topic)) - else: - msg.append("Its topic is empty.") - bot.osd(msg) - return - - elif commandused == 'update': - if not trigger.admin: - bot.osd("You do not have permission to update the channel listing.") - return - channels.bot_part_empty(bot) - channels.channel_list_request(bot) - bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."]) - while channels.channel_lock: - pass - channels.join_all_channels(bot) - foundchannelcount = len(channels.dict['list'].keys()) - bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.") - channels.bot_part_empty(bot) - return - - elif commandused == 'topic': - if not len(trigger.sb['args']): - bot.osd("Channel name input missing.") - return - channel = spicemanip.main(trigger.sb['args'], 1) - if not inlist(channel.lower(), channels.dict['list'].keys()): - bot.osd("Channel name {} not valid.".format(channel)) - return - topic = channels.dict['list'][channel.lower()]['topic'] - channel = channels.dict['list'][channel.lower()]['name'] - bot.osd("Topic for {}: {}".format(channel, topic)) - return - - if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']: - if not len(trigger.sb['args']): - if trigger.is_privmsg: - bot.osd("Channel name required.") - return - else: - channel = trigger.sender - else: - channel = spicemanip.main(trigger.sb['args'], 1) - if not inlist(channel.lower(), channels.dict['list'].keys()): - bot.osd("Channel name {} not valid.".format(channel)) - return - if not inlist(channel.lower(), bot.channels.keys()): - bot.osd("I need to be in {} to see nick privileges.".format(channel)) - return - - privlist = channel_privs(bot, channel, commandused.upper()) - dispmsg = [] - if not len(privlist): - dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel)) - else: - oplist = spicemanip.main(privlist, 'andlist') - dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist) - bot.osd(dispmsg, trigger.nick, 'notice') - return - - # Users List - if commandused == 'users': - channel = spicemanip.main(trigger.sb['args'], 1) - if not inlist(channel.lower(), channels.dict['list'].keys()): - bot.osd("Channel name {} not valid.".format(channel)) - return - if not inlist(channel.lower(), bot.channels.keys()): - bot.osd("I need to be in {} to see user list.".format(channel)) - return - dispmsg = [] - if not len(bot.channels[channel].privileges.keys()): - dispmsg.append("There are no Channel users for " + str(channel)) - else: - userslist = spicemanip.main(bot.channels[channel].privileges.keys(), 'andlist') - dispmsg.append("Channel users for " + str(channel) + " are: " + userslist) - bot.osd(dispmsg, trigger.nick, 'notice') - return diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index f1da6f5..3bc8fdd 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -14,9 +14,6 @@ import spicemanip from .Logs import logs from .Config import config as botconfig from .Database import db as botdb -from .Events import events -from .Prerun import prerun as botprerun -from .Tools import letters_in_string, similar_list class BotCommands(): @@ -234,133 +231,3 @@ class BotCommands(): commands = BotCommands() - - -@events.check_ready([events.BOT_COMMANDSQUERY]) -@botprerun.prerun('nickname') -@sopel.module.nickname_commands('(.*)') -def query_detection_nick(bot, trigger): - - # command issued, check if valid - if not trigger.sb['com'] or not len(trigger.sb['com']): - return - - if not trigger.sb['com'][0] == "?": - return - trigger.sb['com'] = trigger.sb['com'][1:] - - if not letters_in_string(trigger.sb['com']): - return - - commands_list = dict() - for com in commands.dict['commands']['nickname'].keys(): - if com not in commands_list.keys(): - commands_list[com] = commands.dict['commands']['nickname'][com] - - if trigger.sb['com'].endswith("+"): - - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): - return - - if trigger.sb['com'].lower() not in list(commands_list.keys()): - dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(trigger.sb['com']) + "."] - closestmatches = similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') - if len(closestmatches): - dispmsg.append("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") - bot.osd(dispmsg, trigger.nick, 'notice') - return - - realcom = trigger.sb['com'] - if "aliasfor" in commands_list[trigger.sb['com']].keys(): - realcom = commands_list[trigger.sb['com']]["aliasfor"] - validcomlist = commands_list[realcom]["validcoms"] - bot.osd("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') - return - - if trigger.sb['com'].endswith("?"): - - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): - return - - closestmatches = similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') - if not len(closestmatches): - bot.osd("Cannot find any similar " + bot.nick + " commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') - else: - bot.osd("The following " + bot.nick + " commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') - return - - commandlist = [] - for command in list(commands_list.keys()): - if command.lower().startswith(str(trigger.sb['com']).lower()): - commandlist.append(command) - - if not len(commandlist): - bot.osd("No " + bot.nick + " commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') - else: - bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') - - -@events.check_ready([events.BOT_COMMANDSQUERY]) -@botprerun.prerun('query') -@sopel.module.rule('^\?(.*)') -def query_detection(bot, trigger): - - # command issued, check if valid - if not trigger.sb['com'] or not len(trigger.sb['com']): - return - - if not letters_in_string(trigger.sb['com']): - return - - commands_list = dict() - for commandstype in commands.dict['commands'].keys(): - if commandstype not in ['rule', 'nickname']: - for com in commands.dict['commands'][commandstype].keys(): - if com not in commands_list.keys(): - commands_list[com] = commands.dict['commands'][commandstype][com] - - if trigger.sb['com'][:-1] == "+": - - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): - return - - if trigger.sb['com'].lower() not in list(commands_list.keys()): - dispmsg = ["Cannot find any alias commands: No valid commands match " + str(trigger.sb['com']) + "."] - closestmatches = similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') - if len(closestmatches): - dispmsg.append("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") - bot.osd(dispmsg, trigger.nick, 'notice') - return - - realcom = trigger.sb['com'] - if "aliasfor" in commands_list[trigger.sb['com']].keys(): - realcom = commands_list[trigger.sb['com']]["aliasfor"] - validcomlist = commands_list[realcom]["validcoms"] - bot.osd("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') - return - - if trigger.sb['com'][:-1] == "?": - - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): - return - - closestmatches = similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') - if not len(closestmatches): - bot.osd("Cannot find any similar commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') - else: - bot.osd("The following commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') - return - - commandlist = [] - for command in list(commands_list.keys()): - if command.lower().startswith(str(trigger.sb['com']).lower()): - commandlist.append(command) - - if not len(commandlist): - bot.osd("No commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') - else: - bot.osd("The following commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 8f66223..5832abc 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -590,8 +590,3 @@ class BotDatabase(): db = BotDatabase() - - -@sopel.module.nickname_commands('database') -def bot_command_database(bot, trigger): - bot.osd("Database is " + botconfig.db_type) diff --git a/sopel_modules/SpiceBot_Core_Commands/Channels.py b/sopel_modules/SpiceBot_Core_Commands/Channels.py new file mode 100644 index 0000000..289e7f8 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Commands/Channels.py @@ -0,0 +1,117 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Channels system. +""" +import sopel + +import spicemanip + +import sopel_modules.SpiceBot as SpiceBot + + +@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) +@SpiceBot.prerun.prerun('nickname') +@sopel.module.nickname_commands('channels', 'channel') +def nickname_comand_channels(bot, trigger): + + if not len(trigger.sb['args']): + commandused = 'list' + else: + commandused = spicemanip.main(trigger.sb['args'], 1).lower() + + trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') + + if commandused == 'list': + chanlist = spicemanip.main(bot.SpiceBot.channels.keys(), 'andlist') + bot.osd("You can find me in " + chanlist) + return + + elif commandused == 'total': + botcount = len(bot.SpiceBot.channels.keys()) + servercount = len(SpiceBot.channels.dict['list'].keys()) + bot.osd("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.") + return + + elif commandused == 'random': + channel = spicemanip.main(SpiceBot.channels.dict['list'], 'random') + topic = SpiceBot.channels.dict['list'][channel]['topic'] + msg = ["Random channel for you: {}.".format(SpiceBot.channels.dict['list'][channel]['name'])] + if topic and not topic.isspace(): + msg.append("The topic is: {}".format(topic)) + else: + msg.append("Its topic is empty.") + bot.osd(msg) + return + + elif commandused == 'update': + if not trigger.admin: + bot.osd("You do not have permission to update the channel listing.") + return + SpiceBot.channels.bot_part_empty(bot) + SpiceBot.channels.channel_list_request(bot) + bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."]) + while SpiceBot.channels.channel_lock: + pass + SpiceBot.channels.join_all_channels(bot) + foundchannelcount = len(SpiceBot.channels.dict['list'].keys()) + bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.") + SpiceBot.channels.bot_part_empty(bot) + return + + elif commandused == 'topic': + if not len(trigger.sb['args']): + bot.osd("Channel name input missing.") + return + channel = spicemanip.main(trigger.sb['args'], 1) + if not SpiceBot.inlist(channel.lower(), SpiceBot.channels.dict['list'].keys()): + bot.osd("Channel name {} not valid.".format(channel)) + return + topic = SpiceBot.channels.dict['list'][channel.lower()]['topic'] + channel = SpiceBot.channels.dict['list'][channel.lower()]['name'] + bot.osd("Topic for {}: {}".format(channel, topic)) + return + + if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']: + if not len(trigger.sb['args']): + if trigger.is_privmsg: + bot.osd("Channel name required.") + return + else: + channel = trigger.sender + else: + channel = spicemanip.main(trigger.sb['args'], 1) + if not SpiceBot.inlist(channel.lower(), SpiceBot.channels.dict['list'].keys()): + bot.osd("Channel name {} not valid.".format(channel)) + return + if not SpiceBot.inlist(channel.lower(), bot.SpiceBot.channels.keys()): + bot.osd("I need to be in {} to see nick privileges.".format(channel)) + return + + privlist = SpiceBot.channel_privs(bot, channel, commandused.upper()) + dispmsg = [] + if not len(privlist): + dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel)) + else: + oplist = spicemanip.main(privlist, 'andlist') + dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist) + bot.osd(dispmsg, trigger.nick, 'notice') + return + + # Users List + if commandused == 'users': + channel = spicemanip.main(trigger.sb['args'], 1) + if not SpiceBot.inlist(channel.lower(), SpiceBot.channels.dict['list'].keys()): + bot.osd("Channel name {} not valid.".format(channel)) + return + if not SpiceBot.inlist(channel.lower(), bot.SpiceBot.channels.keys()): + bot.osd("I need to be in {} to see user list.".format(channel)) + return + dispmsg = [] + if not len(bot.channels[channel].privileges.keys()): + dispmsg.append("There are no Channel users for " + str(channel)) + else: + userslist = spicemanip.main(bot.channels[channel].privileges.keys(), 'andlist') + dispmsg.append("Channel users for " + str(channel) + " are: " + userslist) + bot.osd(dispmsg, trigger.nick, 'notice') + return diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py new file mode 100644 index 0000000..bf632a8 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -0,0 +1,142 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Commands system. + +This Class stores commands in an easy to access manner +""" +import sopel + +import spicemanip + +import sopel_modules.SpiceBot as SpiceBot + + +@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDSQUERY]) +@SpiceBot.prerun.prerun('nickname') +@sopel.module.nickname_commands('(.*)') +def query_detection_nick(bot, trigger): + + # command issued, check if valid + if not trigger.sb['com'] or not len(trigger.sb['com']): + return + + if not trigger.sb['com'][0] == "?": + return + trigger.sb['com'] = trigger.sb['com'][1:] + + if not SpiceBot.letters_in_string(trigger.sb['com']): + return + + commands_list = dict() + for com in SpiceBot.commands.dict['commands']['nickname'].keys(): + if com not in commands_list.keys(): + commands_list[com] = SpiceBot.commands.dict['commands']['nickname'][com] + + if trigger.sb['com'].endswith("+"): + + trigger.sb['com'] = trigger.sb['com'][:-1] + if not trigger.sb['com'] or not len(trigger.sb['com']): + return + + if trigger.sb['com'].lower() not in list(commands_list.keys()): + dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(trigger.sb['com']) + "."] + closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + if len(closestmatches): + dispmsg.append("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + bot.osd(dispmsg, trigger.nick, 'notice') + return + + realcom = trigger.sb['com'] + if "aliasfor" in commands_list[trigger.sb['com']].keys(): + realcom = commands_list[trigger.sb['com']]["aliasfor"] + validcomlist = commands_list[realcom]["validcoms"] + bot.osd("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') + return + + if trigger.sb['com'].endswith("?"): + + trigger.sb['com'] = trigger.sb['com'][:-1] + if not trigger.sb['com'] or not len(trigger.sb['com']): + return + + closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + if not len(closestmatches): + bot.osd("Cannot find any similar " + bot.nick + " commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + else: + bot.osd("The following " + bot.nick + " commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + return + + commandlist = [] + for command in list(commands_list.keys()): + if command.lower().startswith(str(trigger.sb['com']).lower()): + commandlist.append(command) + + if not len(commandlist): + bot.osd("No " + bot.nick + " commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + else: + bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') + + +@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDSQUERY]) +@SpiceBot.prerun.prerun('query') +@sopel.module.rule('^\?(.*)') +def query_detection(bot, trigger): + + # command issued, check if valid + if not trigger.sb['com'] or not len(trigger.sb['com']): + return + + if not SpiceBot.letters_in_string(trigger.sb['com']): + return + + commands_list = dict() + for commandstype in SpiceBot.commands.dict['commands'].keys(): + if commandstype not in ['rule', 'nickname']: + for com in SpiceBot.commands.dict['commands'][commandstype].keys(): + if com not in commands_list.keys(): + commands_list[com] = SpiceBot.commands.dict['commands'][commandstype][com] + + if trigger.sb['com'][:-1] == "+": + + trigger.sb['com'] = trigger.sb['com'][:-1] + if not trigger.sb['com'] or not len(trigger.sb['com']): + return + + if trigger.sb['com'].lower() not in list(commands_list.keys()): + dispmsg = ["Cannot find any alias commands: No valid commands match " + str(trigger.sb['com']) + "."] + closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + if len(closestmatches): + dispmsg.append("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + bot.osd(dispmsg, trigger.nick, 'notice') + return + + realcom = trigger.sb['com'] + if "aliasfor" in commands_list[trigger.sb['com']].keys(): + realcom = commands_list[trigger.sb['com']]["aliasfor"] + validcomlist = commands_list[realcom]["validcoms"] + bot.osd("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') + return + + if trigger.sb['com'][:-1] == "?": + + trigger.sb['com'] = trigger.sb['com'][:-1] + if not trigger.sb['com'] or not len(trigger.sb['com']): + return + + closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + if not len(closestmatches): + bot.osd("Cannot find any similar commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + else: + bot.osd("The following commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + return + + commandlist = [] + for command in list(commands_list.keys()): + if command.lower().startswith(str(trigger.sb['com']).lower()): + commandlist.append(command) + + if not len(commandlist): + bot.osd("No commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + else: + bot.osd("The following commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') diff --git a/sopel_modules/SpiceBot_Core_Commands/Database.py b/sopel_modules/SpiceBot_Core_Commands/Database.py new file mode 100644 index 0000000..c4773a5 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Commands/Database.py @@ -0,0 +1,15 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Database +""" + +# sopel imports +import sopel.module + +import sopel_modules.SpiceBot as SpiceBot + + +@sopel.module.nickname_commands('database') +def bot_command_database(bot, trigger): + bot.osd("Database is " + SpiceBot.config.db_type) diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py new file mode 100644 index 0000000..38f3e8e --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -0,0 +1,15 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +These are the core SpiceBot Classes + +This module contains references only for other modules to utilize. +""" + +from .Commands import * +from .Channels import * +from .Database import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.1'