diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 8985fea..d8e63d5 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -126,7 +126,8 @@ def watch_chanlist_complete(bot, trigger): @sopel.module.nickname_commands('channels', 'channel') def nickname_comand_chanstats(bot, trigger): - triggerargs = sopel_triggerargs(bot, trigger, 'nickname_command') + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') if not len(triggerargs): commandused = 'list' diff --git a/sopel_modules/SpiceBot_GifSearch/gif.py b/sopel_modules/SpiceBot_GifSearch/gif.py index a5f4724..dfd1cef 100644 --- a/sopel_modules/SpiceBot_GifSearch/gif.py +++ b/sopel_modules/SpiceBot_GifSearch/gif.py @@ -19,7 +19,7 @@ def gif_trigger(bot, trigger): while "SpiceBot_GifSearch" not in bot.memory: pass - triggerargs = sopel_triggerargs(bot, trigger) + triggerargs, triggercommand = sopel_triggerargs(bot, trigger) if triggerargs == []: return bot.osd("Please present a query to search.") diff --git a/sopel_modules/SpiceBot_GifSearch/gifapi.py b/sopel_modules/SpiceBot_GifSearch/gifapi.py index 36e0b87..cb10755 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifapi.py +++ b/sopel_modules/SpiceBot_GifSearch/gifapi.py @@ -19,16 +19,16 @@ def gifapi_triggers(bot, trigger): while "SpiceBot_GifSearch" not in bot.memory: pass - triggerargs, prefixcommand = sopel_triggerargs(bot, trigger, 'prefix_command') + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') - if prefixcommand not in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): + if triggercommand not in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): return if triggerargs == []: return bot.osd("Please present a query to search.") query = spicemanip.main(triggerargs, 0) - searchdict = {"query": query, "gifsearch": prefixcommand} + searchdict = {"query": query, "gifsearch": triggercommand} gifdict = getGif(bot, searchdict) diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 6922d29..ba7de8e 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -101,7 +101,7 @@ def setup_thread(bot): @sopel.module.commands('gif') def gif_trigger(bot, trigger): - triggerargs = sopel_triggerargs(bot, trigger) + triggerargs, triggercommand = sopel_triggerargs(bot, trigger) if triggerargs == []: return bot.osd("Please present a query to search.") diff --git a/sopel_modules/SpiceBot_Messaging/Messaging.py b/sopel_modules/SpiceBot_Messaging/Messaging.py new file mode 100644 index 0000000..4e44519 --- /dev/null +++ b/sopel_modules/SpiceBot_Messaging/Messaging.py @@ -0,0 +1,52 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module +from sopel.tools import stderr + +import sopel_modules.osd +import spicemanip + +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist + + +def configure(config): + pass + + +def setup(bot): + pass + + +@sopel.module.nickname_commands('action', 'notice', 'privmsg') +def bot_command_hub(bot, trigger): + + if not command_permissions_check(bot, trigger, ['admins', 'owner']): + bot.say("I was unable to process this Bot Nick command due to privilege issues.") + return + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') + + if not len(triggerargs): + bot.say("You must specify a channel.") + return + + channel = spicemanip.main(triggerargs, 1) + if not inlist(bot, channel.lower(), bot.memory['SpiceBot_Channels']['channels'].keys()) and channel != 'all': + bot.osd("Channel name {} not valid.".format(channel)) + return + + triggerargs = spicemanip.main(triggerargs, '2+') + + if channel == 'all': + channelsendlist = bot.channels.keys() + else: + channelsendlist = [channel] + + botmessage = spicemanip.main(triggerargs, 0) + if not botmessage: + bot.say("You must specify a message to send.") + return + + bot.osd(botmessage, channelsendlist, triggercommand.upper()) diff --git a/sopel_modules/SpiceBot_Messaging/__init__.py b/sopel_modules/SpiceBot_Messaging/__init__.py new file mode 100644 index 0000000..bc1e8ca --- /dev/null +++ b/sopel_modules/SpiceBot_Messaging/__init__.py @@ -0,0 +1,8 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function + +from .Messaging import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.0' diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 3596aaa..11cf0e6 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -27,15 +27,48 @@ def sopel_triggerargs(bot, trigger, command_type='module_command'): triggerargs = spicemanip.main(triggerargs, 'create') if command_type in ['module_command']: + command = spicemanip.main(triggerargs, 1).lower() triggerargs = spicemanip.main(triggerargs, '2+', 'list') elif command_type in ['nickname_command']: + command = spicemanip.main(triggerargs, 1).lower()[1:] triggerargs = spicemanip.main(triggerargs, '3+', 'list') elif command_type in ['prefix_command']: - prefixcommand = spicemanip.main(triggerargs, 1).lower()[1:] + command = spicemanip.main(triggerargs, 1).lower()[1:] triggerargs = spicemanip.main(triggerargs, '2+', 'list') - return triggerargs, prefixcommand - return triggerargs + return triggerargs, command + + +def command_permissions_check(bot, trigger, privslist): + + commandrunconsensus = [] + + for botpriv in ["admins", "owner"]: + if botpriv in privslist: + botpriveval = eval("bot.config.core." + botpriv) + if not isinstance(botpriveval, list): + botpriveval = [botpriv] + if not inlist(bot, trigger.nick, botpriveval): + commandrunconsensus.append('False') + else: + commandrunconsensus.append('True') + + if not trigger.is_privmsg: + for chanpriv in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']: + if chanpriv in privslist: + chanpriveval = channel_privs(bot, trigger.sender, chanpriv) + if not inlist(bot, trigger.nick, chanpriveval): + commandrunconsensus.append('False') + else: + commandrunconsensus.append('True') + + if privslist == []: + commandrunconsensus.append('True') + + if 'True' not in commandrunconsensus: + return False + + return True """List Manipulation Functions""" diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index 489d119..29f27c1 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -11,7 +11,7 @@ import sopel_modules.osd import spicemanip -from sopel_modules.SpiceBot_SBTools import service_manip, spicebot_update, sopel_triggerargs +from sopel_modules.SpiceBot_SBTools import service_manip, spicebot_update, sopel_triggerargs, command_permissions_check class SpiceBot_Update_MainSection(StaticSection): @@ -33,7 +33,11 @@ def setup(bot): @sopel.module.nickname_commands('update') def nickname_comand_chanstats(bot, trigger): - triggerargs = sopel_triggerargs(bot, trigger, 'nickname_command') + if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): + bot.say("I was unable to process this Bot Nick command due to privilege issues.") + return + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') if not len(triggerargs): commandused = 'nodeps' @@ -46,9 +50,6 @@ def nickname_comand_chanstats(bot, trigger): triggerargs = spicemanip.main(triggerargs, '2+', 'list') - if not trigger.admin: - bot.say("You are not authorized to perform this function.") - stderr("Recieved Command to update.") bot.osd("Received command from " + trigger.nick + " to update from Github and restart. Be Back Soon!", bot.channels.keys())