From 05821b10feea4ab82c9d7b2a21e61e5ba918f386 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 08:11:11 -0400 Subject: [PATCH 001/127] test url detection --- sopel_modules/SpiceBot_Core_Processing/url.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sopel_modules/SpiceBot_Core_Processing/url.py diff --git a/sopel_modules/SpiceBot_Core_Processing/url.py b/sopel_modules/SpiceBot_Core_Processing/url.py new file mode 100644 index 0000000..2462ba5 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Processing/url.py @@ -0,0 +1,13 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Logs system. +""" +import sopel + + +@sopel.module.url('(.*)') +def watch_url(bot, trigger): + + bot.osd(str(trigger)) + bot.osd(str(trigger.args)) From e32f516ccd67bceb541c07f73204313d98f9ca3e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 08:13:12 -0400 Subject: [PATCH 002/127] import --- sopel_modules/SpiceBot_Core_Processing/{url.py => Watch_URL.py} | 0 sopel_modules/SpiceBot_Core_Processing/__init__.py | 1 + 2 files changed, 1 insertion(+) rename sopel_modules/SpiceBot_Core_Processing/{url.py => Watch_URL.py} (100%) diff --git a/sopel_modules/SpiceBot_Core_Processing/url.py b/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py similarity index 100% rename from sopel_modules/SpiceBot_Core_Processing/url.py rename to sopel_modules/SpiceBot_Core_Processing/Watch_URL.py diff --git a/sopel_modules/SpiceBot_Core_Processing/__init__.py b/sopel_modules/SpiceBot_Core_Processing/__init__.py index 06d806d..68e839b 100644 --- a/sopel_modules/SpiceBot_Core_Processing/__init__.py +++ b/sopel_modules/SpiceBot_Core_Processing/__init__.py @@ -15,6 +15,7 @@ from .osd import * from .StartupMonologue import * from .Logs import * from .Kick import * +from .Watch_URL import * __author__ = 'Sam Zick' From b205fab105301f1c7648a75d62951cfffd6aabec Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 08:15:53 -0400 Subject: [PATCH 003/127] test --- sopel_modules/SpiceBot_Core_Processing/Watch_URL.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py b/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py index 2462ba5..0800d00 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py +++ b/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py @@ -1,12 +1,11 @@ # coding=utf8 from __future__ import unicode_literals, absolute_import, division, print_function -""" -This is the SpiceBot Logs system. -""" + import sopel -@sopel.module.url('(.*)') +# @sopel.module.url('(.*)') +@sopel.module.url(r'xkcd.com/(\d+)') def watch_url(bot, trigger): bot.osd(str(trigger)) From 61e28a996fa812efc617aede097160960e7a5468 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 08:18:21 -0400 Subject: [PATCH 004/127] test --- sopel_modules/SpiceBot_Core_Processing/Watch_URL.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py b/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py index 0800d00..53f777f 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py +++ b/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py @@ -5,7 +5,8 @@ import sopel # @sopel.module.url('(.*)') -@sopel.module.url(r'xkcd.com/(\d+)') +# @sopel.module.url(r'xkcd.com/(\d+)') +@sopel.module.rule(r'(?u).*(https?://\S+).*') def watch_url(bot, trigger): bot.osd(str(trigger)) From a50322c715c81007f3c52435f168b207c71709d1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 08:29:25 -0400 Subject: [PATCH 005/127] test over --- .../SpiceBot_Core_Processing/{Watch_URL.py => Watch_URL} | 0 sopel_modules/SpiceBot_Core_Processing/__init__.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename sopel_modules/SpiceBot_Core_Processing/{Watch_URL.py => Watch_URL} (100%) diff --git a/sopel_modules/SpiceBot_Core_Processing/Watch_URL.py b/sopel_modules/SpiceBot_Core_Processing/Watch_URL similarity index 100% rename from sopel_modules/SpiceBot_Core_Processing/Watch_URL.py rename to sopel_modules/SpiceBot_Core_Processing/Watch_URL diff --git a/sopel_modules/SpiceBot_Core_Processing/__init__.py b/sopel_modules/SpiceBot_Core_Processing/__init__.py index 68e839b..95788bd 100644 --- a/sopel_modules/SpiceBot_Core_Processing/__init__.py +++ b/sopel_modules/SpiceBot_Core_Processing/__init__.py @@ -15,7 +15,7 @@ from .osd import * from .StartupMonologue import * from .Logs import * from .Kick import * -from .Watch_URL import * +# from .Watch_URL import * __author__ = 'Sam Zick' From 3b4943dd1e63004b006b2aca88b603e9ec9b054d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 08:34:14 -0400 Subject: [PATCH 006/127] dict update --- sopel_modules/SpiceBot/Google.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Google.py b/sopel_modules/SpiceBot/Google.py index 2afb29b..044344b 100644 --- a/sopel_modules/SpiceBot/Google.py +++ b/sopel_modules/SpiceBot/Google.py @@ -23,7 +23,8 @@ class Google(): self.setup_google() self.cache = { "info": {}, - "maps": {} + "maps": {}, + "youtube": {} } def setup_google(self): From 37914e1f1c6986b78b2ba75a576b19f75f440016 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:11:56 -0400 Subject: [PATCH 007/127] start of reddit testing --- sopel_modules/SpiceBot/Reddit.py | 14 ++++++++++ sopel_modules/SpiceBot/__init__.py | 1 + .../SpiceBot_Core_Commands/Reddit.py | 27 +++++++++++++++++++ .../SpiceBot_Core_Commands/__init__.py | 1 + 4 files changed, 43 insertions(+) create mode 100644 sopel_modules/SpiceBot/Reddit.py create mode 100644 sopel_modules/SpiceBot_Core_Commands/Reddit.py diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py new file mode 100644 index 0000000..1cf973d --- /dev/null +++ b/sopel_modules/SpiceBot/Reddit.py @@ -0,0 +1,14 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Reddit system. +""" + + +class BotReddit(): + """This Logs all channels known to the server""" + def __init__(self): + self.dict = {} + + +reddit = BotReddit() diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index 90787d3..fac2d5c 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -25,6 +25,7 @@ from .AI import * from .Google import * from .Gif import * from .Sherlock import * +from .Reddit import * from .configure import * diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py new file mode 100644 index 0000000..b442915 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -0,0 +1,27 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +# import sopel_modules.SpiceBot as SpiceBot + + +@sopel.module.rule(r"""(?:)u/ + ( + (?:\\/ | [^/])+ + ) + """) +def bot_command_reddit_user(bot, trigger): + bot.osd(str(trigger)) + bot.osd(str(trigger.args)) + + +@sopel.module.rule(r"""(?:)r/ + ( + (?:\\/ | [^/])+ + ) + """) +def bot_command_reddit_subreddit(bot, trigger): + bot.osd(str(trigger)) + bot.osd(str(trigger.args)) diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index cf853c4..6ec62d5 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -20,6 +20,7 @@ from .Search import * from .AI import * from .Gif import * from .Sherlock import * +from .Reddit import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 81867f24ee41be20cf80f924b9e0c40f863ff58d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:17:26 -0400 Subject: [PATCH 008/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index b442915..299111d 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -7,21 +7,13 @@ import sopel.module # import sopel_modules.SpiceBot as SpiceBot -@sopel.module.rule(r"""(?:)u/ - ( - (?:\\/ | [^/])+ - ) - """) +@sopel.module.rule(r"""(?:)u/((?:\\/ | [^/])+)""") def bot_command_reddit_user(bot, trigger): bot.osd(str(trigger)) bot.osd(str(trigger.args)) -@sopel.module.rule(r"""(?:)r/ - ( - (?:\\/ | [^/])+ - ) - """) +@sopel.module.rule(r"""(?:)r/((?:\\/ | [^/])+)""") def bot_command_reddit_subreddit(bot, trigger): bot.osd(str(trigger)) bot.osd(str(trigger.args)) From 2c49caeea1d6531770993d18e9ad01ca29309d8d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:25:29 -0400 Subject: [PATCH 009/127] error handling --- sopel_modules/SpiceBot/Commands.py | 49 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index b351d11..c746c1e 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -222,31 +222,36 @@ class BotCommands(): filelinelist = [] currentsuccesslines = 0 for detected_line in detected_lines: + try: - # Commands - if str(detected_line).startswith("commands"): - comtype = "module" - validcoms = eval(str(detected_line).split("commands")[-1]) - elif str(detected_line).startswith("nickname_commands"): - comtype = "nickname" - validcoms = eval(str(detected_line).split("nickname_commands")[-1]) - elif str(detected_line).startswith("rule"): - comtype = "rule" - validcoms = eval(str(detected_line).split("rule")[-1]) + # Commands + if str(detected_line).startswith("commands"): + comtype = "module" + validcoms = eval(str(detected_line).split("commands")[-1]) + elif str(detected_line).startswith("nickname_commands"): + comtype = "nickname" + validcoms = eval(str(detected_line).split("nickname_commands")[-1]) + elif str(detected_line).startswith("rule"): + comtype = "rule" + validcoms = eval(str(detected_line).split("rule")[-1]) - if isinstance(validcoms, tuple): - validcoms = list(validcoms) - else: - validcoms = [validcoms] - for regexcom in ["(.*)", '^\?(.*)']: - if regexcom in validcoms: - while regexcom in validcoms: - validcoms.remove(regexcom) + if isinstance(validcoms, tuple): + validcoms = list(validcoms) + else: + validcoms = [validcoms] + for regexcom in ["(.*)", '^\?(.*)']: + if regexcom in validcoms: + while regexcom in validcoms: + validcoms.remove(regexcom) - if len(validcoms): - validcomdict = {"comtype": comtype, "validcoms": validcoms} - filelinelist.append(validcomdict) - currentsuccesslines += 1 + if len(validcoms): + validcomdict = {"comtype": comtype, "validcoms": validcoms} + filelinelist.append(validcomdict) + currentsuccesslines += 1 + except Exception as e: + addnothing = e + if addnothing: + currentsuccesslines += 0 if currentsuccesslines: self.dict['counts'] += 1 From 2268fde4adb989e38aabf0d16fc25d41ca12aa5d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:26:00 -0400 Subject: [PATCH 010/127] revert """ changes --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 299111d..b442915 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -7,13 +7,21 @@ import sopel.module # import sopel_modules.SpiceBot as SpiceBot -@sopel.module.rule(r"""(?:)u/((?:\\/ | [^/])+)""") +@sopel.module.rule(r"""(?:)u/ + ( + (?:\\/ | [^/])+ + ) + """) def bot_command_reddit_user(bot, trigger): bot.osd(str(trigger)) bot.osd(str(trigger.args)) -@sopel.module.rule(r"""(?:)r/((?:\\/ | [^/])+)""") +@sopel.module.rule(r"""(?:)r/ + ( + (?:\\/ | [^/])+ + ) + """) def bot_command_reddit_subreddit(bot, trigger): bot.osd(str(trigger)) bot.osd(str(trigger.args)) From 13b59336a2dc6a5026dd0f935f181ece145a82bb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:34:30 -0400 Subject: [PATCH 011/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index b442915..b5dd8a6 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -4,6 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module +import spicemanip + # import sopel_modules.SpiceBot as SpiceBot @@ -13,8 +15,8 @@ import sopel.module ) """) def bot_command_reddit_user(bot, trigger): - bot.osd(str(trigger)) - bot.osd(str(trigger.args)) + trigger_command = spicemanip.main(trigger.args[1], 1).lower()[0:] + bot.osd(str(trigger_command)) @sopel.module.rule(r"""(?:)r/ From 125507f663c76deaed44149899606a67014e60bb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:35:38 -0400 Subject: [PATCH 012/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index b5dd8a6..7a3c6da 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -15,7 +15,7 @@ import spicemanip ) """) def bot_command_reddit_user(bot, trigger): - trigger_command = spicemanip.main(trigger.args[1], 1).lower()[0:] + trigger_command = spicemanip.main(trigger.args[1], 1).lower()[:1] bot.osd(str(trigger_command)) From 7c5ea79f99dd429f4eedfb4472cbf70585f5f147 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:37:14 -0400 Subject: [PATCH 013/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 7a3c6da..02db5b2 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -16,7 +16,9 @@ import spicemanip """) def bot_command_reddit_user(bot, trigger): trigger_command = spicemanip.main(trigger.args[1], 1).lower()[:1] + trigger_arg = spicemanip.main(trigger.args[1], 1).lower()[1:] bot.osd(str(trigger_command)) + bot.osd(str(trigger_arg)) @sopel.module.rule(r"""(?:)r/ From a6f95521601658a34433f8f119693ce0cffbf37a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:42:01 -0400 Subject: [PATCH 014/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 02db5b2..b3b9649 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -15,10 +15,8 @@ import spicemanip ) """) def bot_command_reddit_user(bot, trigger): - trigger_command = spicemanip.main(trigger.args[1], 1).lower()[:1] - trigger_arg = spicemanip.main(trigger.args[1], 1).lower()[1:] - bot.osd(str(trigger_command)) - bot.osd(str(trigger_arg)) + trigger = reddit_prerun(trigger) + bot.osd(str(trigger.sb)) @sopel.module.rule(r"""(?:)r/ @@ -27,5 +25,13 @@ def bot_command_reddit_user(bot, trigger): ) """) def bot_command_reddit_subreddit(bot, trigger): - bot.osd(str(trigger)) - bot.osd(str(trigger.args)) + trigger = reddit_prerun(trigger) + bot.osd(str(trigger.sb)) + + +def reddit_prerun(trigger): + trigger.sb = { + "command": spicemanip.main(trigger.args[1], 1).lower()[:1], + "args": spicemanip.main(trigger.args[1], 1).lower()[2:] + } + return trigger From 790b3ee7fc70aa9893a7fa26fb56f17c2a60bf0a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:43:46 -0400 Subject: [PATCH 015/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index b3b9649..c31197f 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -31,7 +31,8 @@ def bot_command_reddit_subreddit(bot, trigger): def reddit_prerun(trigger): trigger.sb = { - "command": spicemanip.main(trigger.args[1], 1).lower()[:1], - "args": spicemanip.main(trigger.args[1], 1).lower()[2:] + "slashcomm": spicemanip.main(trigger.args[1], 1).lower()[:1], + "command": spicemanip.main(trigger.args[1], 1).lower()[2:], + "args": spicemanip.main(trigger.args[1], "2+", 'list').lower() } return trigger From 415b88f58ff2422fc4796299b3430419b2f9f700 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:46:28 -0400 Subject: [PATCH 016/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index c31197f..9744c04 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -30,9 +30,10 @@ def bot_command_reddit_subreddit(bot, trigger): def reddit_prerun(trigger): + trigger_args = spicemanip.main(trigger.args[1], 'create') trigger.sb = { - "slashcomm": spicemanip.main(trigger.args[1], 1).lower()[:1], - "command": spicemanip.main(trigger.args[1], 1).lower()[2:], - "args": spicemanip.main(trigger.args[1], "2+", 'list').lower() + "slashcomm": spicemanip.main(trigger_args, 1).lower()[:1], + "command": spicemanip.main(trigger_args, 1).lower()[2:], + "args": spicemanip.main(trigger_args, "2+", 'list').lower() } return trigger From 5bc92177614ae680dde45c91858b428962cf0a78 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:48:25 -0400 Subject: [PATCH 017/127] oops --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 9744c04..5bdc257 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -34,6 +34,6 @@ def reddit_prerun(trigger): trigger.sb = { "slashcomm": spicemanip.main(trigger_args, 1).lower()[:1], "command": spicemanip.main(trigger_args, 1).lower()[2:], - "args": spicemanip.main(trigger_args, "2+", 'list').lower() + "args": spicemanip.main(trigger_args, "2+", 'list') } return trigger From cb0503e2c9104af3c6529d677d77c4768644e074 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:52:42 -0400 Subject: [PATCH 018/127] test --- sopel_modules/SpiceBot/Reddit.py | 11 +++++++++++ sopel_modules/SpiceBot_Core_Commands/Reddit.py | 18 +++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index 1cf973d..363ce3a 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -4,11 +4,22 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot Reddit system. """ +import spicemanip + class BotReddit(): """This Logs all channels known to the server""" def __init__(self): self.dict = {} + def prerun(self, trigger): + trigger_args = spicemanip.main(trigger.args[1], 'create') + trigger.sb = { + "slashcomm": spicemanip.main(trigger_args, 1).lower()[:1], + "command": spicemanip.main(trigger_args, 1).lower()[2:], + "args": spicemanip.main(trigger_args, "2+", 'list') + } + return trigger + reddit = BotReddit() diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 5bdc257..23e8410 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -4,9 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import spicemanip - -# import sopel_modules.SpiceBot as SpiceBot +import sopel_modules.SpiceBot as SpiceBot @sopel.module.rule(r"""(?:)u/ @@ -15,7 +13,7 @@ import spicemanip ) """) def bot_command_reddit_user(bot, trigger): - trigger = reddit_prerun(trigger) + trigger = SpiceBot.reddit.reddit_prerun(trigger) bot.osd(str(trigger.sb)) @@ -25,15 +23,5 @@ def bot_command_reddit_user(bot, trigger): ) """) def bot_command_reddit_subreddit(bot, trigger): - trigger = reddit_prerun(trigger) + trigger = SpiceBot.reddit.reddit_prerun(trigger) bot.osd(str(trigger.sb)) - - -def reddit_prerun(trigger): - trigger_args = spicemanip.main(trigger.args[1], 'create') - trigger.sb = { - "slashcomm": spicemanip.main(trigger_args, 1).lower()[:1], - "command": spicemanip.main(trigger_args, 1).lower()[2:], - "args": spicemanip.main(trigger_args, "2+", 'list') - } - return trigger From 3b102c51866382f109d421105f255dfbc840e1c5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 09:53:01 -0400 Subject: [PATCH 019/127] quick patch --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 23e8410..067af00 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_user(bot, trigger): - trigger = SpiceBot.reddit.reddit_prerun(trigger) + trigger = SpiceBot.reddit.prerun(trigger) bot.osd(str(trigger.sb)) @@ -23,5 +23,5 @@ def bot_command_reddit_user(bot, trigger): ) """) def bot_command_reddit_subreddit(bot, trigger): - trigger = SpiceBot.reddit.reddit_prerun(trigger) + trigger = SpiceBot.reddit.prerun(trigger) bot.osd(str(trigger.sb)) From 1258fb38b90b655955da8c3e58ce3170e5df1aca Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 10:10:31 -0400 Subject: [PATCH 020/127] test --- sopel_modules/SpiceBot/Reddit.py | 29 +++++++++++++++++-- .../SpiceBot_Core_Commands/Reddit.py | 8 ++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index 363ce3a..70b4e74 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -6,20 +6,45 @@ This is the SpiceBot Reddit system. import spicemanip +import requests +from fake_useragent import UserAgent + class BotReddit(): """This Logs all channels known to the server""" def __init__(self): self.dict = {} + self.header = {'User-Agent': str(UserAgent().chrome)} def prerun(self, trigger): + # trigger_argsdict = self.trigger_handler(trigger) + page = self.check_reddit_up() + if not page: + message = "Reddit Appears to be down" + return message + elif str(page.status_code).startswith(tuple(["4", "5"])): + message = "Reddit is replying with http code " + str(page.status_code) + return message + + message = "Reddit is replying with http code " + str(page.status_code) + return message + + def trigger_handler(self, trigger): trigger_args = spicemanip.main(trigger.args[1], 'create') - trigger.sb = { + trigger_argsdict = { "slashcomm": spicemanip.main(trigger_args, 1).lower()[:1], "command": spicemanip.main(trigger_args, 1).lower()[2:], "args": spicemanip.main(trigger_args, "2+", 'list') } - return trigger + return trigger_argsdict + + def check_reddit_up(self): + try: + page = requests.get("https://www.reddit.com/", headers=self.header) + except Exception as e: + page = e + page = None + return page reddit = BotReddit() diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 067af00..f9cc588 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -13,8 +13,8 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_user(bot, trigger): - trigger = SpiceBot.reddit.prerun(trigger) - bot.osd(str(trigger.sb)) + message = SpiceBot.reddit.prerun(trigger) + bot.osd(str(message)) @sopel.module.rule(r"""(?:)r/ @@ -23,5 +23,5 @@ def bot_command_reddit_user(bot, trigger): ) """) def bot_command_reddit_subreddit(bot, trigger): - trigger = SpiceBot.reddit.prerun(trigger) - bot.osd(str(trigger.sb)) + message = SpiceBot.reddit.prerun(trigger) + bot.osd(str(message)) From e75a08f46abcf6e242584cc078b53db44e89d451 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 10:48:22 -0400 Subject: [PATCH 021/127] test reddit praw --- sopel_modules/SpiceBot/Reddit.py | 159 +++++++++++++++++++++++++++- sopel_modules/SpiceBot/configure.py | 5 + sopel_modules/SpiceBot/setup.py | 7 ++ 3 files changed, 168 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index 70b4e74..66c99f0 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -4,20 +4,52 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot Reddit system. """ +from sopel.config.types import StaticSection, ValidatedAttribute + import spicemanip import requests +# from lxml import html from fake_useragent import UserAgent +import praw +from prawcore import NotFound +from random import randint + +from .Config import config as botconfig +from .Logs import logs + + +class SpiceBot_Reddit_MainSection(StaticSection): + client_id = ValidatedAttribute('client_id', default=None) + client_secret = ValidatedAttribute('client_secret', default=None) class BotReddit(): """This Logs all channels known to the server""" def __init__(self): + self.setup_commands() self.dict = {} self.header = {'User-Agent': str(UserAgent().chrome)} + self.client_id = botconfig.SpiceBot_Reddit.client_id + self.client_secret = botconfig.SpiceBot_Reddit.client_secret + if not self.client_id or not self.client_secret: + self.praw = None + logs.log('SpiceBot_Reddit', "Error loading reddit auth", True) + else: + self.praw = praw.Reddit( + client_id=self.client_id, + client_secret=self.client_secret, + user_agent='spicebot:net.example.myredditapp:v1.2.3 (by /u/SpiceBot-dbb)' + ) + + def setup_commands(self): + botconfig.define_section("SpiceBot_Reddit", SpiceBot_Reddit_MainSection, validate=False) def prerun(self, trigger): - # trigger_argsdict = self.trigger_handler(trigger) + if not self.praw: + return "Reddit API is not available" + message = "if you see this, there may be an error" + trigger_argsdict = self.trigger_handler(trigger) page = self.check_reddit_up() if not page: message = "Reddit Appears to be down" @@ -25,10 +57,90 @@ class BotReddit(): elif str(page.status_code).startswith(tuple(["4", "5"])): message = "Reddit is replying with http code " + str(page.status_code) return message - - message = "Reddit is replying with http code " + str(page.status_code) + if trigger_argsdict["slashcomm"] == "u": + return self.user_handler(trigger_argsdict) + elif trigger_argsdict["slashcomm"] == "r": + return self.subreddit_handler(trigger_argsdict) return message + def user_handler(self, trigger_argsdict): + subcommand_valid = ['check'] + subcommand = spicemanip.main([x for x in trigger_argsdict["args"] if x in subcommand_valid], 1) or 'check' + + userreal = self.reddit_user_exists(trigger_argsdict["command"]) + if not userreal["exists"]: + return userreal["error"] + + fulluurul = str("https://www.reddit.com/" + trigger_argsdict["slashcomm"] + "/" + trigger_argsdict["command"]) + if subcommand == 'check': + return [trigger_argsdict["command"] + " appears to be a valid reddit " + trigger_argsdict["urltypetxt"] + "!", fulluurul] + + def subreddit_handler(self, trigger_argsdict): + subcommand_valid = ['check', 'hot', 'new', 'top', 'random', 'controversial', 'gilded', 'rising', 'best'] + subcommand = spicemanip.main([x for x in trigger_argsdict["args"] if x in subcommand_valid], 1) or 'check' + + fullrurul = str("https://www.reddit.com/" + trigger_argsdict["slashcomm"] + "/" + trigger_argsdict["command"]) + + subredditcheck = self.reddit_subreddit_check(trigger_argsdict["command"]) + if not subredditcheck["exists"]: + return subredditcheck["error"] + + subreddit = self.praw.subreddit(trigger_argsdict["command"]) + if subcommand == 'check': + dispmsg = [] + dispmsg.append("[Reddit " + trigger_argsdict["slashcomm"] + "/" + trigger_argsdict["command"] + "]") + if subreddit.over18: + dispmsg.append("") + dispmsg.append(str(subreddit.public_description)) + dispmsg.append(fullrurul) + return dispmsg + + if subcommand == 'random': + targnum = spicemanip.main([x for x in trigger_argsdict["args"] if str(x).isdigit()], 1) or 500 + else: + targnum = spicemanip.main([x for x in trigger_argsdict["args"] if str(x).isdigit()], 1) or 1 + targnum = int(targnum) + + if subcommand == 'new': + submissions = subreddit.new(limit=targnum) + elif subcommand == 'top': + submissions = subreddit.top(limit=targnum) + elif subcommand == 'hot': + submissions = subreddit.hot(limit=targnum) + elif subcommand == 'controversial': + submissions = subreddit.controversial(limit=targnum) + elif subcommand == 'gilded': + submissions = subreddit.gilded(limit=targnum) + elif subcommand == 'rising': + submissions = subreddit.rising(limit=targnum) + elif subcommand == 'random': + submissions = subreddit.hot(limit=targnum) + else: + return "An error has occured." + + listarray = [] + for submission in submissions: + listarray.append(submission) + + if listarray == []: + submission = None + elif subcommand == 'random': + submission = listarray[randint(0, len(listarray) - 1)] + else: + submission = listarray[targnum - 1] + + dispmsg = [] + dispmsg.append("[Reddit " + trigger_argsdict["slashcomm"] + "/" + trigger_argsdict["command"] + " " + subcommand + "]") + if subreddit.over18: + dispmsg.append("") + if submission: + dispmsg.append("{" + str(submission.score) + "}") + dispmsg.append(submission.title) + dispmsg.append(submission.url) + else: + dispmsg.append("No Content Found.") + return dispmsg + def trigger_handler(self, trigger): trigger_args = spicemanip.main(trigger.args[1], 'create') trigger_argsdict = { @@ -36,6 +148,11 @@ class BotReddit(): "command": spicemanip.main(trigger_args, 1).lower()[2:], "args": spicemanip.main(trigger_args, "2+", 'list') } + if trigger_argsdict["slashcomm"] == "u": + trigger_argsdict["urltypetxt"] = "user" + if trigger_argsdict["slashcomm"] == "r": + trigger_argsdict["urltypetxt"] = "subreddit" + return trigger_argsdict def check_reddit_up(self): @@ -46,5 +163,41 @@ class BotReddit(): page = None return page + def reddit_subreddit_check(self, sub): + returndict = {"exists": True, "error": None} + try: + self.praw.subreddits.search_by_name(sub, exact=True) + except NotFound: + returndict["error"] = str(sub + " appears to not exist!") + returndict["exists"] = False + return returndict + + try: + subtype = self.praw.subreddit(sub).subreddit_type + except Exception as e: + returndict["exists"] = False + if str(e) == "received 403 HTTP response": + returndict["error"] = str(sub + " appears to be an private subreddit!") + return returndict + elif str(e) == "received 404 HTTP response": + returndict["error"] = str(sub + " appears to be an banned subreddit!") + return returndict + else: + returndict["error"] = str(sub + " appears to not have a type") + return returndict + return subtype + + return returndict + + def reddit_user_exists(self, user): + returndict = {"exists": True, "error": None} + try: + self.praw.redditor(user).fullname + except NotFound: + returndict["exists"] = False + returndict["error"] = str(user + " appears to not exist!") + return returndict + return returndict + reddit = BotReddit() diff --git a/sopel_modules/SpiceBot/configure.py b/sopel_modules/SpiceBot/configure.py index d666b58..2c317c6 100644 --- a/sopel_modules/SpiceBot/configure.py +++ b/sopel_modules/SpiceBot/configure.py @@ -8,6 +8,7 @@ from .Google import SpiceBot_Google_MainSection from .AI import SpiceBot_AI_MainSection from .Update import SpiceBot_Update_MainSection from .Gif import SpiceBot_Gif_MainSection +from .Reddit import SpiceBot_Reddit_MainSection from .Kick import SpiceBot_Kick from .osd import SpiceBot_OSD @@ -49,3 +50,7 @@ def configure(config): config.define_section("SpiceBot_Gif", SpiceBot_Gif_MainSection, validate=False) config.SopelGifSearch.configure_setting('extra', 'SpiceBot_Gif API Extra directory') config.SopelGifSearch.configure_setting('nsfw', 'SpiceBot_Gif API nsfw content') + + config.define_section("SpiceBot_Reddit", SpiceBot_Reddit_MainSection, validate=False) + config.SopelGifSearch.configure_setting('client_id', 'SpiceBot_Reddit client_id') + config.SopelGifSearch.configure_setting('client_secret', 'SpiceBot_Reddit client_secret') diff --git a/sopel_modules/SpiceBot/setup.py b/sopel_modules/SpiceBot/setup.py index e440b4d..afab024 100644 --- a/sopel_modules/SpiceBot/setup.py +++ b/sopel_modules/SpiceBot/setup.py @@ -15,6 +15,7 @@ from .Channels import SpiceBot_Channels_MainSection from .Commands import SpiceBot_Commands_MainSection from .Google import SpiceBot_Google_MainSection from .Update import SpiceBot_Update_MainSection +from .Reddit import SpiceBot_Reddit_MainSection from .osd import SopelWrapperOSD, ToolsOSD, SopelOSD, SpiceBot_OSD from .Kick import SopelWrapperKICK, SopelKICK, SpiceBot_Kick from .Gif import SpiceBot_Gif_MainSection @@ -55,6 +56,8 @@ def setup(bot): setup_gif(bot) + setup_reddit(bot) + def setup_config(bot): logs.log('SpiceBot_Config', "Setting Up Configuration") @@ -145,3 +148,7 @@ def setup_kick(bot): def setup_gif(bot): bot.config.define_section("SopelGifSearch", SpiceBot_Gif_MainSection, validate=False) + + +def setup_reddit(bot): + bot.config.define_section("SpiceBot_Reddit", SpiceBot_Reddit_MainSection, validate=False) From 63a02dfcc615bfb58f39eea0732eba8f0a2cd686 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 10:53:45 -0400 Subject: [PATCH 022/127] update message --- sopel_modules/SpiceBot/Reddit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index 66c99f0..55f0cd2 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -27,14 +27,14 @@ class SpiceBot_Reddit_MainSection(StaticSection): class BotReddit(): """This Logs all channels known to the server""" def __init__(self): - self.setup_commands() + self.setup_reddit() self.dict = {} self.header = {'User-Agent': str(UserAgent().chrome)} self.client_id = botconfig.SpiceBot_Reddit.client_id self.client_secret = botconfig.SpiceBot_Reddit.client_secret if not self.client_id or not self.client_secret: self.praw = None - logs.log('SpiceBot_Reddit', "Error loading reddit auth", True) + logs.log('SpiceBot_Reddit', "Client ID or Secret missing from config", True) else: self.praw = praw.Reddit( client_id=self.client_id, @@ -42,7 +42,7 @@ class BotReddit(): user_agent='spicebot:net.example.myredditapp:v1.2.3 (by /u/SpiceBot-dbb)' ) - def setup_commands(self): + def setup_reddit(self): botconfig.define_section("SpiceBot_Reddit", SpiceBot_Reddit_MainSection, validate=False) def prerun(self, trigger): From 9dd2503900c88f74791aedf7ebba8a2fa4f27dc7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 10:59:41 -0400 Subject: [PATCH 023/127] test --- sopel_modules/SpiceBot/Reddit.py | 5 ++--- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 7 +------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index 55f0cd2..522303f 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -28,7 +28,7 @@ class BotReddit(): """This Logs all channels known to the server""" def __init__(self): self.setup_reddit() - self.dict = {} + self.cache = {} self.header = {'User-Agent': str(UserAgent().chrome)} self.client_id = botconfig.SpiceBot_Reddit.client_id self.client_secret = botconfig.SpiceBot_Reddit.client_secret @@ -174,6 +174,7 @@ class BotReddit(): try: subtype = self.praw.subreddit(sub).subreddit_type + returndict["subtype"] = subtype except Exception as e: returndict["exists"] = False if str(e) == "received 403 HTTP response": @@ -185,8 +186,6 @@ class BotReddit(): else: returndict["error"] = str(sub + " appears to not have a type") return returndict - return subtype - return returndict def reddit_user_exists(self, user): diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index f9cc588..f6d54cd 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -12,16 +12,11 @@ import sopel_modules.SpiceBot as SpiceBot (?:\\/ | [^/])+ ) """) -def bot_command_reddit_user(bot, trigger): - message = SpiceBot.reddit.prerun(trigger) - bot.osd(str(message)) - - @sopel.module.rule(r"""(?:)r/ ( (?:\\/ | [^/])+ ) """) -def bot_command_reddit_subreddit(bot, trigger): +def bot_command_reddit_user(bot, trigger): message = SpiceBot.reddit.prerun(trigger) bot.osd(str(message)) From 4502153e106adc703af04057853493568296e049 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 11:08:27 -0400 Subject: [PATCH 024/127] test trigger.group --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index f6d54cd..efa37be 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -18,5 +18,11 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_user(bot, trigger): + bot.say(str(trigger.group(0))) + bot.say(str(trigger.group(1))) + bot.say(str(trigger.group(2))) + bot.say(str(trigger.group(3))) + bot.say(str(trigger.group(4))) + bot.say(str(trigger.group(5))) message = SpiceBot.reddit.prerun(trigger) bot.osd(str(message)) From 15fed55dbe534cb20a0aed4cf92590e0bfefcab8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 11:10:14 -0400 Subject: [PATCH 025/127] revert --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index efa37be..f6d54cd 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -18,11 +18,5 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_user(bot, trigger): - bot.say(str(trigger.group(0))) - bot.say(str(trigger.group(1))) - bot.say(str(trigger.group(2))) - bot.say(str(trigger.group(3))) - bot.say(str(trigger.group(4))) - bot.say(str(trigger.group(5))) message = SpiceBot.reddit.prerun(trigger) bot.osd(str(message)) From 18afa59314aa09ee2622e1299b0672eb7aa62a6b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 11:14:25 -0400 Subject: [PATCH 026/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index f6d54cd..72cf8eb 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -18,5 +18,7 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_user(bot, trigger): + inputs = list(trigger.group(1).split(" "))[0] + bot.say(str(inputs)) message = SpiceBot.reddit.prerun(trigger) bot.osd(str(message)) From bae909272588ba1cbe44be368b413a10450c0235 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 11:15:25 -0400 Subject: [PATCH 027/127] revert test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 72cf8eb..f6d54cd 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -18,7 +18,5 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_user(bot, trigger): - inputs = list(trigger.group(1).split(" "))[0] - bot.say(str(inputs)) message = SpiceBot.reddit.prerun(trigger) bot.osd(str(message)) From ebc0b1756ad2981e2c444d6f7fe8408ddbd8e23f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 11:17:23 -0400 Subject: [PATCH 028/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index f6d54cd..53270a2 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -18,5 +18,6 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_user(bot, trigger): + bot.say(str(trigger.group(2))) message = SpiceBot.reddit.prerun(trigger) bot.osd(str(message)) From e055f0652d03f98c26ccd291202c85f36c61636c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 11:22:13 -0400 Subject: [PATCH 029/127] test --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 53270a2..8c84257 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -17,7 +17,7 @@ import sopel_modules.SpiceBot as SpiceBot (?:\\/ | [^/])+ ) """) -def bot_command_reddit_user(bot, trigger): - bot.say(str(trigger.group(2))) +def bot_command_reddit_syntax(bot, trigger): + bot.say(str(trigger.group(1).split(' ', 1))) message = SpiceBot.reddit.prerun(trigger) bot.osd(str(message)) From cea4fb555b361f1d5b4e721adacb7d59f31f0b2e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 11:24:00 -0400 Subject: [PATCH 030/127] fix --- sopel_modules/SpiceBot_Core_Commands/Reddit.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Commands/Reddit.py index 8c84257..785e2b5 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Commands/Reddit.py @@ -18,6 +18,5 @@ import sopel_modules.SpiceBot as SpiceBot ) """) def bot_command_reddit_syntax(bot, trigger): - bot.say(str(trigger.group(1).split(' ', 1))) message = SpiceBot.reddit.prerun(trigger) - bot.osd(str(message)) + bot.osd(message) From b29dc97429697c72b38cee48d0bcdcbb5c00e605 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 13:22:43 -0400 Subject: [PATCH 031/127] user info --- sopel_modules/SpiceBot/Reddit.py | 58 +++++++++++++++++++------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index 522303f..ee439d1 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -5,14 +5,13 @@ This is the SpiceBot Reddit system. """ from sopel.config.types import StaticSection, ValidatedAttribute +from sopel.formatting import bold, color, colors import spicemanip -import requests -# from lxml import html -from fake_useragent import UserAgent +import datetime as dt import praw -from prawcore import NotFound +import prawcore from random import randint from .Config import config as botconfig @@ -29,7 +28,6 @@ class BotReddit(): def __init__(self): self.setup_reddit() self.cache = {} - self.header = {'User-Agent': str(UserAgent().chrome)} self.client_id = botconfig.SpiceBot_Reddit.client_id self.client_secret = botconfig.SpiceBot_Reddit.client_secret if not self.client_id or not self.client_secret: @@ -50,13 +48,6 @@ class BotReddit(): return "Reddit API is not available" message = "if you see this, there may be an error" trigger_argsdict = self.trigger_handler(trigger) - page = self.check_reddit_up() - if not page: - message = "Reddit Appears to be down" - return message - elif str(page.status_code).startswith(tuple(["4", "5"])): - message = "Reddit is replying with http code " + str(page.status_code) - return message if trigger_argsdict["slashcomm"] == "u": return self.user_handler(trigger_argsdict) elif trigger_argsdict["slashcomm"] == "r": @@ -73,7 +64,36 @@ class BotReddit(): fulluurul = str("https://www.reddit.com/" + trigger_argsdict["slashcomm"] + "/" + trigger_argsdict["command"]) if subcommand == 'check': - return [trigger_argsdict["command"] + " appears to be a valid reddit " + trigger_argsdict["urltypetxt"] + "!", fulluurul] + u = self.praw.redditor(trigger_argsdict["command"]) + message = ['[REDDITOR] ' + u.name] + is_cakeday = self.user_cakeday(u.created_utc) + if is_cakeday: + message.append(bold(color('Cake day', colors.LIGHT_PURPLE))) + message.append(fulluurul) + if u.is_gold: + message.append(bold(color('Gold', colors.YELLOW))) + if u.is_mod: + message.append(bold(color('Mod', colors.GREEN))) + message.append('Link: ' + str(u.link_karma)) + message.append('Comment: ' + str(u.comment_karma)) + return message + + def user_cakeday(self, created): + now = dt.datetime.utcnow() + cakeday_start = dt.datetime.utcfromtimestamp(created) + cakeday_start = cakeday_start.replace(year=now.year) + day = dt.timedelta(days=1) + year_div_by_400 = now.year % 400 == 0 + year_div_by_100 = now.year % 100 == 0 + year_div_by_4 = now.year % 4 == 0 + is_leap = year_div_by_400 or ((not year_div_by_100) and year_div_by_4) + if (not is_leap) and ((cakeday_start.month, cakeday_start.day) == (2, 29)): + # If cake day is 2/29 and it's not a leap year, cake day is 3/1. + # Cake day begins at exact account creation time. + is_cakeday = cakeday_start + day <= now <= cakeday_start + (2 * day) + else: + is_cakeday = cakeday_start <= now <= cakeday_start + day + return is_cakeday def subreddit_handler(self, trigger_argsdict): subcommand_valid = ['check', 'hot', 'new', 'top', 'random', 'controversial', 'gilded', 'rising', 'best'] @@ -155,19 +175,11 @@ class BotReddit(): return trigger_argsdict - def check_reddit_up(self): - try: - page = requests.get("https://www.reddit.com/", headers=self.header) - except Exception as e: - page = e - page = None - return page - def reddit_subreddit_check(self, sub): returndict = {"exists": True, "error": None} try: self.praw.subreddits.search_by_name(sub, exact=True) - except NotFound: + except prawcore.exceptions.NotFound: returndict["error"] = str(sub + " appears to not exist!") returndict["exists"] = False return returndict @@ -192,7 +204,7 @@ class BotReddit(): returndict = {"exists": True, "error": None} try: self.praw.redditor(user).fullname - except NotFound: + except prawcore.exceptions.NotFound: returndict["exists"] = False returndict["error"] = str(user + " appears to not exist!") return returndict From c194b03a165706619f7c7ad274f89a3cd57aec16 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 19 Jun 2019 13:52:35 -0400 Subject: [PATCH 032/127] patch --- sopel_modules/SpiceBot_Core_Commands/AI.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index 5c13fb7..bd182de 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -62,6 +62,8 @@ def bot_command_rule_ai(bot, trigger): else: command_type = 'other' trigger_args = spicemanip.main(message, 'create') + if not len(trigger_args): + return trigger_command = trigger_args[0] fulltrigger = spicemanip.main(trigger_args, 0) From 36884c7d4d35ccf10cda50a22183e91cb8d98e19 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 09:27:06 -0400 Subject: [PATCH 033/127] test without, make sure old stuff still works --- sopel_modules/SpiceBot/Commands.py | 39 ++-- sopel_modules/SpiceBot/DictComs.py | 309 ++++++++++++++++++++++++++++ sopel_modules/SpiceBot/Gif.py | 10 +- sopel_modules/SpiceBot/Tools.py | 18 +- sopel_modules/SpiceBot/__init__.py | 1 + sopel_modules/SpiceBot/configure.py | 12 +- sopel_modules/SpiceBot/setup.py | 9 +- 7 files changed, 365 insertions(+), 33 deletions(-) create mode 100644 sopel_modules/SpiceBot/DictComs.py diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index c746c1e..bd12f52 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -107,27 +107,24 @@ class BotCommands(): self.lock.acquire() command_type = command_dict["comtype"] - validcoms = command_dict["validcoms"] - - if not isinstance(validcoms, list): - validcoms = [validcoms] - if command_type not in list(self.dict['commands'].keys()): self.dict['commands'][command_type] = dict() - dict_from_file = dict() - # default command to filename - if "validcoms" not in list(dict_from_file.keys()): - dict_from_file["validcoms"] = validcoms + if "validcoms" not in list(command_dict.keys()): + command_dict["validcoms"] = [command_dict["filename"]] - maincom = dict_from_file["validcoms"][0] - if len(dict_from_file["validcoms"]) > 1: - comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') + validcoms = command_dict["validcoms"] + if not isinstance(validcoms, list): + validcoms = [validcoms] + + maincom = command_dict["validcoms"][0] + if len(command_dict["validcoms"]) > 1: + comaliases = spicemanip.main(command_dict["validcoms"], '2+', 'list') else: comaliases = [] - self.dict['commands'][command_type][maincom] = dict_from_file + self.dict['commands'][command_type][maincom] = command_dict for comalias in comaliases: if comalias not in list(self.dict['commands'][command_type].keys()): self.dict['commands'][command_type][comalias] = {"aliasfor": maincom} @@ -194,6 +191,11 @@ class BotCommands(): module_file_lines.append(line) module_file.close() + # gather file stats + slashsplit = str(modulefile).split("/") + filename = slashsplit[-1] + filename_base = os.path.basename(filename).rsplit('.', 1)[0] + detected_lines = [] for line in module_file_lines: @@ -245,7 +247,12 @@ class BotCommands(): validcoms.remove(regexcom) if len(validcoms): - validcomdict = {"comtype": comtype, "validcoms": validcoms} + validcomdict = { + "comtype": comtype, + "validcoms": validcoms, + "filepath": str(modulefile), + "filename": filename_base, + } filelinelist.append(validcomdict) currentsuccesslines += 1 except Exception as e: @@ -257,8 +264,8 @@ class BotCommands(): self.dict['counts'] += 1 if len(filelinelist): - for atlinefound in filelinelist: - self.register(atlinefound) + for vcomdict in filelinelist: + self.register(vcomdict) commands = BotCommands() diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py new file mode 100644 index 0000000..e2f4b75 --- /dev/null +++ b/sopel_modules/SpiceBot/DictComs.py @@ -0,0 +1,309 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot JSON Commands system. + +This Class stores commands in an easy to access manner +""" + +import os + +from sopel.config.types import StaticSection, ListAttribute +import sopel_modules + +from .Config import config as botconfig +from .Tools import read_directory_json_to_dict +from .Commands import commands as botcommands + +import spicemanip + +import requests +from fake_useragent import UserAgent +from lxml import html +import urllib + + +class SpiceBot_DictComs_MainSection(StaticSection): + extra = ListAttribute('extra') + + +class BotJSONCommands(): + """This Logs all commands known to the bot""" + def __init__(self): + def __init__(self): + self.setup_dictcoms() + self.header = {'User-Agent': str(UserAgent().chrome)} + self.valid_com_types = [ + 'simple', 'fillintheblank', 'targetplusreason', + 'sayings', "readfromfile", "readfromurl", + "ascii_art", "gif", "translate", "responses", + "feeds", "search" + ] + + dir_to_scan = [] + for plugin_dir in set(sopel_modules.__path__): + configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") + gifcfgdir = os.path.join(configsdir, "dictcoms") + dir_to_scan.append(gifcfgdir) + + if len(botconfig.SpiceBot_DictComs.extra): + for extragifcfgdir in botconfig.SpiceBot_DictComs.extra: + dir_to_scan.append(extragifcfgdir) + + valid_dictcom_dict = read_directory_json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") + + for dict_from_file in list(valid_dictcom_dict.keys()): + + dict_from_file["comtype"] = "prefix_command" + + # default command to filename + if "validcoms" not in list(dict_from_file.keys()): + dict_from_file["validcoms"] = [dict_from_file["filename"]] + elif dict_from_file["validcoms"] == []: + dict_from_file["validcoms"] = [dict_from_file["filename"]] + elif not isinstance(dict_from_file['validcoms'], list): + dict_from_file["validcoms"] = [dict_from_file["validcoms"]] + + maincom = dict_from_file["validcoms"][0] + + # check for tuple dict keys and split + validkeys = [x for x in list(dict_from_file.keys())] + for validkey in validkeys: + if isinstance(validkey, tuple): + tuple_bak = validkey + tuple_contents_bak = dict_from_file[validkey] + del dict_from_file[validkey] + for var in tuple_bak: + dict_from_file[var] = tuple_contents_bak + + # check that type is set, use cases will inherit this if not set + if "type" not in list(dict_from_file.keys()): + foldername = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0] + foldername = str(foldername).split("/")[-1] + dict_from_file["type"] = foldername + if dict_from_file["type"] not in self.valid_com_types: + dict_from_file["type"] = 'simple' + + # Don't process these. + keysprocessed = [] + keysprocessed.extend(["validcoms", "filepath", "filename"]) + + # the command must have an author + if "author" not in list(dict_from_file.keys()): + dict_from_file["author"] = "deathbybandaid" + keysprocessed.append("author") + + # the command must have a contributors list + if "contributors" not in list(dict_from_file.keys()): + dict_from_file["contributors"] = [] + if not isinstance(dict_from_file["contributors"], list): + dict_from_file["contributors"] = [dict_from_file["contributors"]] + if "deathbybandaid" not in dict_from_file["contributors"]: + dict_from_file["contributors"].append("deathbybandaid") + if dict_from_file["author"] not in dict_from_file["contributors"]: + dict_from_file["contributors"].append(dict_from_file["author"]) + keysprocessed.append("contributors") + + if "hardcoded_channel_block" not in list(dict_from_file.keys()): + dict_from_file["hardcoded_channel_block"] = [] + keysprocessed.append("hardcoded_channel_block") + + if "example" not in list(dict_from_file.keys()): + dict_from_file["example"] = str(botconfig.core.prefix_list[0] + maincom) + + if "exampleresponse" not in list(dict_from_file.keys()): + dict_from_file["exampleresponse"] = None + + if "description" not in list(dict_from_file.keys()): + dict_from_file["description"] = None + + if "privs" not in list(dict_from_file.keys()): + dict_from_file["privs"] = [] + + keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"]) + + # handle basic required dict handling + dict_required = ["?default"] + dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, dict_required) + keysprocessed.extend(dict_required) + + # remove later + keysprocessed.append("type") + + # all other keys not processed above are considered potential use cases + otherkeys = [] + for otherkey in list(dict_from_file.keys()): + if otherkey not in keysprocessed: + otherkeys.append(otherkey) + if otherkeys != []: + dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, otherkeys) + keysprocessed.extend(otherkeys) + + botcommands.register(dict_from_file) + + def bot_dict_use_cases(self, maincom, dict_from_file, process_list): + + for mustbe in process_list: + + # All of the above need to be in the dict if not + if mustbe not in list(dict_from_file.keys()): + dict_from_file[mustbe] = dict() + + # verify if already there, that the key is a dict + if not isinstance(dict_from_file[mustbe], dict): + dict_from_file[mustbe] = dict() + + # Each usecase for the command must have a type, flat files inherit this type + if "type" not in list(dict_from_file[mustbe].keys()): + if "type" in list(dict_from_file.keys()): + dict_from_file[mustbe]["type"] = dict_from_file["type"] + else: + dict_from_file[mustbe]["type"] = "simple" + + # each usecase needs to know if it can be updated. Default is false + if "updates_enabled" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["updates_enabled"] = False + if dict_from_file[mustbe]["updates_enabled"]: + if dict_from_file[mustbe]["updates_enabled"] not in ["shared", "user"]: + dict_from_file[mustbe]["updates_enabled"] = "shared" + + # each usecase needs to know if it needs a target + if "target_required" not in list(dict_from_file[mustbe].keys()): + if dict_from_file[mustbe]["type"] in ['target', 'targetplusreason']: + dict_from_file[mustbe]["target_required"] = True + else: + dict_from_file[mustbe]["target_required"] = False + if "target_backup" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["target_backup"] = False + if "target_bypass" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["target_bypass"] = [] + + # special target reactions + for reason in ['self', 'bot', 'bots', 'offline', 'unknown', 'privmsg', 'diffchannel', 'diffbot']: + if 'react_'+reason not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]['react_'+reason] = False + + # each usecase needs to know if it needs input for fillintheblank + if "blank_required" not in list(dict_from_file[mustbe].keys()): + if dict_from_file[mustbe]["type"] in ['fillintheblank', 'targetplusreason', "translate"]: + dict_from_file[mustbe]["blank_required"] = True + else: + dict_from_file[mustbe]["blank_required"] = False + if "blank_backup" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["blank_backup"] = False + if "blank_fail" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["blank_fail"] = ["This command requires input."] + if not isinstance(dict_from_file[mustbe]["blank_fail"], list): + dict_from_file[mustbe]["blank_fail"] = [dict_from_file[mustbe]["blank_fail"]] + + if "blank_phrasehandle" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["blank_phrasehandle"] = False + if dict_from_file[mustbe]["blank_phrasehandle"]: + if not isinstance(dict_from_file[mustbe]["blank_phrasehandle"], list): + dict_from_file[mustbe]["blank_phrasehandle"] = [dict_from_file[mustbe]["blank_phrasehandle"]] + + if "response_fail" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["response_fail"] = False + if dict_from_file[mustbe]["response_fail"]: + if not isinstance(dict_from_file[mustbe]["response_fail"], list): + dict_from_file[mustbe]["response_fail"] = [dict_from_file[mustbe]["response_fail"]] + + # if dict_from_file[mustbe]["updates_enabled"]: + # adjust_nick_array(bot, str(bot.nick), 'long', 'sayings', maincom + "_" + str(mustbe), dict_from_file[mustbe]["responses"], 'startup') + # dict_from_file[mustbe]["responses"] = get_nick_value(bot, str(bot.nick), 'long', 'sayings', maincom + "_" + str(mustbe)) or [] + + # each usecase needs a response + if "responses" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["responses"] = [] + + # verify responses are in list form + if not isinstance(dict_from_file[mustbe]["responses"], list): + # TODO read text files + # if dict_from_file[mustbe]["responses"] in bot.memory["botdict"]["tempvals"]['txt_files'].keys(): + # dict_from_file[mustbe]["responses"] = bot.memory["botdict"]["tempvals"]['txt_files'][dict_from_file[mustbe]["responses"]] + if str(dict_from_file[mustbe]["responses"]).startswith(tuple(["https://", "http://"])): + try: + page = requests.get(dict_from_file[mustbe]["responses"], headers=self.header) + except Exception as e: + page = e + page = None + + if page and not str(page.status_code).startswith(tuple(["4", "5"])): + htmlfile = urllib.request.urlopen(dict_from_file[mustbe]["responses"]) + lines = htmlfile.read().splitlines() + dict_from_file[mustbe]["responses"] = lines + else: + dict_from_file[mustbe]["responses"] = [dict_from_file[mustbe]["responses"]] + + # each usecase needs a prefixtext + if "prefixtext" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["prefixtext"] = False + if dict_from_file[mustbe]["prefixtext"]: + if not isinstance(dict_from_file[mustbe]["prefixtext"], list): + dict_from_file[mustbe]["prefixtext"] = [dict_from_file[mustbe]["prefixtext"]] + + # each usecase needs a suffixtext + if "suffixtext" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["suffixtext"] = False + if dict_from_file[mustbe]["suffixtext"]: + if not isinstance(dict_from_file[mustbe]["suffixtext"], list): + dict_from_file[mustbe]["suffixtext"] = [dict_from_file[mustbe]["suffixtext"]] + + # Translations + if "translations" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["translations"] = False + if dict_from_file[mustbe]["translations"]: + if not isinstance(dict_from_file[mustbe]["translations"], list): + dict_from_file[mustbe]["translations"] = [dict_from_file[mustbe]["translations"]] + + # make sure we have the smaller variation list + if "replyvariation" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["replyvariation"] = [] + if not isinstance(dict_from_file[mustbe]["replyvariation"], list): + dict_from_file[mustbe]["replyvariation"] = [dict_from_file[mustbe]["replyvariation"]] + + # This is to provide functionality for flat dictionaries responses + if dict_from_file[mustbe]["responses"] == [] and mustbe == "?default": + if "responses" in list(dict_from_file.keys()): + if isinstance(dict_from_file["responses"], list): + dict_from_file[mustbe]["responses"].extend(dict_from_file["responses"]) + else: + dict_from_file[mustbe]["responses"].append(dict_from_file["responses"]) + del dict_from_file["responses"] + + # Verify responses list is not empty + if dict_from_file[mustbe]["responses"] == []: + dict_from_file[mustbe]["responses"].append("No " + str(mustbe) + " responses set for " + str(maincom) + ".") + + # Some commands run query mode + if "search_fail" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["search_fail"] = None + if dict_from_file[mustbe]["search_fail"]: + if not isinstance(dict_from_file[mustbe]["search_fail"], list): + dict_from_file[mustbe]["search_fail"] = [dict_from_file[mustbe]["search_fail"]] + + if "selection_allowed" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["selection_allowed"] = True + + # Translations + if "randnum" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["randnum"] = False + if dict_from_file[mustbe]["randnum"]: + if not isinstance(dict_from_file[mustbe]["randnum"], list): + dict_from_file[mustbe]["randnum"] = [0, 50] + if len(dict_from_file[mustbe]["randnum"]) == 1: + dict_from_file[mustbe]["randnum"] = [0, dict_from_file[mustbe]["randnum"][0]] + + if "hardcoded_channel_block" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["hardcoded_channel_block"] = [] + + if "privs" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["privs"] = [] + + return dict_from_file + + def setup_dictcoms(self): + botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) + + +jsoncommands = BotJSONCommands() diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index f39ac9c..dab7b39 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -42,8 +42,8 @@ class BotGif(): gifcfgdir = os.path.join(configsdir, "gifapi") dir_to_scan.append(gifcfgdir) - if len(botconfig.SopelGifSearch.extra): - for extragifcfgdir in botconfig.SopelGifSearch.extra: + if len(botconfig.SpiceBot_Gif.extra): + for extragifcfgdir in botconfig.SpiceBot_Gif.extra: dir_to_scan.append(extragifcfgdir) valid_gif_api_dict = read_directory_json_to_dict(dir_to_scan, "Gif API", "SpiceBot_Gif") @@ -62,13 +62,13 @@ class BotGif(): for validgifapi in list(self.valid_api.keys()): command_dict = { "comtype": "gif_prefix", - "validcoms": validgifapi + "validcoms": [validgifapi] } botcommands.dict['counts'] += 1 botcommands.register(command_dict) def setup_gif(self): - botconfig.define_section("SopelGifSearch", SpiceBot_Gif_MainSection, validate=False) + botconfig.define_section("SpiceBot_Gif", SpiceBot_Gif_MainSection, validate=False) def get_gif(self, searchdict): @@ -90,7 +90,7 @@ class BotGif(): for remx in query_defaults["gifsearchremove"]: searchdict["gifsearch"].remove(remx) - if botconfig.SopelGifSearch.nsfw: + if botconfig.SpiceBot_Gif.nsfw: query_defaults["nsfw"] = True # verify query is there to search diff --git a/sopel_modules/SpiceBot/Tools.py b/sopel_modules/SpiceBot/Tools.py index ef61bee..185241c 100644 --- a/sopel_modules/SpiceBot/Tools.py +++ b/sopel_modules/SpiceBot/Tools.py @@ -352,14 +352,18 @@ def read_directory_json_to_dict(directories, configtypename="Config File", log_f # Close File inf.close() - if filereadgood and isinstance(dict_from_file, dict): - filecount += 1 - slashsplit = str(filepath).split("/") - filename = slashsplit[-1] - filename_base = os.path.basename(filename).rsplit('.', 1)[0] - configs_dict[filename_base] = dict_from_file - else: + # gather file stats + slashsplit = str(filepath).split("/") + filename = slashsplit[-1] + filename_base = os.path.basename(filename).rsplit('.', 1)[0] + + if not filereadgood or not isinstance(dict_from_file, dict): fileopenfail += 1 + else: + filecount += 1 + dict_from_file["filepath"] = str(filepath) + dict_from_file["filename"] = str(filename_base) + configs_dict[filename_base] = dict_from_file if filecount: if logging: diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index fac2d5c..03d0ca4 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -26,6 +26,7 @@ from .Google import * from .Gif import * from .Sherlock import * from .Reddit import * +# from .DictComs import * from .configure import * diff --git a/sopel_modules/SpiceBot/configure.py b/sopel_modules/SpiceBot/configure.py index 2c317c6..473258b 100644 --- a/sopel_modules/SpiceBot/configure.py +++ b/sopel_modules/SpiceBot/configure.py @@ -8,6 +8,7 @@ from .Google import SpiceBot_Google_MainSection from .AI import SpiceBot_AI_MainSection from .Update import SpiceBot_Update_MainSection from .Gif import SpiceBot_Gif_MainSection +from .DictComs import SpiceBot_DictComs_MainSection from .Reddit import SpiceBot_Reddit_MainSection from .Kick import SpiceBot_Kick from .osd import SpiceBot_OSD @@ -48,9 +49,12 @@ def configure(config): config.SpiceBot_Google.configure_setting('search_api', 'api key for google searching') config.define_section("SpiceBot_Gif", SpiceBot_Gif_MainSection, validate=False) - config.SopelGifSearch.configure_setting('extra', 'SpiceBot_Gif API Extra directory') - config.SopelGifSearch.configure_setting('nsfw', 'SpiceBot_Gif API nsfw content') + config.SpiceBot_Gif.configure_setting('extra', 'SpiceBot_Gif API Extra directory') + config.SpiceBot_Gif.configure_setting('nsfw', 'SpiceBot_Gif API nsfw content') config.define_section("SpiceBot_Reddit", SpiceBot_Reddit_MainSection, validate=False) - config.SopelGifSearch.configure_setting('client_id', 'SpiceBot_Reddit client_id') - config.SopelGifSearch.configure_setting('client_secret', 'SpiceBot_Reddit client_secret') + config.SpiceBot_Gif.configure_setting('client_id', 'SpiceBot_Reddit client_id') + config.SpiceBot_Gif.configure_setting('client_secret', 'SpiceBot_Reddit client_secret') + + config.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) + config.SpiceBot_DictComs.configure_setting('extra', 'SpiceBot_DictComs API Extra directory') diff --git a/sopel_modules/SpiceBot/setup.py b/sopel_modules/SpiceBot/setup.py index afab024..e3038b8 100644 --- a/sopel_modules/SpiceBot/setup.py +++ b/sopel_modules/SpiceBot/setup.py @@ -19,6 +19,7 @@ from .Reddit import SpiceBot_Reddit_MainSection from .osd import SopelWrapperOSD, ToolsOSD, SopelOSD, SpiceBot_OSD from .Kick import SopelWrapperKICK, SopelKICK, SpiceBot_Kick from .Gif import SpiceBot_Gif_MainSection +from .DictComs import SpiceBot_DictComs_MainSection from .AI import SpiceBot_AI_MainSection @@ -58,6 +59,8 @@ def setup(bot): setup_reddit(bot) + setup_dictcoms(bot) + def setup_config(bot): logs.log('SpiceBot_Config', "Setting Up Configuration") @@ -147,8 +150,12 @@ def setup_kick(bot): def setup_gif(bot): - bot.config.define_section("SopelGifSearch", SpiceBot_Gif_MainSection, validate=False) + bot.config.define_section("SpiceBot_Gif", SpiceBot_Gif_MainSection, validate=False) def setup_reddit(bot): bot.config.define_section("SpiceBot_Reddit", SpiceBot_Reddit_MainSection, validate=False) + + +def setup_dictcoms(bot): + bot.config.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) From 9d1339f31af8a715166259a9daab69dd44d582b7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 09:38:38 -0400 Subject: [PATCH 034/127] config folder names --- sopel_modules/SpiceBot/AI.py | 2 +- sopel_modules/SpiceBot/DictComs.py | 2 +- sopel_modules/SpiceBot/Gif.py | 2 +- sopel_modules/SpiceBot/Read.py | 17 +++++++++++++++++ sopel_modules/SpiceBot/Sherlock.py | 4 ++-- .../{aiml => SpiceBot_AI}/dog.aiml | 0 .../nickname_acknowledge.aiml | 0 .../nickname_canyousee.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_gender.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_goodbye.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_hello.aiml | 0 .../nickname_insulthandler.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_lazy.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_love.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_ping.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_praise.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_really.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_thanks.aiml | 0 .../nickname_transporter.aiml | 0 .../nickname_welcomeback.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_whatis.aiml | 0 .../{aiml => SpiceBot_AI}/nickname_whereis.aiml | 0 .../{gifapi => SpiceBot_Gif}/gfycat.json | 0 .../{gifapi => SpiceBot_Gif}/gifme.json | 0 .../{gifapi => SpiceBot_Gif}/giphy.json | 0 .../{gifapi => SpiceBot_Gif}/tenor.json | 0 .../{sherlock => SpiceBot_Sherlock}/500px.json | 0 .../About.me.json | 0 .../AngelList.json | 0 .../BLIP.fm.json | 0 .../Bandcamp.json | 0 .../Behance.json | 0 .../BitBucket.json | 0 .../Blogger.json | 0 .../BuzzFeed.json | 0 .../{sherlock => SpiceBot_Sherlock}/Canva.json | 0 .../{sherlock => SpiceBot_Sherlock}/CashMe.json | 0 .../Codecademy.json | 0 .../Codementor.json | 0 .../ColourLovers.json | 0 .../Contently.json | 0 .../DailyMotion.json | 0 .../Designspiration.json | 0 .../DeviantART.json | 0 .../{sherlock => SpiceBot_Sherlock}/Disqus.json | 0 .../Dribbble.json | 0 .../{sherlock => SpiceBot_Sherlock}/Ebay.json | 0 .../{sherlock => SpiceBot_Sherlock}/Ello.json | 0 .../{sherlock => SpiceBot_Sherlock}/Etsy.json | 0 .../Facebook.json | 0 .../{sherlock => SpiceBot_Sherlock}/Flickr.json | 0 .../Flipboard.json | 0 .../Fotolog.json | 0 .../Foursquare.json | 0 .../{sherlock => SpiceBot_Sherlock}/GitHub.json | 0 .../GoodReads.json | 0 .../GooglePlus.json | 0 .../Gravatar.json | 0 .../Gumroad.json | 0 .../HackerNews.json | 0 .../HackerOne.json | 0 .../{sherlock => SpiceBot_Sherlock}/Houzz.json | 0 .../{sherlock => SpiceBot_Sherlock}/IFTTT.json | 0 .../{sherlock => SpiceBot_Sherlock}/Imgur.json | 0 .../Instagram.json | 0 .../Instructables.json | 0 .../Keybase.json | 0 .../Kongregate.json | 0 .../LiveJournal.json | 0 .../{sherlock => SpiceBot_Sherlock}/Medium.json | 0 .../MixCloud.json | 0 .../Newgrounds.json | 0 .../Pastebin.json | 0 .../Patreon.json | 0 .../{sherlock => SpiceBot_Sherlock}/Pexels.json | 0 .../Pinterest.json | 0 .../{sherlock => SpiceBot_Sherlock}/Reddit.json | 0 .../ReverbNation.json | 0 .../{sherlock => SpiceBot_Sherlock}/Roblox.json | 0 .../{sherlock => SpiceBot_Sherlock}/Scribd.json | 0 .../{sherlock => SpiceBot_Sherlock}/Slack.json | 0 .../SlideShare.json | 0 .../SoundCloud.json | 0 .../Spotify.json | 0 .../{sherlock => SpiceBot_Sherlock}/Steam.json | 0 .../{sherlock => SpiceBot_Sherlock}/Tinder.json | 0 .../{sherlock => SpiceBot_Sherlock}/Trakt.json | 0 .../{sherlock => SpiceBot_Sherlock}/Trip.json | 0 .../TripAdvisor.json | 0 .../Twitter.json | 0 .../Unsplash.json | 0 .../{sherlock => SpiceBot_Sherlock}/VK.json | 0 .../{sherlock => SpiceBot_Sherlock}/VSCO.json | 0 .../{sherlock => SpiceBot_Sherlock}/Vimeo.json | 0 .../Wattpad.json | 0 .../WeHeartIt.json | 0 .../WordPress.json | 0 .../YouTube.json | 0 .../devRant.json | 0 .../iMGSRC.RU.json | 0 .../last.fm.json | 0 101 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 sopel_modules/SpiceBot/Read.py rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/dog.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_acknowledge.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_canyousee.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_gender.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_goodbye.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_hello.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_insulthandler.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_lazy.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_love.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_ping.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_praise.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_really.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_thanks.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_transporter.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_welcomeback.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_whatis.aiml (100%) rename sopel_modules/SpiceBot_Configs/{aiml => SpiceBot_AI}/nickname_whereis.aiml (100%) rename sopel_modules/SpiceBot_Configs/{gifapi => SpiceBot_Gif}/gfycat.json (100%) rename sopel_modules/SpiceBot_Configs/{gifapi => SpiceBot_Gif}/gifme.json (100%) rename sopel_modules/SpiceBot_Configs/{gifapi => SpiceBot_Gif}/giphy.json (100%) rename sopel_modules/SpiceBot_Configs/{gifapi => SpiceBot_Gif}/tenor.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/500px.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/About.me.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/AngelList.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/BLIP.fm.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Bandcamp.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Behance.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/BitBucket.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Blogger.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/BuzzFeed.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Canva.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/CashMe.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Codecademy.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Codementor.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/ColourLovers.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Contently.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/DailyMotion.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Designspiration.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/DeviantART.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Disqus.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Dribbble.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Ebay.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Ello.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Etsy.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Facebook.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Flickr.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Flipboard.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Fotolog.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Foursquare.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/GitHub.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/GoodReads.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/GooglePlus.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Gravatar.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Gumroad.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/HackerNews.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/HackerOne.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Houzz.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/IFTTT.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Imgur.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Instagram.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Instructables.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Keybase.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Kongregate.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/LiveJournal.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Medium.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/MixCloud.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Newgrounds.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Pastebin.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Patreon.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Pexels.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Pinterest.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Reddit.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/ReverbNation.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Roblox.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Scribd.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Slack.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/SlideShare.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/SoundCloud.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Spotify.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Steam.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Tinder.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Trakt.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Trip.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/TripAdvisor.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Twitter.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Unsplash.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/VK.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/VSCO.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Vimeo.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/Wattpad.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/WeHeartIt.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/WordPress.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/YouTube.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/devRant.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/iMGSRC.RU.json (100%) rename sopel_modules/SpiceBot_Configs/{sherlock => SpiceBot_Sherlock}/last.fm.json (100%) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index 14e5782..ccd0ea2 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -63,7 +63,7 @@ class SpiceBot_AI(): braindirs = [] for plugin_dir in set(sopel_modules.__path__): configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - aimldir = os.path.join(configsdir, "aiml") + aimldir = os.path.join(configsdir, "SpiceBot_AI") braindirs.append(aimldir) if len(botconfig.SpiceBot_AI.extra): diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index e2f4b75..df0c145 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -43,7 +43,7 @@ class BotJSONCommands(): dir_to_scan = [] for plugin_dir in set(sopel_modules.__path__): configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - gifcfgdir = os.path.join(configsdir, "dictcoms") + gifcfgdir = os.path.join(configsdir, "SpiceBot_DictComs") dir_to_scan.append(gifcfgdir) if len(botconfig.SpiceBot_DictComs.extra): diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index dab7b39..b596a8c 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -39,7 +39,7 @@ class BotGif(): dir_to_scan = [] for plugin_dir in set(sopel_modules.__path__): configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - gifcfgdir = os.path.join(configsdir, "gifapi") + gifcfgdir = os.path.join(configsdir, "SpiceBot_Gif") dir_to_scan.append(gifcfgdir) if len(botconfig.SpiceBot_Gif.extra): diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py new file mode 100644 index 0000000..277e09b --- /dev/null +++ b/sopel_modules/SpiceBot/Read.py @@ -0,0 +1,17 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +"""This is a method to read files, online and local, and cache them""" + +import sopel_modules + + +class BotRead(): + + def __init__(self): + self.dict = dict() + + def config_dir(self): + return + + +read = BotRead() diff --git a/sopel_modules/SpiceBot/Sherlock.py b/sopel_modules/SpiceBot/Sherlock.py index a5e66f2..2c85e4e 100644 --- a/sopel_modules/SpiceBot/Sherlock.py +++ b/sopel_modules/SpiceBot/Sherlock.py @@ -21,10 +21,10 @@ class Sherlock(): dir_to_scan = [] for plugin_dir in set(sopel_modules.__path__): configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - usercfgdir = os.path.join(configsdir, "sherlock") + usercfgdir = os.path.join(configsdir, "SpiceBot_Sherlock") dir_to_scan.append(usercfgdir) - valid_usernames_dict = read_directory_json_to_dict(dir_to_scan, "Gif API", "SpiceBot_Gif") + valid_usernames_dict = read_directory_json_to_dict(dir_to_scan, "Sherlock", "SpiceBot_Sherlock") for social_network in list(valid_usernames_dict.keys()): self.dict[social_network] = valid_usernames_dict[social_network] diff --git a/sopel_modules/SpiceBot_Configs/aiml/dog.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/dog.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/dog.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/dog.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_acknowledge.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_acknowledge.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_acknowledge.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_acknowledge.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_canyousee.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_canyousee.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_canyousee.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_canyousee.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_gender.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_gender.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_gender.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_gender.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_goodbye.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_goodbye.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_goodbye.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_goodbye.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_hello.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_hello.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_hello.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_hello.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_insulthandler.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_insulthandler.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_insulthandler.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_insulthandler.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_lazy.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_lazy.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_lazy.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_lazy.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_love.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_love.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_love.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_love.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_ping.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_ping.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_ping.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_ping.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_praise.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_praise.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_praise.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_praise.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_really.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_really.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_really.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_really.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_thanks.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_thanks.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_thanks.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_thanks.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_transporter.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_transporter.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_transporter.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_transporter.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_welcomeback.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_welcomeback.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_welcomeback.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_welcomeback.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_whatis.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_whatis.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_whatis.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_whatis.aiml diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_whereis.aiml b/sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_whereis.aiml similarity index 100% rename from sopel_modules/SpiceBot_Configs/aiml/nickname_whereis.aiml rename to sopel_modules/SpiceBot_Configs/SpiceBot_AI/nickname_whereis.aiml diff --git a/sopel_modules/SpiceBot_Configs/gifapi/gfycat.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Gif/gfycat.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/gifapi/gfycat.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Gif/gfycat.json diff --git a/sopel_modules/SpiceBot_Configs/gifapi/gifme.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Gif/gifme.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/gifapi/gifme.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Gif/gifme.json diff --git a/sopel_modules/SpiceBot_Configs/gifapi/giphy.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Gif/giphy.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/gifapi/giphy.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Gif/giphy.json diff --git a/sopel_modules/SpiceBot_Configs/gifapi/tenor.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Gif/tenor.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/gifapi/tenor.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Gif/tenor.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/500px.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/500px.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/500px.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/500px.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/About.me.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/About.me.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/About.me.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/About.me.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/AngelList.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/AngelList.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/AngelList.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/AngelList.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/BLIP.fm.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/BLIP.fm.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/BLIP.fm.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/BLIP.fm.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Bandcamp.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Bandcamp.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Bandcamp.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Bandcamp.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Behance.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Behance.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Behance.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Behance.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/BitBucket.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/BitBucket.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/BitBucket.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/BitBucket.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Blogger.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Blogger.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Blogger.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Blogger.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/BuzzFeed.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/BuzzFeed.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/BuzzFeed.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/BuzzFeed.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Canva.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Canva.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Canva.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Canva.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/CashMe.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/CashMe.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/CashMe.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/CashMe.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Codecademy.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Codecademy.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Codecademy.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Codecademy.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Codementor.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Codementor.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Codementor.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Codementor.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/ColourLovers.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/ColourLovers.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/ColourLovers.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/ColourLovers.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Contently.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Contently.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Contently.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Contently.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/DailyMotion.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/DailyMotion.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/DailyMotion.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/DailyMotion.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Designspiration.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Designspiration.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Designspiration.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Designspiration.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/DeviantART.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/DeviantART.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/DeviantART.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/DeviantART.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Disqus.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Disqus.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Disqus.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Disqus.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Dribbble.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Dribbble.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Dribbble.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Dribbble.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Ebay.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Ebay.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Ebay.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Ebay.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Ello.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Ello.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Ello.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Ello.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Etsy.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Etsy.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Etsy.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Etsy.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Facebook.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Facebook.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Facebook.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Facebook.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Flickr.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Flickr.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Flickr.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Flickr.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Flipboard.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Flipboard.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Flipboard.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Flipboard.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Fotolog.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Fotolog.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Fotolog.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Fotolog.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Foursquare.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Foursquare.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Foursquare.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Foursquare.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/GitHub.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/GitHub.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/GitHub.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/GitHub.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/GoodReads.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/GoodReads.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/GoodReads.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/GoodReads.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/GooglePlus.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/GooglePlus.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/GooglePlus.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/GooglePlus.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Gravatar.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Gravatar.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Gravatar.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Gravatar.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Gumroad.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Gumroad.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Gumroad.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Gumroad.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/HackerNews.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/HackerNews.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/HackerNews.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/HackerNews.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/HackerOne.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/HackerOne.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/HackerOne.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/HackerOne.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Houzz.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Houzz.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Houzz.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Houzz.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/IFTTT.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/IFTTT.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/IFTTT.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/IFTTT.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Imgur.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Imgur.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Imgur.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Imgur.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Instagram.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Instagram.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Instagram.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Instagram.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Instructables.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Instructables.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Instructables.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Instructables.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Keybase.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Keybase.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Keybase.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Keybase.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Kongregate.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Kongregate.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Kongregate.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Kongregate.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/LiveJournal.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/LiveJournal.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/LiveJournal.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/LiveJournal.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Medium.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Medium.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Medium.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Medium.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/MixCloud.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/MixCloud.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/MixCloud.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/MixCloud.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Newgrounds.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Newgrounds.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Newgrounds.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Newgrounds.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Pastebin.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Pastebin.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Pastebin.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Pastebin.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Patreon.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Patreon.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Patreon.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Patreon.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Pexels.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Pexels.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Pexels.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Pexels.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Pinterest.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Pinterest.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Pinterest.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Pinterest.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Reddit.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Reddit.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Reddit.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Reddit.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/ReverbNation.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/ReverbNation.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/ReverbNation.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/ReverbNation.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Roblox.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Roblox.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Roblox.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Roblox.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Scribd.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Scribd.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Scribd.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Scribd.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Slack.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Slack.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Slack.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Slack.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/SlideShare.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/SlideShare.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/SlideShare.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/SlideShare.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/SoundCloud.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/SoundCloud.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/SoundCloud.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/SoundCloud.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Spotify.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Spotify.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Spotify.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Spotify.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Steam.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Steam.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Steam.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Steam.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Tinder.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Tinder.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Tinder.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Tinder.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Trakt.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Trakt.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Trakt.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Trakt.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Trip.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Trip.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Trip.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Trip.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/TripAdvisor.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/TripAdvisor.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/TripAdvisor.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/TripAdvisor.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Twitter.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Twitter.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Twitter.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Twitter.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Unsplash.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Unsplash.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Unsplash.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Unsplash.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/VK.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/VK.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/VK.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/VK.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/VSCO.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/VSCO.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/VSCO.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/VSCO.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Vimeo.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Vimeo.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Vimeo.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Vimeo.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/Wattpad.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Wattpad.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/Wattpad.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/Wattpad.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/WeHeartIt.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/WeHeartIt.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/WeHeartIt.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/WeHeartIt.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/WordPress.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/WordPress.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/WordPress.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/WordPress.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/YouTube.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/YouTube.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/YouTube.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/YouTube.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/devRant.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/devRant.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/devRant.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/devRant.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/iMGSRC.RU.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/iMGSRC.RU.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/iMGSRC.RU.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/iMGSRC.RU.json diff --git a/sopel_modules/SpiceBot_Configs/sherlock/last.fm.json b/sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/last.fm.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/sherlock/last.fm.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_Sherlock/last.fm.json From 0fe8f7dbf383e50d008395e8d88ddf0948cd9886 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 09:45:21 -0400 Subject: [PATCH 035/127] begin usage of read class --- sopel_modules/SpiceBot/DictComs.py | 4 +- sopel_modules/SpiceBot/Gif.py | 4 +- sopel_modules/SpiceBot/Read.py | 59 ++++++++++++++++++++++++++++++ sopel_modules/SpiceBot/Sherlock.py | 4 +- sopel_modules/SpiceBot/Tools.py | 58 ----------------------------- sopel_modules/SpiceBot/__init__.py | 1 + 6 files changed, 66 insertions(+), 64 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index df0c145..d5325d7 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -12,7 +12,7 @@ from sopel.config.types import StaticSection, ListAttribute import sopel_modules from .Config import config as botconfig -from .Tools import read_directory_json_to_dict +from .Read import read as botread from .Commands import commands as botcommands import spicemanip @@ -50,7 +50,7 @@ class BotJSONCommands(): for extragifcfgdir in botconfig.SpiceBot_DictComs.extra: dir_to_scan.append(extragifcfgdir) - valid_dictcom_dict = read_directory_json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") + valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") for dict_from_file in list(valid_dictcom_dict.keys()): diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index b596a8c..231462f 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -6,7 +6,7 @@ from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute import sopel_modules from .Config import config as botconfig -from .Tools import read_directory_json_to_dict +from .Read import read as botread from .Commands import commands as botcommands import spicemanip @@ -46,7 +46,7 @@ class BotGif(): for extragifcfgdir in botconfig.SpiceBot_Gif.extra: dir_to_scan.append(extragifcfgdir) - valid_gif_api_dict = read_directory_json_to_dict(dir_to_scan, "Gif API", "SpiceBot_Gif") + valid_gif_api_dict = botread.json_to_dict(dir_to_scan, "Gif API", "SpiceBot_Gif") for gif_api in list(valid_gif_api_dict.keys()): botconfig.define_section(gif_api, GifAPISection, validate=False) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 277e09b..3a29b74 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -4,6 +4,11 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel_modules +import os +import codecs + +from .Logs import logs + class BotRead(): @@ -13,5 +18,59 @@ class BotRead(): def config_dir(self): return + def json_to_dict(directories, configtypename="Config File", log_from='read_directory_json_to_dict', logging=True): + + if not isinstance(directories, list): + directories = [directories] + + configs_dict = {} + filesprocess, fileopenfail, filecount = [], 0, 0 + for directory in directories: + if os.path.exists(directory) and os.path.isdir(directory): + if len(os.listdir(directory)) > 0: + for file in os.listdir(directory): + filepath = os.path.join(directory, file) + if os.path.isfile(filepath) and filepath.endswith('.json'): + filesprocess.append(filepath) + + for filepath in filesprocess: + + # Read dictionary from file, if not, enable an empty dict + filereadgood = True + inf = codecs.open(filepath, "r", encoding='utf-8') + infread = inf.read() + try: + dict_from_file = eval(infread) + except Exception as e: + filereadgood = False + if logging: + logs.log(log_from, "Error loading %s: %s (%s)" % (configtypename, e, filepath)) + dict_from_file = dict() + # Close File + inf.close() + + # gather file stats + slashsplit = str(filepath).split("/") + filename = slashsplit[-1] + filename_base = os.path.basename(filename).rsplit('.', 1)[0] + + if not filereadgood or not isinstance(dict_from_file, dict): + fileopenfail += 1 + else: + filecount += 1 + dict_from_file["filepath"] = str(filepath) + dict_from_file["filename"] = str(filename_base) + configs_dict[filename_base] = dict_from_file + + if filecount: + if logging: + logs.log(log_from, 'Registered %d %s dict files,' % (filecount, configtypename)) + logs.log(log_from, '%d %s dict files failed to load' % (fileopenfail, configtypename), True) + else: + if logging: + logs.log(log_from, "Warning: Couldn't load any %s dict files" % (configtypename)) + + return configs_dict + read = BotRead() diff --git a/sopel_modules/SpiceBot/Sherlock.py b/sopel_modules/SpiceBot/Sherlock.py index 2c85e4e..2ae66ed 100644 --- a/sopel_modules/SpiceBot/Sherlock.py +++ b/sopel_modules/SpiceBot/Sherlock.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel_modules -from .Tools import read_directory_json_to_dict +from .Read import read as botread import os from fake_useragent import UserAgent @@ -24,7 +24,7 @@ class Sherlock(): usercfgdir = os.path.join(configsdir, "SpiceBot_Sherlock") dir_to_scan.append(usercfgdir) - valid_usernames_dict = read_directory_json_to_dict(dir_to_scan, "Sherlock", "SpiceBot_Sherlock") + valid_usernames_dict = botread.json_to_dict(dir_to_scan, "Sherlock", "SpiceBot_Sherlock") for social_network in list(valid_usernames_dict.keys()): self.dict[social_network] = valid_usernames_dict[social_network] diff --git a/sopel_modules/SpiceBot/Tools.py b/sopel_modules/SpiceBot/Tools.py index 185241c..84464e6 100644 --- a/sopel_modules/SpiceBot/Tools.py +++ b/sopel_modules/SpiceBot/Tools.py @@ -316,61 +316,3 @@ def service_manip(servicename, dowhat, log_from='service_manip'): os.system("sudo service " + str(servicename) + " " + str(dowhat)) except Exception as e: logs.log(log_from, str(dowhat).title() + "ing " + str(servicename) + ".service Failed: " + str(e)) - - -"""Config Reading Functions""" - - -def read_directory_json_to_dict(directories, configtypename="Config File", log_from='read_directory_json_to_dict', logging=True): - - if not isinstance(directories, list): - directories = [directories] - - configs_dict = {} - filesprocess, fileopenfail, filecount = [], 0, 0 - for directory in directories: - if os.path.exists(directory) and os.path.isdir(directory): - if len(os.listdir(directory)) > 0: - for file in os.listdir(directory): - filepath = os.path.join(directory, file) - if os.path.isfile(filepath) and filepath.endswith('.json'): - filesprocess.append(filepath) - - for filepath in filesprocess: - - # Read dictionary from file, if not, enable an empty dict - filereadgood = True - inf = codecs.open(filepath, "r", encoding='utf-8') - infread = inf.read() - try: - dict_from_file = eval(infread) - except Exception as e: - filereadgood = False - if logging: - logs.log(log_from, "Error loading %s: %s (%s)" % (configtypename, e, filepath)) - dict_from_file = dict() - # Close File - inf.close() - - # gather file stats - slashsplit = str(filepath).split("/") - filename = slashsplit[-1] - filename_base = os.path.basename(filename).rsplit('.', 1)[0] - - if not filereadgood or not isinstance(dict_from_file, dict): - fileopenfail += 1 - else: - filecount += 1 - dict_from_file["filepath"] = str(filepath) - dict_from_file["filename"] = str(filename_base) - configs_dict[filename_base] = dict_from_file - - if filecount: - if logging: - logs.log(log_from, 'Registered %d %s dict files,' % (filecount, configtypename)) - logs.log(log_from, '%d %s dict files failed to load' % (fileopenfail, configtypename), True) - else: - if logging: - logs.log(log_from, "Warning: Couldn't load any %s dict files" % (configtypename)) - - return configs_dict diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index 03d0ca4..f051b6c 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -27,6 +27,7 @@ from .Gif import * from .Sherlock import * from .Reddit import * # from .DictComs import * +from .Read import * from .configure import * From ad63faf6f0769176ad61d5055891169d5774a219 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 09:54:39 -0400 Subject: [PATCH 036/127] test with self --- sopel_modules/SpiceBot/Read.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 3a29b74..0f3a056 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -18,7 +18,7 @@ class BotRead(): def config_dir(self): return - def json_to_dict(directories, configtypename="Config File", log_from='read_directory_json_to_dict', logging=True): + def json_to_dict(self, directories, configtypename="Config File", log_from='read_directory_json_to_dict', logging=True): if not isinstance(directories, list): directories = [directories] From dc566d2096d230c3b1ceced23105ee523016c7fe Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 10:04:12 -0400 Subject: [PATCH 037/127] filepath counts --- sopel_modules/SpiceBot/Gif.py | 2 +- sopel_modules/SpiceBot/Read.py | 14 ++++++++++++-- .../SpiceBot_Core_Processing/StartupMonologue.py | 9 +++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 231462f..94708a7 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -60,11 +60,11 @@ class BotGif(): self.valid_api[gif_api]["apikey"] = apikey for validgifapi in list(self.valid_api.keys()): + botcommands.dict['counts'] += 1 command_dict = { "comtype": "gif_prefix", "validcoms": [validgifapi] } - botcommands.dict['counts'] += 1 botcommands.register(command_dict) def setup_gif(self): diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 0f3a056..c23dda5 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -15,8 +15,18 @@ class BotRead(): def __init__(self): self.dict = dict() - def config_dir(self): - return + def get_config_dirs(self, config_dir_name): + dir_to_scan = [] + for plugin_dir in set(sopel_modules.__path__): + configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") + cfgdir = os.path.join(configsdir, config_dir_name) + dir_to_scan.append(cfgdir) + + extradir = eval("botconfig." + config_dir_name) + if len(extradir): + for extracfgdir in extradir: + dir_to_scan.append(extracfgdir) + return dir_to_scan def json_to_dict(self, directories, configtypename="Config File", log_from='read_directory_json_to_dict', logging=True): diff --git a/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py b/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py index f8aafab..ec49264 100644 --- a/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py +++ b/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py @@ -33,10 +33,15 @@ def bot_startup_monologue_channels(bot, trigger): @sopel.module.event(SpiceBot.events.BOT_COMMANDS) @sopel.module.rule('.*') def bot_startup_monologue_commands(bot, trigger): - availablecomsnum, availablecomsfiles = 0, 0 + availablecomsnum, availablecomsfiles = 0, [] for commandstype in list(SpiceBot.commands.dict['commands'].keys()): availablecomsnum += len(list(SpiceBot.commands.dict['commands'][commandstype].keys())) - availablecomsfiles += SpiceBot.commands.dict['counts'] + for validcom in list(SpiceBot.commands.dict['commands'][commandstype].keys()): + if "filepath" in list(SpiceBot.commands.dict['commands'][commandstype][validcom].keys()): + filepath = SpiceBot.commands.dict['commands'][commandstype][validcom]["filepath"].lower() + if filepath not in availablecomsfiles: + availablecomsfiles.append(filepath) + availablecomsfiles = len(availablecomsfiles) displayval = "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files." SpiceBot.startupmonologue.dict["commands"] = displayval SpiceBot.logs.log('SpiceBot_StartupMonologue', displayval) From ef4bd6078ca0947af9ce025fedac6b9414184710 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 10:11:30 -0400 Subject: [PATCH 038/127] better --- sopel_modules/SpiceBot/Commands.py | 3 --- sopel_modules/SpiceBot/Gif.py | 10 +++------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index bd12f52..5243a09 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -260,9 +260,6 @@ class BotCommands(): if addnothing: currentsuccesslines += 0 - if currentsuccesslines: - self.dict['counts'] += 1 - if len(filelinelist): for vcomdict in filelinelist: self.register(vcomdict) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 94708a7..ca96b80 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -59,13 +59,9 @@ class BotGif(): if apikey: self.valid_api[gif_api]["apikey"] = apikey - for validgifapi in list(self.valid_api.keys()): - botcommands.dict['counts'] += 1 - command_dict = { - "comtype": "gif_prefix", - "validcoms": [validgifapi] - } - botcommands.register(command_dict) + self.valid_api[gif_api]["comtype"] = "gif_prefix" + self.valid_api[gif_api]["validcoms"] = [self.valid_api[gif_api]["filename"]] + botcommands.register(self.valid_api[gif_api]) def setup_gif(self): botconfig.define_section("SpiceBot_Gif", SpiceBot_Gif_MainSection, validate=False) From 55c5e32df97b2eb9296436560b481847c4ddae9f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 11:18:30 -0400 Subject: [PATCH 039/127] fetch config directories --- sopel_modules/SpiceBot/AI.py | 12 ++---------- sopel_modules/SpiceBot/DictComs.py | 16 +--------------- sopel_modules/SpiceBot/Gif.py | 12 +----------- sopel_modules/SpiceBot/Read.py | 18 +++++++++++++++--- sopel_modules/SpiceBot/Sherlock.py | 18 +++++++++++------- sopel_modules/SpiceBot/configure.py | 4 ++++ sopel_modules/SpiceBot/setup.py | 7 +++++++ 7 files changed, 41 insertions(+), 46 deletions(-) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index ccd0ea2..afa7dcd 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -13,6 +13,7 @@ import aiml from .Database import db as botdb from .Config import config as botconfig +from .Read import read as botread import spicemanip @@ -59,16 +60,7 @@ class SpiceBot_AI(): self.save_brain() def load_brain(self): - import sopel_modules - braindirs = [] - for plugin_dir in set(sopel_modules.__path__): - configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - aimldir = os.path.join(configsdir, "SpiceBot_AI") - braindirs.append(aimldir) - - if len(botconfig.SpiceBot_AI.extra): - for extrabraindir in botconfig.SpiceBot_AI.extra: - braindirs.append(extrabraindir) + braindirs = botread.get_config_dirs("SpiceBot_AI") # learn directories self.learn(braindirs) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index d5325d7..e2b8467 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -6,20 +6,14 @@ This is the SpiceBot JSON Commands system. This Class stores commands in an easy to access manner """ -import os - from sopel.config.types import StaticSection, ListAttribute -import sopel_modules from .Config import config as botconfig from .Read import read as botread from .Commands import commands as botcommands -import spicemanip - import requests from fake_useragent import UserAgent -from lxml import html import urllib @@ -40,15 +34,7 @@ class BotJSONCommands(): "feeds", "search" ] - dir_to_scan = [] - for plugin_dir in set(sopel_modules.__path__): - configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - gifcfgdir = os.path.join(configsdir, "SpiceBot_DictComs") - dir_to_scan.append(gifcfgdir) - - if len(botconfig.SpiceBot_DictComs.extra): - for extragifcfgdir in botconfig.SpiceBot_DictComs.extra: - dir_to_scan.append(extragifcfgdir) + dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index ca96b80..8b8cab0 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi """How to handle gifs""" from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -import sopel_modules from .Config import config as botconfig from .Read import read as botread @@ -11,7 +10,6 @@ from .Commands import commands as botcommands import spicemanip -import os from fake_useragent import UserAgent import urllib import random @@ -36,15 +34,7 @@ class BotGif(): self.header = {'User-Agent': str(UserAgent().chrome)} self.valid_api = {} - dir_to_scan = [] - for plugin_dir in set(sopel_modules.__path__): - configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - gifcfgdir = os.path.join(configsdir, "SpiceBot_Gif") - dir_to_scan.append(gifcfgdir) - - if len(botconfig.SpiceBot_Gif.extra): - for extragifcfgdir in botconfig.SpiceBot_Gif.extra: - dir_to_scan.append(extragifcfgdir) + dir_to_scan = botread.get_config_dirs("SpiceBot_Gif") valid_gif_api_dict = botread.json_to_dict(dir_to_scan, "Gif API", "SpiceBot_Gif") diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index c23dda5..9d0ecb5 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -17,15 +17,27 @@ class BotRead(): def get_config_dirs(self, config_dir_name): dir_to_scan = [] + + # check config directory stored within this project for plugin_dir in set(sopel_modules.__path__): configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") cfgdir = os.path.join(configsdir, config_dir_name) - dir_to_scan.append(cfgdir) + if os.path.exists(cfgdir) and os.path.isdir(cfgdir): + if len(os.listdir(cfgdir)) > 0: + dir_to_scan.append(cfgdir) - extradir = eval("botconfig." + config_dir_name) + # attempt to check for extra directories + try: + extradir = eval("botconfig." + config_dir_name + ".extra") + except Exception as e: + extradir = e + extradir = [] if len(extradir): for extracfgdir in extradir: - dir_to_scan.append(extracfgdir) + if os.path.exists(extracfgdir) and os.path.isdir(extracfgdir): + if len(os.listdir(extracfgdir)) > 0: + dir_to_scan.append(extracfgdir) + return dir_to_scan def json_to_dict(self, directories, configtypename="Config File", log_from='read_directory_json_to_dict', logging=True): diff --git a/sopel_modules/SpiceBot/Sherlock.py b/sopel_modules/SpiceBot/Sherlock.py index 2ae66ed..f525b13 100644 --- a/sopel_modules/SpiceBot/Sherlock.py +++ b/sopel_modules/SpiceBot/Sherlock.py @@ -2,27 +2,28 @@ from __future__ import unicode_literals, absolute_import, division, print_function """A way to search google""" -import sopel_modules +from sopel.config.types import StaticSection, ListAttribute from .Read import read as botread +from .Config import config as botconfig -import os from fake_useragent import UserAgent import requests import time +class SpiceBot_Sherlock_MainSection(StaticSection): + extra = ListAttribute('extra') + + class Sherlock(): def __init__(self): + self.setup_sherlock() self.header = {'User-Agent': str(UserAgent().chrome)} self.dict = {} - dir_to_scan = [] - for plugin_dir in set(sopel_modules.__path__): - configsdir = os.path.join(plugin_dir, "SpiceBot_Configs") - usercfgdir = os.path.join(configsdir, "SpiceBot_Sherlock") - dir_to_scan.append(usercfgdir) + dir_to_scan = botread.get_config_dirs("SpiceBot_Sherlock") valid_usernames_dict = botread.json_to_dict(dir_to_scan, "Sherlock", "SpiceBot_Sherlock") @@ -30,6 +31,9 @@ class Sherlock(): self.dict[social_network] = valid_usernames_dict[social_network] self.dict[social_network]["cache"] = dict() + def setup_sherlock(self): + botconfig.define_section("SpiceBot_Sherlock", SpiceBot_Sherlock_MainSection, validate=False) + def check_network(self, username, social_network): username = str(username).lower() diff --git a/sopel_modules/SpiceBot/configure.py b/sopel_modules/SpiceBot/configure.py index 473258b..9e59a47 100644 --- a/sopel_modules/SpiceBot/configure.py +++ b/sopel_modules/SpiceBot/configure.py @@ -10,6 +10,7 @@ from .Update import SpiceBot_Update_MainSection from .Gif import SpiceBot_Gif_MainSection from .DictComs import SpiceBot_DictComs_MainSection from .Reddit import SpiceBot_Reddit_MainSection +from .Sherlock import SpiceBot_Sherlock_MainSection from .Kick import SpiceBot_Kick from .osd import SpiceBot_OSD @@ -58,3 +59,6 @@ def configure(config): config.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) config.SpiceBot_DictComs.configure_setting('extra', 'SpiceBot_DictComs API Extra directory') + + config.define_section("SpiceBot_Sherlock", SpiceBot_Sherlock_MainSection, validate=False) + config.SpiceBot_Sherlock.configure_setting('extra', 'SpiceBot_Sherlock API Extra directory') diff --git a/sopel_modules/SpiceBot/setup.py b/sopel_modules/SpiceBot/setup.py index e3038b8..36a4c39 100644 --- a/sopel_modules/SpiceBot/setup.py +++ b/sopel_modules/SpiceBot/setup.py @@ -20,6 +20,7 @@ from .osd import SopelWrapperOSD, ToolsOSD, SopelOSD, SpiceBot_OSD from .Kick import SopelWrapperKICK, SopelKICK, SpiceBot_Kick from .Gif import SpiceBot_Gif_MainSection from .DictComs import SpiceBot_DictComs_MainSection +from .Sherlock import SpiceBot_Sherlock_MainSection from .AI import SpiceBot_AI_MainSection @@ -61,6 +62,8 @@ def setup(bot): setup_dictcoms(bot) + setup_sherlock(bot) + def setup_config(bot): logs.log('SpiceBot_Config', "Setting Up Configuration") @@ -159,3 +162,7 @@ def setup_reddit(bot): def setup_dictcoms(bot): bot.config.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) + + +def setup_sherlock(bot): + bot.config.define_section("SpiceBot_Sherlock", SpiceBot_Sherlock_MainSection, validate=False) From 23faf6e4d215ad0a03c74fcfc9670ca595a83c1c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 11:58:55 -0400 Subject: [PATCH 040/127] add folder values --- sopel_modules/SpiceBot/Commands.py | 6 +++++- sopel_modules/SpiceBot/DictComs.py | 4 +--- sopel_modules/SpiceBot/Read.py | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 5243a09..5194f62 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -195,6 +195,8 @@ class BotCommands(): slashsplit = str(modulefile).split("/") filename = slashsplit[-1] filename_base = os.path.basename(filename).rsplit('.', 1)[0] + folderpath = str(modulefile).split("/" + filename)[0] + foldername = str(folderpath).split("/")[-1] detected_lines = [] for line in module_file_lines: @@ -251,7 +253,9 @@ class BotCommands(): "comtype": comtype, "validcoms": validcoms, "filepath": str(modulefile), - "filename": filename_base, + "filename": str(filename_base), + "folderpath": str(folderpath), + "foldername": str(foldername), } filelinelist.append(validcomdict) currentsuccesslines += 1 diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index e2b8467..098c20f 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -64,9 +64,7 @@ class BotJSONCommands(): # check that type is set, use cases will inherit this if not set if "type" not in list(dict_from_file.keys()): - foldername = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0] - foldername = str(foldername).split("/")[-1] - dict_from_file["type"] = foldername + dict_from_file["type"] = dict_from_file["foldername"] if dict_from_file["type"] not in self.valid_com_types: dict_from_file["type"] = 'simple' diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 9d0ecb5..95473e3 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -82,6 +82,8 @@ class BotRead(): filecount += 1 dict_from_file["filepath"] = str(filepath) dict_from_file["filename"] = str(filename_base) + dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0] + dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1] configs_dict[filename_base] = dict_from_file if filecount: From f1cbe5edba78fd8ddb5d877305d4de5f113c0195 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 13:33:16 -0400 Subject: [PATCH 041/127] ready for live testing maybe --- sopel_modules/SpiceBot/Commands.py | 34 ++++++------ sopel_modules/SpiceBot/DictComs.py | 38 +------------- sopel_modules/SpiceBot/Read.py | 83 ++++++++++++++++++++++++++++++ sopel_modules/SpiceBot/__init__.py | 2 +- 4 files changed, 103 insertions(+), 54 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 5194f62..092f526 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -13,10 +13,12 @@ import os import threading import spicemanip +import sopel_modules from .Logs import logs from .Config import config as botconfig from .Database import db as botdb +from .Read import read as botread class SpiceBot_Commands_MainSection(StaticSection): @@ -29,7 +31,6 @@ class BotCommands(): self.setup_commands() self.lock = threading.Lock() self.dict = { - "counts": 0, 'nickrules': [], 'nickaiml': [], "commands": { @@ -145,14 +146,10 @@ class BotCommands(): filepathlisting.append(home_modules_dir) # pypi installed - try: - import sopel_modules - for plugin_dir in set(sopel_modules.__path__): - for pathname in os.listdir(plugin_dir): - pypi_modules_dir = os.path.join(plugin_dir, pathname) - filepathlisting.append(pypi_modules_dir) - except Exception as e: - logs.log('SpiceBOT_COMMANDS', "sopel_modules not loaded :" + str(e)) + for plugin_dir in set(sopel_modules.__path__): + for pathname in os.listdir(plugin_dir): + pypi_modules_dir = os.path.join(plugin_dir, pathname) + filepathlisting.append(pypi_modules_dir) # Extra directories for directory in botconfig.extra: @@ -198,6 +195,15 @@ class BotCommands(): folderpath = str(modulefile).split("/" + filename)[0] foldername = str(folderpath).split("/")[-1] + # check for json reference file + validcomdict = botread.module_json_to_dict(str(modulefile)) + + # replace json defaults + validcomdict["filepath"] = str(modulefile) + validcomdict["filename"] = str(filename_base) + validcomdict["folderpath"] = str(folderpath) + validcomdict["foldername"] = str(foldername) + detected_lines = [] for line in module_file_lines: @@ -249,14 +255,8 @@ class BotCommands(): validcoms.remove(regexcom) if len(validcoms): - validcomdict = { - "comtype": comtype, - "validcoms": validcoms, - "filepath": str(modulefile), - "filename": str(filename_base), - "folderpath": str(folderpath), - "foldername": str(foldername), - } + validcomdict["comtype"] = comtype + validcomdict["validcoms"] = validcoms filelinelist.append(validcomdict) currentsuccesslines += 1 except Exception as e: diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 098c20f..833010d 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -63,47 +63,13 @@ class BotJSONCommands(): dict_from_file[var] = tuple_contents_bak # check that type is set, use cases will inherit this if not set - if "type" not in list(dict_from_file.keys()): - dict_from_file["type"] = dict_from_file["foldername"] - if dict_from_file["type"] not in self.valid_com_types: + if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types: dict_from_file["type"] = 'simple' # Don't process these. keysprocessed = [] keysprocessed.extend(["validcoms", "filepath", "filename"]) - - # the command must have an author - if "author" not in list(dict_from_file.keys()): - dict_from_file["author"] = "deathbybandaid" - keysprocessed.append("author") - - # the command must have a contributors list - if "contributors" not in list(dict_from_file.keys()): - dict_from_file["contributors"] = [] - if not isinstance(dict_from_file["contributors"], list): - dict_from_file["contributors"] = [dict_from_file["contributors"]] - if "deathbybandaid" not in dict_from_file["contributors"]: - dict_from_file["contributors"].append("deathbybandaid") - if dict_from_file["author"] not in dict_from_file["contributors"]: - dict_from_file["contributors"].append(dict_from_file["author"]) - keysprocessed.append("contributors") - - if "hardcoded_channel_block" not in list(dict_from_file.keys()): - dict_from_file["hardcoded_channel_block"] = [] - keysprocessed.append("hardcoded_channel_block") - - if "example" not in list(dict_from_file.keys()): - dict_from_file["example"] = str(botconfig.core.prefix_list[0] + maincom) - - if "exampleresponse" not in list(dict_from_file.keys()): - dict_from_file["exampleresponse"] = None - - if "description" not in list(dict_from_file.keys()): - dict_from_file["description"] = None - - if "privs" not in list(dict_from_file.keys()): - dict_from_file["privs"] = [] - + keysprocessed.append("author", "contributors") keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"]) # handle basic required dict handling diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 95473e3..0aecded 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -8,6 +8,7 @@ import os import codecs from .Logs import logs +from .Config import config as botconfig class BotRead(): @@ -84,6 +85,7 @@ class BotRead(): dict_from_file["filename"] = str(filename_base) dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0] dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1] + dict_from_file = self.command_defaults(dict_from_file) configs_dict[filename_base] = dict_from_file if filecount: @@ -96,5 +98,86 @@ class BotRead(): return configs_dict + def module_json_to_dict(self, filepath, logging=True): + + # gather file stats + slashsplit = str(filepath).split("/") + filename = slashsplit[-1] + filename_base = os.path.basename(filename).rsplit('.', 1)[0] + folderpath = str(filepath).split("/" + filename)[0] + + jsonpath = os.path.join(folderpath, filename_base + ".json") + if os.path.exists(jsonpath) and os.path.isfile(jsonpath): + + # Read dictionary from file, if not, enable an empty dict + filereadgood = True + inf = codecs.open(filepath, "r", encoding='utf-8') + infread = inf.read() + try: + dict_from_file = eval(infread) + except Exception as e: + filereadgood = False + if logging: + logs.log("SpiceBot_Modules", "Error loading %s: %s (%s)" % ("Module Commands", e, filepath)) + dict_from_file = dict() + # Close File + inf.close() + + # gather file stats + slashsplit = str(filepath).split("/") + filename = slashsplit[-1] + filename_base = os.path.basename(filename).rsplit('.', 1)[0] + + if not filereadgood or not isinstance(dict_from_file, dict): + dict_from_file = {} + else: + dict_from_file["filepath"] = str(filepath) + dict_from_file["filename"] = str(filename_base) + dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0] + dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1] + dict_from_file = self.command_defaults(dict_from_file) + else: + dict_from_file = {} + + dict_from_file = self.command_defaults(dict_from_file) + return dict_from_file + + def command_defaults(self, dict_from_file): + + # the command must have an author + if "author" not in list(dict_from_file.keys()): + dict_from_file["author"] = "deathbybandaid" + + # the command must have a contributors list + if "contributors" not in list(dict_from_file.keys()): + dict_from_file["contributors"] = [] + if not isinstance(dict_from_file["contributors"], list): + dict_from_file["contributors"] = [dict_from_file["contributors"]] + if "deathbybandaid" not in dict_from_file["contributors"]: + dict_from_file["contributors"].append("deathbybandaid") + if dict_from_file["author"] not in dict_from_file["contributors"]: + dict_from_file["contributors"].append(dict_from_file["author"]) + + if "example" not in list(dict_from_file.keys()): + dict_from_file["example"] = "$maincom" + # TODO + #if dict_from_file["comtype"] == "nickname": + # dict_from_file["example"] = str(botconfig.nick + " $maincom") + # else: + # dict_from_file["example"] = str(botconfig.core.prefix_list[0] + "$maincom") + if not dict_from_file["example"].startswith("$maincom"): + dict_from_file["example"] = "$maincom " + dict_from_file["example"] + + if "exampleresponse" not in list(dict_from_file.keys()): + dict_from_file["exampleresponse"] = None + + if "description" not in list(dict_from_file.keys()): + dict_from_file["description"] = None + + if "privs" not in list(dict_from_file.keys()): + dict_from_file["privs"] = [] + + return dict_from_file + read = BotRead() diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index f051b6c..31db45c 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -26,7 +26,7 @@ from .Google import * from .Gif import * from .Sherlock import * from .Reddit import * -# from .DictComs import * +from .DictComs import * from .Read import * From 7e19896b48f213ef5e1d44a8faac7ebe335bc3c6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 13:34:54 -0400 Subject: [PATCH 042/127] import funky --- sopel_modules/SpiceBot/Read.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 0aecded..4d3f0cc 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -29,6 +29,7 @@ class BotRead(): # attempt to check for extra directories try: + extradir = botconfig.extra extradir = eval("botconfig." + config_dir_name + ".extra") except Exception as e: extradir = e From 79c07345d96209dc788767d82ff1466982c91553 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 13:45:30 -0400 Subject: [PATCH 043/127] test --- sopel_modules/SpiceBot/DictComs.py | 2 +- .../SpiceBot_DictComs/bandaid | 8 ++++++++ .../SpiceBot_Core_Commands/DictComs.py | 20 +++++++++++++++++++ .../SpiceBot_Core_Commands/__init__.py | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid create mode 100644 sopel_modules/SpiceBot_Core_Commands/DictComs.py diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 833010d..f3c1731 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -40,7 +40,7 @@ class BotJSONCommands(): for dict_from_file in list(valid_dictcom_dict.keys()): - dict_from_file["comtype"] = "prefix_command" + dict_from_file["comtype"] = "prefix" # default command to filename if "validcoms" not in list(dict_from_file.keys()): diff --git a/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid b/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid new file mode 100644 index 0000000..6d58dd2 --- /dev/null +++ b/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid @@ -0,0 +1,8 @@ +{ + +"?default": { + "type": "simple", + "responses": ["Bandaids? You mean bitch stickers??"], + }, + +} diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py new file mode 100644 index 0000000..7e73204 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -0,0 +1,20 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot DictCom system +""" + +# sopel imports +import sopel.module + +import sopel_modules.SpiceBot as SpiceBot + + +@SpiceBot.prerun.prerun('prefix') +@sopel.module.nickname_commands('(.*)') +def bot_command_dictcom(bot, trigger): + + if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()): + return + + bot.say("here") diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index 6ec62d5..e4b9d44 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -21,6 +21,7 @@ from .AI import * from .Gif import * from .Sherlock import * from .Reddit import * +from .DictComs import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From ecd5b0879c08e41058b0c12dc7a2f2e0d187b6c2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:15:38 -0400 Subject: [PATCH 044/127] test --- sopel_modules/SpiceBot/DictComs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index f3c1731..cb8aa2d 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -16,6 +16,8 @@ import requests from fake_useragent import UserAgent import urllib +import sys + class SpiceBot_DictComs_MainSection(StaticSection): extra = ListAttribute('extra') @@ -35,8 +37,10 @@ class BotJSONCommands(): ] dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") + sys.stderr.write(dir_to_scan) valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") + sys.stderr.write(valid_dictcom_dict) for dict_from_file in list(valid_dictcom_dict.keys()): From e5464a7fd292d13c7ba76d62948b9326cb94c5b0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:18:17 -0400 Subject: [PATCH 045/127] test --- sopel_modules/SpiceBot/DictComs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index cb8aa2d..7e12caa 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -27,6 +27,7 @@ class BotJSONCommands(): """This Logs all commands known to the bot""" def __init__(self): def __init__(self): + sys.stderr.write("[here] test 1 2 2") self.setup_dictcoms() self.header = {'User-Agent': str(UserAgent().chrome)} self.valid_com_types = [ From 49a962295abc6f063e3f4c67000c95e4d2b56fa0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:22:55 -0400 Subject: [PATCH 046/127] test --- sopel_modules/SpiceBot/DictComs.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 7e12caa..974a569 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -16,18 +16,14 @@ import requests from fake_useragent import UserAgent import urllib -import sys - class SpiceBot_DictComs_MainSection(StaticSection): extra = ListAttribute('extra') class BotJSONCommands(): - """This Logs all commands known to the bot""" def __init__(self): def __init__(self): - sys.stderr.write("[here] test 1 2 2") self.setup_dictcoms() self.header = {'User-Agent': str(UserAgent().chrome)} self.valid_com_types = [ @@ -38,12 +34,10 @@ class BotJSONCommands(): ] dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") - sys.stderr.write(dir_to_scan) - valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") - sys.stderr.write(valid_dictcom_dict) + self.valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") - for dict_from_file in list(valid_dictcom_dict.keys()): + for dict_from_file in list(self.valid_dictcom_dict.keys()): dict_from_file["comtype"] = "prefix" From d05b16c3f87056414e126722d3a48a3b280949c4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:23:37 -0400 Subject: [PATCH 047/127] oh man --- sopel_modules/SpiceBot/DictComs.py | 405 ++++++++++++++--------------- 1 file changed, 202 insertions(+), 203 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 974a569..7fb66b3 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -23,236 +23,235 @@ class SpiceBot_DictComs_MainSection(StaticSection): class BotJSONCommands(): def __init__(self): - def __init__(self): - self.setup_dictcoms() - self.header = {'User-Agent': str(UserAgent().chrome)} - self.valid_com_types = [ - 'simple', 'fillintheblank', 'targetplusreason', - 'sayings', "readfromfile", "readfromurl", - "ascii_art", "gif", "translate", "responses", - "feeds", "search" - ] + self.setup_dictcoms() + self.header = {'User-Agent': str(UserAgent().chrome)} + self.valid_com_types = [ + 'simple', 'fillintheblank', 'targetplusreason', + 'sayings', "readfromfile", "readfromurl", + "ascii_art", "gif", "translate", "responses", + "feeds", "search" + ] - dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") + dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") - self.valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") + self.valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") - for dict_from_file in list(self.valid_dictcom_dict.keys()): + for dict_from_file in list(self.valid_dictcom_dict.keys()): - dict_from_file["comtype"] = "prefix" + dict_from_file["comtype"] = "prefix" - # default command to filename - if "validcoms" not in list(dict_from_file.keys()): - dict_from_file["validcoms"] = [dict_from_file["filename"]] - elif dict_from_file["validcoms"] == []: - dict_from_file["validcoms"] = [dict_from_file["filename"]] - elif not isinstance(dict_from_file['validcoms'], list): - dict_from_file["validcoms"] = [dict_from_file["validcoms"]] + # default command to filename + if "validcoms" not in list(dict_from_file.keys()): + dict_from_file["validcoms"] = [dict_from_file["filename"]] + elif dict_from_file["validcoms"] == []: + dict_from_file["validcoms"] = [dict_from_file["filename"]] + elif not isinstance(dict_from_file['validcoms'], list): + dict_from_file["validcoms"] = [dict_from_file["validcoms"]] - maincom = dict_from_file["validcoms"][0] + maincom = dict_from_file["validcoms"][0] - # check for tuple dict keys and split - validkeys = [x for x in list(dict_from_file.keys())] - for validkey in validkeys: - if isinstance(validkey, tuple): - tuple_bak = validkey - tuple_contents_bak = dict_from_file[validkey] - del dict_from_file[validkey] - for var in tuple_bak: - dict_from_file[var] = tuple_contents_bak + # check for tuple dict keys and split + validkeys = [x for x in list(dict_from_file.keys())] + for validkey in validkeys: + if isinstance(validkey, tuple): + tuple_bak = validkey + tuple_contents_bak = dict_from_file[validkey] + del dict_from_file[validkey] + for var in tuple_bak: + dict_from_file[var] = tuple_contents_bak - # check that type is set, use cases will inherit this if not set - if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types: - dict_from_file["type"] = 'simple' + # check that type is set, use cases will inherit this if not set + if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types: + dict_from_file["type"] = 'simple' - # Don't process these. - keysprocessed = [] - keysprocessed.extend(["validcoms", "filepath", "filename"]) - keysprocessed.append("author", "contributors") - keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"]) + # Don't process these. + keysprocessed = [] + keysprocessed.extend(["validcoms", "filepath", "filename"]) + keysprocessed.append("author", "contributors") + keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"]) - # handle basic required dict handling - dict_required = ["?default"] - dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, dict_required) - keysprocessed.extend(dict_required) + # handle basic required dict handling + dict_required = ["?default"] + dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, dict_required) + keysprocessed.extend(dict_required) - # remove later - keysprocessed.append("type") + # remove later + keysprocessed.append("type") - # all other keys not processed above are considered potential use cases - otherkeys = [] - for otherkey in list(dict_from_file.keys()): - if otherkey not in keysprocessed: - otherkeys.append(otherkey) - if otherkeys != []: - dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, otherkeys) - keysprocessed.extend(otherkeys) + # all other keys not processed above are considered potential use cases + otherkeys = [] + for otherkey in list(dict_from_file.keys()): + if otherkey not in keysprocessed: + otherkeys.append(otherkey) + if otherkeys != []: + dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, otherkeys) + keysprocessed.extend(otherkeys) - botcommands.register(dict_from_file) + botcommands.register(dict_from_file) - def bot_dict_use_cases(self, maincom, dict_from_file, process_list): + def bot_dict_use_cases(self, maincom, dict_from_file, process_list): - for mustbe in process_list: + for mustbe in process_list: - # All of the above need to be in the dict if not - if mustbe not in list(dict_from_file.keys()): - dict_from_file[mustbe] = dict() + # All of the above need to be in the dict if not + if mustbe not in list(dict_from_file.keys()): + dict_from_file[mustbe] = dict() - # verify if already there, that the key is a dict - if not isinstance(dict_from_file[mustbe], dict): - dict_from_file[mustbe] = dict() + # verify if already there, that the key is a dict + if not isinstance(dict_from_file[mustbe], dict): + dict_from_file[mustbe] = dict() - # Each usecase for the command must have a type, flat files inherit this type - if "type" not in list(dict_from_file[mustbe].keys()): - if "type" in list(dict_from_file.keys()): - dict_from_file[mustbe]["type"] = dict_from_file["type"] + # Each usecase for the command must have a type, flat files inherit this type + if "type" not in list(dict_from_file[mustbe].keys()): + if "type" in list(dict_from_file.keys()): + dict_from_file[mustbe]["type"] = dict_from_file["type"] + else: + dict_from_file[mustbe]["type"] = "simple" + + # each usecase needs to know if it can be updated. Default is false + if "updates_enabled" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["updates_enabled"] = False + if dict_from_file[mustbe]["updates_enabled"]: + if dict_from_file[mustbe]["updates_enabled"] not in ["shared", "user"]: + dict_from_file[mustbe]["updates_enabled"] = "shared" + + # each usecase needs to know if it needs a target + if "target_required" not in list(dict_from_file[mustbe].keys()): + if dict_from_file[mustbe]["type"] in ['target', 'targetplusreason']: + dict_from_file[mustbe]["target_required"] = True + else: + dict_from_file[mustbe]["target_required"] = False + if "target_backup" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["target_backup"] = False + if "target_bypass" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["target_bypass"] = [] + + # special target reactions + for reason in ['self', 'bot', 'bots', 'offline', 'unknown', 'privmsg', 'diffchannel', 'diffbot']: + if 'react_'+reason not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]['react_'+reason] = False + + # each usecase needs to know if it needs input for fillintheblank + if "blank_required" not in list(dict_from_file[mustbe].keys()): + if dict_from_file[mustbe]["type"] in ['fillintheblank', 'targetplusreason', "translate"]: + dict_from_file[mustbe]["blank_required"] = True + else: + dict_from_file[mustbe]["blank_required"] = False + if "blank_backup" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["blank_backup"] = False + if "blank_fail" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["blank_fail"] = ["This command requires input."] + if not isinstance(dict_from_file[mustbe]["blank_fail"], list): + dict_from_file[mustbe]["blank_fail"] = [dict_from_file[mustbe]["blank_fail"]] + + if "blank_phrasehandle" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["blank_phrasehandle"] = False + if dict_from_file[mustbe]["blank_phrasehandle"]: + if not isinstance(dict_from_file[mustbe]["blank_phrasehandle"], list): + dict_from_file[mustbe]["blank_phrasehandle"] = [dict_from_file[mustbe]["blank_phrasehandle"]] + + if "response_fail" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["response_fail"] = False + if dict_from_file[mustbe]["response_fail"]: + if not isinstance(dict_from_file[mustbe]["response_fail"], list): + dict_from_file[mustbe]["response_fail"] = [dict_from_file[mustbe]["response_fail"]] + + # if dict_from_file[mustbe]["updates_enabled"]: + # adjust_nick_array(bot, str(bot.nick), 'long', 'sayings', maincom + "_" + str(mustbe), dict_from_file[mustbe]["responses"], 'startup') + # dict_from_file[mustbe]["responses"] = get_nick_value(bot, str(bot.nick), 'long', 'sayings', maincom + "_" + str(mustbe)) or [] + + # each usecase needs a response + if "responses" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["responses"] = [] + + # verify responses are in list form + if not isinstance(dict_from_file[mustbe]["responses"], list): + # TODO read text files + # if dict_from_file[mustbe]["responses"] in bot.memory["botdict"]["tempvals"]['txt_files'].keys(): + # dict_from_file[mustbe]["responses"] = bot.memory["botdict"]["tempvals"]['txt_files'][dict_from_file[mustbe]["responses"]] + if str(dict_from_file[mustbe]["responses"]).startswith(tuple(["https://", "http://"])): + try: + page = requests.get(dict_from_file[mustbe]["responses"], headers=self.header) + except Exception as e: + page = e + page = None + + if page and not str(page.status_code).startswith(tuple(["4", "5"])): + htmlfile = urllib.request.urlopen(dict_from_file[mustbe]["responses"]) + lines = htmlfile.read().splitlines() + dict_from_file[mustbe]["responses"] = lines + else: + dict_from_file[mustbe]["responses"] = [dict_from_file[mustbe]["responses"]] + + # each usecase needs a prefixtext + if "prefixtext" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["prefixtext"] = False + if dict_from_file[mustbe]["prefixtext"]: + if not isinstance(dict_from_file[mustbe]["prefixtext"], list): + dict_from_file[mustbe]["prefixtext"] = [dict_from_file[mustbe]["prefixtext"]] + + # each usecase needs a suffixtext + if "suffixtext" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["suffixtext"] = False + if dict_from_file[mustbe]["suffixtext"]: + if not isinstance(dict_from_file[mustbe]["suffixtext"], list): + dict_from_file[mustbe]["suffixtext"] = [dict_from_file[mustbe]["suffixtext"]] + + # Translations + if "translations" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["translations"] = False + if dict_from_file[mustbe]["translations"]: + if not isinstance(dict_from_file[mustbe]["translations"], list): + dict_from_file[mustbe]["translations"] = [dict_from_file[mustbe]["translations"]] + + # make sure we have the smaller variation list + if "replyvariation" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["replyvariation"] = [] + if not isinstance(dict_from_file[mustbe]["replyvariation"], list): + dict_from_file[mustbe]["replyvariation"] = [dict_from_file[mustbe]["replyvariation"]] + + # This is to provide functionality for flat dictionaries responses + if dict_from_file[mustbe]["responses"] == [] and mustbe == "?default": + if "responses" in list(dict_from_file.keys()): + if isinstance(dict_from_file["responses"], list): + dict_from_file[mustbe]["responses"].extend(dict_from_file["responses"]) else: - dict_from_file[mustbe]["type"] = "simple" + dict_from_file[mustbe]["responses"].append(dict_from_file["responses"]) + del dict_from_file["responses"] - # each usecase needs to know if it can be updated. Default is false - if "updates_enabled" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["updates_enabled"] = False - if dict_from_file[mustbe]["updates_enabled"]: - if dict_from_file[mustbe]["updates_enabled"] not in ["shared", "user"]: - dict_from_file[mustbe]["updates_enabled"] = "shared" + # Verify responses list is not empty + if dict_from_file[mustbe]["responses"] == []: + dict_from_file[mustbe]["responses"].append("No " + str(mustbe) + " responses set for " + str(maincom) + ".") - # each usecase needs to know if it needs a target - if "target_required" not in list(dict_from_file[mustbe].keys()): - if dict_from_file[mustbe]["type"] in ['target', 'targetplusreason']: - dict_from_file[mustbe]["target_required"] = True - else: - dict_from_file[mustbe]["target_required"] = False - if "target_backup" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["target_backup"] = False - if "target_bypass" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["target_bypass"] = [] + # Some commands run query mode + if "search_fail" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["search_fail"] = None + if dict_from_file[mustbe]["search_fail"]: + if not isinstance(dict_from_file[mustbe]["search_fail"], list): + dict_from_file[mustbe]["search_fail"] = [dict_from_file[mustbe]["search_fail"]] - # special target reactions - for reason in ['self', 'bot', 'bots', 'offline', 'unknown', 'privmsg', 'diffchannel', 'diffbot']: - if 'react_'+reason not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]['react_'+reason] = False + if "selection_allowed" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["selection_allowed"] = True - # each usecase needs to know if it needs input for fillintheblank - if "blank_required" not in list(dict_from_file[mustbe].keys()): - if dict_from_file[mustbe]["type"] in ['fillintheblank', 'targetplusreason', "translate"]: - dict_from_file[mustbe]["blank_required"] = True - else: - dict_from_file[mustbe]["blank_required"] = False - if "blank_backup" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["blank_backup"] = False - if "blank_fail" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["blank_fail"] = ["This command requires input."] - if not isinstance(dict_from_file[mustbe]["blank_fail"], list): - dict_from_file[mustbe]["blank_fail"] = [dict_from_file[mustbe]["blank_fail"]] + # Translations + if "randnum" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["randnum"] = False + if dict_from_file[mustbe]["randnum"]: + if not isinstance(dict_from_file[mustbe]["randnum"], list): + dict_from_file[mustbe]["randnum"] = [0, 50] + if len(dict_from_file[mustbe]["randnum"]) == 1: + dict_from_file[mustbe]["randnum"] = [0, dict_from_file[mustbe]["randnum"][0]] - if "blank_phrasehandle" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["blank_phrasehandle"] = False - if dict_from_file[mustbe]["blank_phrasehandle"]: - if not isinstance(dict_from_file[mustbe]["blank_phrasehandle"], list): - dict_from_file[mustbe]["blank_phrasehandle"] = [dict_from_file[mustbe]["blank_phrasehandle"]] + if "hardcoded_channel_block" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["hardcoded_channel_block"] = [] - if "response_fail" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["response_fail"] = False - if dict_from_file[mustbe]["response_fail"]: - if not isinstance(dict_from_file[mustbe]["response_fail"], list): - dict_from_file[mustbe]["response_fail"] = [dict_from_file[mustbe]["response_fail"]] + if "privs" not in list(dict_from_file[mustbe].keys()): + dict_from_file[mustbe]["privs"] = [] - # if dict_from_file[mustbe]["updates_enabled"]: - # adjust_nick_array(bot, str(bot.nick), 'long', 'sayings', maincom + "_" + str(mustbe), dict_from_file[mustbe]["responses"], 'startup') - # dict_from_file[mustbe]["responses"] = get_nick_value(bot, str(bot.nick), 'long', 'sayings', maincom + "_" + str(mustbe)) or [] + return dict_from_file - # each usecase needs a response - if "responses" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["responses"] = [] - - # verify responses are in list form - if not isinstance(dict_from_file[mustbe]["responses"], list): - # TODO read text files - # if dict_from_file[mustbe]["responses"] in bot.memory["botdict"]["tempvals"]['txt_files'].keys(): - # dict_from_file[mustbe]["responses"] = bot.memory["botdict"]["tempvals"]['txt_files'][dict_from_file[mustbe]["responses"]] - if str(dict_from_file[mustbe]["responses"]).startswith(tuple(["https://", "http://"])): - try: - page = requests.get(dict_from_file[mustbe]["responses"], headers=self.header) - except Exception as e: - page = e - page = None - - if page and not str(page.status_code).startswith(tuple(["4", "5"])): - htmlfile = urllib.request.urlopen(dict_from_file[mustbe]["responses"]) - lines = htmlfile.read().splitlines() - dict_from_file[mustbe]["responses"] = lines - else: - dict_from_file[mustbe]["responses"] = [dict_from_file[mustbe]["responses"]] - - # each usecase needs a prefixtext - if "prefixtext" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["prefixtext"] = False - if dict_from_file[mustbe]["prefixtext"]: - if not isinstance(dict_from_file[mustbe]["prefixtext"], list): - dict_from_file[mustbe]["prefixtext"] = [dict_from_file[mustbe]["prefixtext"]] - - # each usecase needs a suffixtext - if "suffixtext" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["suffixtext"] = False - if dict_from_file[mustbe]["suffixtext"]: - if not isinstance(dict_from_file[mustbe]["suffixtext"], list): - dict_from_file[mustbe]["suffixtext"] = [dict_from_file[mustbe]["suffixtext"]] - - # Translations - if "translations" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["translations"] = False - if dict_from_file[mustbe]["translations"]: - if not isinstance(dict_from_file[mustbe]["translations"], list): - dict_from_file[mustbe]["translations"] = [dict_from_file[mustbe]["translations"]] - - # make sure we have the smaller variation list - if "replyvariation" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["replyvariation"] = [] - if not isinstance(dict_from_file[mustbe]["replyvariation"], list): - dict_from_file[mustbe]["replyvariation"] = [dict_from_file[mustbe]["replyvariation"]] - - # This is to provide functionality for flat dictionaries responses - if dict_from_file[mustbe]["responses"] == [] and mustbe == "?default": - if "responses" in list(dict_from_file.keys()): - if isinstance(dict_from_file["responses"], list): - dict_from_file[mustbe]["responses"].extend(dict_from_file["responses"]) - else: - dict_from_file[mustbe]["responses"].append(dict_from_file["responses"]) - del dict_from_file["responses"] - - # Verify responses list is not empty - if dict_from_file[mustbe]["responses"] == []: - dict_from_file[mustbe]["responses"].append("No " + str(mustbe) + " responses set for " + str(maincom) + ".") - - # Some commands run query mode - if "search_fail" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["search_fail"] = None - if dict_from_file[mustbe]["search_fail"]: - if not isinstance(dict_from_file[mustbe]["search_fail"], list): - dict_from_file[mustbe]["search_fail"] = [dict_from_file[mustbe]["search_fail"]] - - if "selection_allowed" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["selection_allowed"] = True - - # Translations - if "randnum" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["randnum"] = False - if dict_from_file[mustbe]["randnum"]: - if not isinstance(dict_from_file[mustbe]["randnum"], list): - dict_from_file[mustbe]["randnum"] = [0, 50] - if len(dict_from_file[mustbe]["randnum"]) == 1: - dict_from_file[mustbe]["randnum"] = [0, dict_from_file[mustbe]["randnum"][0]] - - if "hardcoded_channel_block" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["hardcoded_channel_block"] = [] - - if "privs" not in list(dict_from_file[mustbe].keys()): - dict_from_file[mustbe]["privs"] = [] - - return dict_from_file - - def setup_dictcoms(self): - botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) + def setup_dictcoms(self): + botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) jsoncommands = BotJSONCommands() From 07b6fa3f3933fe82cb37a45c6288e913694d89a2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:25:51 -0400 Subject: [PATCH 048/127] test --- sopel_modules/SpiceBot/DictComs.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 7fb66b3..13137a3 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -16,12 +16,15 @@ import requests from fake_useragent import UserAgent import urllib +import sys + class SpiceBot_DictComs_MainSection(StaticSection): extra = ListAttribute('extra') class BotJSONCommands(): + def __init__(self): self.setup_dictcoms() self.header = {'User-Agent': str(UserAgent().chrome)} @@ -33,10 +36,11 @@ class BotJSONCommands(): ] dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") + sys.stderr.write(dir_to_scan) - self.valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") + valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") - for dict_from_file in list(self.valid_dictcom_dict.keys()): + for dict_from_file in list(valid_dictcom_dict.keys()): dict_from_file["comtype"] = "prefix" From d6e00fc85fb1286ab24bbafc7cb9c25c420fd327 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:28:07 -0400 Subject: [PATCH 049/127] test --- sopel_modules/SpiceBot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index 31db45c..f051b6c 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -26,7 +26,7 @@ from .Google import * from .Gif import * from .Sherlock import * from .Reddit import * -from .DictComs import * +# from .DictComs import * from .Read import * From 98f9cb0fbb0479c98bb2beeb9aaa25ea7afe86a4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:34:11 -0400 Subject: [PATCH 050/127] test --- sopel_modules/SpiceBot/Read.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 4d3f0cc..b637462 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -61,9 +61,9 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True - inf = codecs.open(filepath, "r", encoding='utf-8') - infread = inf.read() try: + inf = codecs.open(filepath, "r", encoding='utf-8') + infread = inf.read() dict_from_file = eval(infread) except Exception as e: filereadgood = False From bc1bef8cd2483e4bb22d53b1e134268816eaa9d3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:34:53 -0400 Subject: [PATCH 051/127] test --- sopel_modules/SpiceBot/Read.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index b637462..4280899 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -112,9 +112,9 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True - inf = codecs.open(filepath, "r", encoding='utf-8') - infread = inf.read() try: + inf = codecs.open(filepath, "r", encoding='utf-8') + infread = inf.read() dict_from_file = eval(infread) except Exception as e: filereadgood = False From f2b1fa87e033f526fa8789d6fbd0df8d5caa40a7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:39:12 -0400 Subject: [PATCH 052/127] test --- sopel_modules/SpiceBot/Read.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 4280899..163d32b 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -62,7 +62,7 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True try: - inf = codecs.open(filepath, "r", encoding='utf-8') + inf = codecs.open(str(filepath), "r", encoding='utf-8') infread = inf.read() dict_from_file = eval(infread) except Exception as e: @@ -113,7 +113,7 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True try: - inf = codecs.open(filepath, "r", encoding='utf-8') + inf = codecs.open(str(filepath), "r", encoding='utf-8') infread = inf.read() dict_from_file = eval(infread) except Exception as e: From 987e793bb2aa562d2e3635cacdb82ef3cc6988a6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:41:08 -0400 Subject: [PATCH 053/127] test --- sopel_modules/SpiceBot/Read.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 163d32b..cc939fd 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel_modules import os +import sys import codecs from .Logs import logs @@ -62,7 +63,8 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True try: - inf = codecs.open(str(filepath), "r", encoding='utf-8') + sys.stderr(str(filepath)) + inf = codecs.open(filepath, "r", encoding='utf-8') infread = inf.read() dict_from_file = eval(infread) except Exception as e: @@ -113,7 +115,7 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True try: - inf = codecs.open(str(filepath), "r", encoding='utf-8') + inf = codecs.open(filepath, "r", encoding='utf-8') infread = inf.read() dict_from_file = eval(infread) except Exception as e: From 2875ea4a0710557f333e7c340b543d68ab9c4674 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:43:23 -0400 Subject: [PATCH 054/127] test --- sopel_modules/SpiceBot/Read.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index cc939fd..8305851 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel_modules import os -import sys import codecs from .Logs import logs @@ -62,10 +61,9 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True + inf = codecs.open(filepath, "r", encoding='utf-8') + infread = inf.read() try: - sys.stderr(str(filepath)) - inf = codecs.open(filepath, "r", encoding='utf-8') - infread = inf.read() dict_from_file = eval(infread) except Exception as e: filereadgood = False @@ -114,14 +112,14 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True + inf = codecs.open(jsonpath, "r", encoding='utf-8') + infread = inf.read() try: - inf = codecs.open(filepath, "r", encoding='utf-8') - infread = inf.read() dict_from_file = eval(infread) except Exception as e: filereadgood = False if logging: - logs.log("SpiceBot_Modules", "Error loading %s: %s (%s)" % ("Module Commands", e, filepath)) + logs.log("SpiceBot_Modules", "Error loading %s: %s (%s)" % ("Module Commands", e, jsonpath)) dict_from_file = dict() # Close File inf.close() @@ -134,7 +132,7 @@ class BotRead(): if not filereadgood or not isinstance(dict_from_file, dict): dict_from_file = {} else: - dict_from_file["filepath"] = str(filepath) + dict_from_file["filepath"] = str(jsonpath) dict_from_file["filename"] = str(filename_base) dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0] dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1] From bde826861d23910e46ec45ac7fc7891e53690abf Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:45:16 -0400 Subject: [PATCH 055/127] test --- sopel_modules/SpiceBot/Commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 092f526..eb450c2 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -196,7 +196,8 @@ class BotCommands(): foldername = str(folderpath).split("/")[-1] # check for json reference file - validcomdict = botread.module_json_to_dict(str(modulefile)) + # validcomdict = botread.module_json_to_dict(str(modulefile)) + validcomdict = {} # replace json defaults validcomdict["filepath"] = str(modulefile) From e0ef5a63f9b56ee97f89c9300f62992c69893a90 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:47:36 -0400 Subject: [PATCH 056/127] test --- sopel_modules/SpiceBot/Read.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 8305851..2cc3ff1 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -61,17 +61,17 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True - inf = codecs.open(filepath, "r", encoding='utf-8') - infread = inf.read() try: + inf = codecs.open(filepath, "r", encoding='utf-8') + infread = inf.read() + # Close File + inf.close() dict_from_file = eval(infread) except Exception as e: filereadgood = False if logging: logs.log(log_from, "Error loading %s: %s (%s)" % (configtypename, e, filepath)) dict_from_file = dict() - # Close File - inf.close() # gather file stats slashsplit = str(filepath).split("/") @@ -112,17 +112,17 @@ class BotRead(): # Read dictionary from file, if not, enable an empty dict filereadgood = True - inf = codecs.open(jsonpath, "r", encoding='utf-8') - infread = inf.read() try: + inf = codecs.open(jsonpath, "r", encoding='utf-8') + infread = inf.read() dict_from_file = eval(infread) + # Close File + inf.close() except Exception as e: filereadgood = False if logging: logs.log("SpiceBot_Modules", "Error loading %s: %s (%s)" % ("Module Commands", e, jsonpath)) dict_from_file = dict() - # Close File - inf.close() # gather file stats slashsplit = str(filepath).split("/") From b1981bf94329313924e2ddfaeb8e8bd401816ea6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:50:38 -0400 Subject: [PATCH 057/127] test --- sopel_modules/SpiceBot/Commands.py | 3 +-- sopel_modules/SpiceBot/DictComs.py | 3 --- sopel_modules/SpiceBot_Core_Commands/__init__.py | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index eb450c2..092f526 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -196,8 +196,7 @@ class BotCommands(): foldername = str(folderpath).split("/")[-1] # check for json reference file - # validcomdict = botread.module_json_to_dict(str(modulefile)) - validcomdict = {} + validcomdict = botread.module_json_to_dict(str(modulefile)) # replace json defaults validcomdict["filepath"] = str(modulefile) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 13137a3..1ae695c 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -16,8 +16,6 @@ import requests from fake_useragent import UserAgent import urllib -import sys - class SpiceBot_DictComs_MainSection(StaticSection): extra = ListAttribute('extra') @@ -36,7 +34,6 @@ class BotJSONCommands(): ] dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") - sys.stderr.write(dir_to_scan) valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index e4b9d44..97c416c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -21,7 +21,7 @@ from .AI import * from .Gif import * from .Sherlock import * from .Reddit import * -from .DictComs import * +# from .DictComs import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 4ea289cf34a0c4ac19b49ac8eb603eb5fa5a830f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:51:43 -0400 Subject: [PATCH 058/127] test --- sopel_modules/SpiceBot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index f051b6c..31db45c 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -26,7 +26,7 @@ from .Google import * from .Gif import * from .Sherlock import * from .Reddit import * -# from .DictComs import * +from .DictComs import * from .Read import * From 9fb68d581fb187eeb52663163a9c5be84dde52f9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:53:25 -0400 Subject: [PATCH 059/127] self --- sopel_modules/SpiceBot/DictComs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 1ae695c..1228d48 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -35,9 +35,9 @@ class BotJSONCommands(): dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") - valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") + self.valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") - for dict_from_file in list(valid_dictcom_dict.keys()): + for dict_from_file in list(self.valid_dictcom_dict.keys()): dict_from_file["comtype"] = "prefix" From fb43749c3c0611669a382787327761be35cae67c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 14:57:04 -0400 Subject: [PATCH 060/127] test --- sopel_modules/SpiceBot/DictComs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 1228d48..f124849 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -16,6 +16,8 @@ import requests from fake_useragent import UserAgent import urllib +import sys + class SpiceBot_DictComs_MainSection(StaticSection): extra = ListAttribute('extra') @@ -34,6 +36,7 @@ class BotJSONCommands(): ] dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") + sys.stderr(str(dir_to_scan)) self.valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") From 1818c65d81e3bf8109774ce95f8243574903df2f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:05:03 -0400 Subject: [PATCH 061/127] test --- sopel_modules/SpiceBot/DictComs.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index f124849..9c0904a 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -16,8 +16,6 @@ import requests from fake_useragent import UserAgent import urllib -import sys - class SpiceBot_DictComs_MainSection(StaticSection): extra = ListAttribute('extra') @@ -35,10 +33,9 @@ class BotJSONCommands(): "feeds", "search" ] - dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") - sys.stderr(str(dir_to_scan)) + self.dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") - self.valid_dictcom_dict = botread.json_to_dict(dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") + self.valid_dictcom_dict = botread.json_to_dict(self.dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") for dict_from_file in list(self.valid_dictcom_dict.keys()): From f527e93e6349fe8851df4a802f74b9d7c2021829 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:06:35 -0400 Subject: [PATCH 062/127] self --- sopel_modules/SpiceBot/Gif.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 8b8cab0..83239d3 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -34,9 +34,9 @@ class BotGif(): self.header = {'User-Agent': str(UserAgent().chrome)} self.valid_api = {} - dir_to_scan = botread.get_config_dirs("SpiceBot_Gif") + self.dir_to_scan = botread.get_config_dirs("SpiceBot_Gif") - valid_gif_api_dict = botread.json_to_dict(dir_to_scan, "Gif API", "SpiceBot_Gif") + valid_gif_api_dict = botread.json_to_dict(self.dir_to_scan, "Gif API", "SpiceBot_Gif") for gif_api in list(valid_gif_api_dict.keys()): botconfig.define_section(gif_api, GifAPISection, validate=False) From e2d04adcdca17ea65f4b65b36d38de45de482ebe Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:07:08 -0400 Subject: [PATCH 063/127] json --- .../SpiceBot_Configs/SpiceBot_DictComs/{bandaid => bandaid.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/{bandaid => bandaid.json} (100%) diff --git a/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid b/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid rename to sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid.json From 1e4e244701fff3db96470d2f1c03c9ba6e9f1bba Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:16:47 -0400 Subject: [PATCH 064/127] test --- sopel_modules/SpiceBot/DictComs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 9c0904a..6fdc357 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -39,7 +39,10 @@ class BotJSONCommands(): for dict_from_file in list(self.valid_dictcom_dict.keys()): - dict_from_file["comtype"] = "prefix" + try: + dict_from_file["comtype"] = "prefix" + except Exception as e: + sys.stderr(str(dict_from_file)) # default command to filename if "validcoms" not in list(dict_from_file.keys()): From d8e5fb017b2886be25c6394211c74843209ec90a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:17:39 -0400 Subject: [PATCH 065/127] test --- sopel_modules/SpiceBot/DictComs.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 6fdc357..0b65fa6 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -37,12 +37,11 @@ class BotJSONCommands(): self.valid_dictcom_dict = botread.json_to_dict(self.dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") - for dict_from_file in list(self.valid_dictcom_dict.keys()): + for jsondict in list(self.valid_dictcom_dict.keys()): - try: - dict_from_file["comtype"] = "prefix" - except Exception as e: - sys.stderr(str(dict_from_file)) + dict_from_file = self.valid_dictcom_dict[jsondict] + + dict_from_file["comtype"] = "prefix" # default command to filename if "validcoms" not in list(dict_from_file.keys()): From 9afece27cfd0c10af32b9f37e8c24dd9c6634db2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:19:05 -0400 Subject: [PATCH 066/127] weird --- sopel_modules/SpiceBot/DictComs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 0b65fa6..6f89b4a 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -70,7 +70,7 @@ class BotJSONCommands(): # Don't process these. keysprocessed = [] keysprocessed.extend(["validcoms", "filepath", "filename"]) - keysprocessed.append("author", "contributors") + keysprocessed.extend(["author", "contributors"]) keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"]) # handle basic required dict handling From 408d4067434d01feb1190745101b4304b2fd2f55 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:25:36 -0400 Subject: [PATCH 067/127] test --- sopel_modules/SpiceBot/DictComs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 6f89b4a..7cf1751 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -69,7 +69,7 @@ class BotJSONCommands(): # Don't process these. keysprocessed = [] - keysprocessed.extend(["validcoms", "filepath", "filename"]) + keysprocessed.extend(["validcoms", "filepath", "filename", "comtype"]) keysprocessed.extend(["author", "contributors"]) keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"]) From 5a3029d4044fccce56f1b7c2beffc39f1d48b1c3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:30:40 -0400 Subject: [PATCH 068/127] BotDictCommands --- sopel_modules/SpiceBot/DictComs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 7cf1751..ea1a324 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -21,7 +21,7 @@ class SpiceBot_DictComs_MainSection(StaticSection): extra = ListAttribute('extra') -class BotJSONCommands(): +class BotDictCommands(): def __init__(self): self.setup_dictcoms() @@ -257,4 +257,4 @@ class BotJSONCommands(): botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) -jsoncommands = BotJSONCommands() +dictcoms = BotDictCommands() From ade0bd813fa48b6f7a1e2f22c11b136fb224e593 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:34:13 -0400 Subject: [PATCH 069/127] test --- sopel_modules/SpiceBot_Core_Commands/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index 97c416c..e4b9d44 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -21,7 +21,7 @@ from .AI import * from .Gif import * from .Sherlock import * from .Reddit import * -# from .DictComs import * +from .DictComs import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 5cbb599fff9055545046009123da4832665bf7d8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:36:45 -0400 Subject: [PATCH 070/127] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 7e73204..6f256fb 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -11,8 +11,8 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun.prerun('prefix') -@sopel.module.nickname_commands('(.*)') -def bot_command_dictcom(bot, trigger): +@sopel.module.commands('(.*)') +def command_dictcom(bot, trigger): if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()): return From b3e12f4f8ade867beb380ac02514d032d4834ae9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 15:45:38 -0400 Subject: [PATCH 071/127] multipleprefix --- sopel_modules/SpiceBot/DictComs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index ea1a324..c7264c2 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -41,8 +41,6 @@ class BotDictCommands(): dict_from_file = self.valid_dictcom_dict[jsondict] - dict_from_file["comtype"] = "prefix" - # default command to filename if "validcoms" not in list(dict_from_file.keys()): dict_from_file["validcoms"] = [dict_from_file["filename"]] @@ -67,6 +65,8 @@ class BotDictCommands(): if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types: dict_from_file["type"] = 'simple' + dict_from_file["comtype"] = "prefix_" + dict_from_file["type"] + # Don't process these. keysprocessed = [] keysprocessed.extend(["validcoms", "filepath", "filename", "comtype"]) From 44e6448b64df612066e6f8dc20d59de459e79b15 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 20 Jun 2019 16:01:03 -0400 Subject: [PATCH 072/127] test --- sopel_modules/SpiceBot/DictComs.py | 5 +++++ sopel_modules/SpiceBot_Core_Commands/DictComs.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index c7264c2..78fe249 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -25,6 +25,7 @@ class BotDictCommands(): def __init__(self): self.setup_dictcoms() + self.validprefixcoms = [] self.header = {'User-Agent': str(UserAgent().chrome)} self.valid_com_types = [ 'simple', 'fillintheblank', 'targetplusreason', @@ -92,6 +93,10 @@ class BotDictCommands(): botcommands.register(dict_from_file) + for commandtype in self.valid_com_types: + if "prefix_" + commandtype in list(botcommands.dict['commands'].keys()): + self.validprefixcoms.extend(list(botcommands.dict['commands']["prefix_" + commandtype].keys())) + def bot_dict_use_cases(self, maincom, dict_from_file, process_list): for mustbe in process_list: diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 6f256fb..69b86be 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -14,7 +14,7 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.commands('(.*)') def command_dictcom(bot, trigger): - if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()): + if trigger.sb['com'] not in list(SpiceBot.dictcoms.validprefixcoms): return bot.say("here") From e7d9996c643d10386f9417648ed98132cddc8d6d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 21 Jun 2019 07:52:35 -0400 Subject: [PATCH 073/127] test --- sopel_modules/SpiceBot/DictComs.py | 7 +------ sopel_modules/SpiceBot_Core_Commands/DictComs.py | 8 ++++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 78fe249..faa4f0d 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -25,7 +25,6 @@ class BotDictCommands(): def __init__(self): self.setup_dictcoms() - self.validprefixcoms = [] self.header = {'User-Agent': str(UserAgent().chrome)} self.valid_com_types = [ 'simple', 'fillintheblank', 'targetplusreason', @@ -66,7 +65,7 @@ class BotDictCommands(): if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types: dict_from_file["type"] = 'simple' - dict_from_file["comtype"] = "prefix_" + dict_from_file["type"] + dict_from_file["comtype"] = "prefix" + dict_from_file["type"] # Don't process these. keysprocessed = [] @@ -93,10 +92,6 @@ class BotDictCommands(): botcommands.register(dict_from_file) - for commandtype in self.valid_com_types: - if "prefix_" + commandtype in list(botcommands.dict['commands'].keys()): - self.validprefixcoms.extend(list(botcommands.dict['commands']["prefix_" + commandtype].keys())) - def bot_dict_use_cases(self, maincom, dict_from_file, process_list): for mustbe in process_list: diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 69b86be..0cb2753 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -14,7 +14,11 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.commands('(.*)') def command_dictcom(bot, trigger): - if trigger.sb['com'] not in list(SpiceBot.dictcoms.validprefixcoms): + if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()): return - bot.say("here") + # command aliases + if "aliasfor" in list(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']].keys()): + trigger.sb['com'] = SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]["aliasfor"] + + bot.say(str(trigger.sb['com'])) From 60383c11c80dda57feb1bbba4760e7c27aac7d01 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 21 Jun 2019 07:54:45 -0400 Subject: [PATCH 074/127] fix --- sopel_modules/SpiceBot/DictComs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index faa4f0d..ea1a324 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -41,6 +41,8 @@ class BotDictCommands(): dict_from_file = self.valid_dictcom_dict[jsondict] + dict_from_file["comtype"] = "prefix" + # default command to filename if "validcoms" not in list(dict_from_file.keys()): dict_from_file["validcoms"] = [dict_from_file["filename"]] @@ -65,8 +67,6 @@ class BotDictCommands(): if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types: dict_from_file["type"] = 'simple' - dict_from_file["comtype"] = "prefix" + dict_from_file["type"] - # Don't process these. keysprocessed = [] keysprocessed.extend(["validcoms", "filepath", "filename", "comtype"]) From 871fd454e292577f5dc7a21c9c6684e77c109735 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 21 Jun 2019 08:19:19 -0400 Subject: [PATCH 075/127] add subdirectories for dictcom --- sopel_modules/SpiceBot/DictComs.py | 16 +++++++++++++--- .../SpiceBot_DictComs/{ => simple}/bandaid.json | 0 sopel_modules/SpiceBot_Core_Commands/DictComs.py | 9 ++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) rename sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/{ => simple}/bandaid.json (100%) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index ea1a324..83b3b55 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -15,6 +15,7 @@ from .Commands import commands as botcommands import requests from fake_useragent import UserAgent import urllib +import os class SpiceBot_DictComs_MainSection(StaticSection): @@ -33,7 +34,16 @@ class BotDictCommands(): "feeds", "search" ] + self.prefix_com_load() + + def prefix_com_load(self): self.dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") + for directory in self.dir_to_scan: + for valid_com_type in self.valid_com_types: + poss_path = os.path.join(directory, valid_com_type) + if os.path.exists(poss_path) and os.path.isdir(poss_path): + if len(os.listdir(poss_path)) > 0: + self.dir_to_scan.append(poss_path) self.valid_dictcom_dict = botread.json_to_dict(self.dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") @@ -75,7 +85,7 @@ class BotDictCommands(): # handle basic required dict handling dict_required = ["?default"] - dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, dict_required) + dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, dict_required) keysprocessed.extend(dict_required) # remove later @@ -87,12 +97,12 @@ class BotDictCommands(): if otherkey not in keysprocessed: otherkeys.append(otherkey) if otherkeys != []: - dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, otherkeys) + dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, otherkeys) keysprocessed.extend(otherkeys) botcommands.register(dict_from_file) - def bot_dict_use_cases(self, maincom, dict_from_file, process_list): + def prefix_com_load_subtypes(self, maincom, dict_from_file, process_list): for mustbe in process_list: diff --git a/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid.json b/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/simple/bandaid.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/simple/bandaid.json diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 0cb2753..fe73704 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -4,6 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot DictCom system """ +import copy + # sopel imports import sopel.module @@ -21,4 +23,9 @@ def command_dictcom(bot, trigger): if "aliasfor" in list(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']].keys()): trigger.sb['com'] = SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]["aliasfor"] - bot.say(str(trigger.sb['com'])) + # simplify usage of the bot command going forward + # copy dict to not overwrite + trigger.sb['comdict'] = copy.deepcopy(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]) + + # execute function based on command type + trigger.sb['comtype'] = trigger.sb['comdict']["type"].lower() From c16557d4a9dc3a7a39ec40357529797c0c6d1e72 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 08:25:38 -0400 Subject: [PATCH 076/127] test --- sopel_modules/SpiceBot/DictComs.py | 51 +++++++++++-------- .../SpiceBot_Core_Commands/DictComs.py | 14 +---- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 83b3b55..1572f88 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -12,10 +12,11 @@ from .Config import config as botconfig from .Read import read as botread from .Commands import commands as botcommands -import requests +# import requests from fake_useragent import UserAgent -import urllib +# import urllib import os +import copy class SpiceBot_DictComs_MainSection(StaticSection): @@ -33,10 +34,28 @@ class BotDictCommands(): "ascii_art", "gif", "translate", "responses", "feeds", "search" ] + self.dict_required = ["?default"] + self.builtin_keys = [ + "filepath", "filename", "folderpath", "foldername", + "comtype", "type", "validcoms", + "author", "contributors", + "description", "exampleresponse", "example", + "privs" + ] - self.prefix_com_load() + self.dictcom_load() - def prefix_com_load(self): + def get_dict(self, triggersb): + + # simplify usage of the bot command going forward + # copy dict to not overwrite + triggersb['comdict'] = copy.deepcopy(botcommands.dict['commands']["prefix"][triggersb['realcom']]) + + # execute function based on command type + triggersb['comtype'] = triggersb['comdict']["type"].lower() + return triggersb + + def dictcom_load(self): self.dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") for directory in self.dir_to_scan: for valid_com_type in self.valid_com_types: @@ -77,32 +96,20 @@ class BotDictCommands(): if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types: dict_from_file["type"] = 'simple' - # Don't process these. - keysprocessed = [] - keysprocessed.extend(["validcoms", "filepath", "filename", "comtype"]) - keysprocessed.extend(["author", "contributors"]) - keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"]) - # handle basic required dict handling - dict_required = ["?default"] - dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, dict_required) - keysprocessed.extend(dict_required) - - # remove later - keysprocessed.append("type") + dict_from_file = self.dictcom_load_usecases(maincom, dict_from_file, self.dict_required) # all other keys not processed above are considered potential use cases otherkeys = [] for otherkey in list(dict_from_file.keys()): - if otherkey not in keysprocessed: + if otherkey not in self.builtin_keys: otherkeys.append(otherkey) if otherkeys != []: - dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, otherkeys) - keysprocessed.extend(otherkeys) + dict_from_file = self.dictcom_load_usecases(maincom, dict_from_file, otherkeys) botcommands.register(dict_from_file) - def prefix_com_load_subtypes(self, maincom, dict_from_file, process_list): + def dictcom_load_usecases(self, maincom, dict_from_file, process_list): for mustbe in process_list: @@ -121,6 +128,9 @@ class BotDictCommands(): else: dict_from_file[mustbe]["type"] = "simple" + return dict_from_file + + """ # each usecase needs to know if it can be updated. Default is false if "updates_enabled" not in list(dict_from_file[mustbe].keys()): dict_from_file[mustbe]["updates_enabled"] = False @@ -262,6 +272,7 @@ class BotDictCommands(): dict_from_file[mustbe]["privs"] = [] return dict_from_file + """ def setup_dictcoms(self): botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index fe73704..1c66e65 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -4,8 +4,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot DictCom system """ -import copy - # sopel imports import sopel.module @@ -19,13 +17,5 @@ def command_dictcom(bot, trigger): if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()): return - # command aliases - if "aliasfor" in list(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']].keys()): - trigger.sb['com'] = SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]["aliasfor"] - - # simplify usage of the bot command going forward - # copy dict to not overwrite - trigger.sb['comdict'] = copy.deepcopy(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]) - - # execute function based on command type - trigger.sb['comtype'] = trigger.sb['comdict']["type"].lower() + trigger.sb = SpiceBot.dictcoms.get_dict(trigger.sb) + bot.osd(str(trigger.sb)) From a440b8e92d8ac313f31350cec1df6e8f9dd14848 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:16:43 -0400 Subject: [PATCH 077/127] try quitting --- sopel_modules/SpiceBot/DictComs.py | 3 ++- sopel_modules/SpiceBot/Prerun.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 1572f88..4267700 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -28,7 +28,8 @@ class BotDictCommands(): def __init__(self): self.setup_dictcoms() self.header = {'User-Agent': str(UserAgent().chrome)} - self.valid_com_types = [ + self.valid_com_types = ['simple'] + self.valid_com_types_old = [ 'simple', 'fillintheblank', 'targetplusreason', 'sayings', "readfromfile", "readfromurl", "ascii_art", "gif", "translate", "responses", diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 72b9a44..d0f1816 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -56,6 +56,7 @@ class BotPrerun(): function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) + quit() return return internal_prerun From fce9cad4e021f8b9dc4a36f1295130d27d575294 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:18:57 -0400 Subject: [PATCH 078/127] test --- sopel_modules/SpiceBot/Prerun.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index d0f1816..b073ab1 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -56,9 +56,7 @@ class BotPrerun(): function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) - quit() - return - + quit() return internal_prerun return actual_decorator From 660d6b56134ea8782684d5750470881f7340b47e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:21:40 -0400 Subject: [PATCH 079/127] test --- sopel_modules/SpiceBot/Prerun.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index b073ab1..28461f6 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -47,6 +47,7 @@ class BotPrerun(): # Run the function for all splits for argsdict in argsdict_list: + bot.say(str(argsdict)) trigger.sb = copy.deepcopy(argsdict) trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) From bd47fe79008ac10dbb6839380f4d91dec2e1830e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:25:07 -0400 Subject: [PATCH 080/127] test --- sopel_modules/SpiceBot/Prerun.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 28461f6..763f6e4 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -91,7 +91,6 @@ class BotPrerun(): return prerun_split def trigger_runstatus(self, bot, trigger): - return True # Bots can't run commands if Identifier(trigger.nick) == bot.nick: @@ -105,6 +104,9 @@ class BotPrerun(): bot.osd("The admin switch (-a) is for use by authorized nicks ONLY.", 'notice') return False + if trigger.sb["hyphen_arg"]: + return False + # don't run commands that are disabled in channels if not trigger.is_privmsg: commandused = trigger.sb["realcom"] From 4e099b6b5269be30c1393d4e34fe2f2fe6fbddf8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:28:05 -0400 Subject: [PATCH 081/127] test --- sopel_modules/SpiceBot/Prerun.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 763f6e4..671bbbd 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -53,7 +53,10 @@ class BotPrerun(): trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command - if self.trigger_runstatus(bot, trigger): + dowerun = self.trigger_runstatus(bot, trigger) + if not dowerun: + quit() + else: function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) From 7b223ba327cabd8743f37bdb71a44d0f3f97879d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:29:58 -0400 Subject: [PATCH 082/127] test --- sopel_modules/SpiceBot/Prerun.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 671bbbd..f7751c4 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -54,9 +54,8 @@ class BotPrerun(): if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command dowerun = self.trigger_runstatus(bot, trigger) - if not dowerun: - quit() - else: + bot.say(str(dowerun)) + if dowerun: function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) From a3a0cd7e31f63646aaaa38ecbba53738c795431e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:32:44 -0400 Subject: [PATCH 083/127] test --- sopel_modules/SpiceBot/Prerun.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index f7751c4..834b938 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -53,15 +53,14 @@ class BotPrerun(): trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command - dowerun = self.trigger_runstatus(bot, trigger) - bot.say(str(dowerun)) - if dowerun: + if self.trigger_runstatus(bot, trigger): function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) quit() return internal_prerun return actual_decorator + quit() def trigger_args(self, triggerargs_one, trigger_command_type='module'): trigger_args = spicemanip.main(triggerargs_one, 'create') From e782403d1589205828f62e9c0d17002f6405d297 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:33:04 -0400 Subject: [PATCH 084/127] test --- sopel_modules/SpiceBot/Prerun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 834b938..ee8646c 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -47,7 +47,6 @@ class BotPrerun(): # Run the function for all splits for argsdict in argsdict_list: - bot.say(str(argsdict)) trigger.sb = copy.deepcopy(argsdict) trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) @@ -60,6 +59,7 @@ class BotPrerun(): quit() return internal_prerun return actual_decorator + bot.say(str(here)) quit() def trigger_args(self, triggerargs_one, trigger_command_type='module'): From a455b4b1083ede7b1466013c9759650cd1c326fe Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:33:18 -0400 Subject: [PATCH 085/127] test --- sopel_modules/SpiceBot/Prerun.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index ee8646c..e4ae028 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -59,7 +59,6 @@ class BotPrerun(): quit() return internal_prerun return actual_decorator - bot.say(str(here)) quit() def trigger_args(self, triggerargs_one, trigger_command_type='module'): From 1e24444085e835f73e8498448457efd71c9088f8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:38:08 -0400 Subject: [PATCH 086/127] test --- sopel_modules/SpiceBot/Prerun.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index e4ae028..9ab2d01 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -40,11 +40,24 @@ class BotPrerun(): argsdict_default["realcom"] = realcom # split into && groupings - and_split = self.trigger_and_split(trigger_args) + # and_split = self.trigger_and_split(trigger_args) # Create dict listings for trigger.sb - argsdict_list = self.trigger_argsdict_list(argsdict_default, and_split) + # argsdict_list = self.trigger_argsdict_list(argsdict_default, and_split) + argsdict = self.trigger_argsdict_single(argsdict_default, trigger_args) + trigger.sb = copy.deepcopy(argsdict) + + trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) + if not trigger.sb["hyphen_arg"]: + # check if anything prohibits the nick from running the command + if self.trigger_runstatus(bot, trigger): + function(bot, trigger, *args, **kwargs) + else: + self.trigger_hyphen_arg_handler(bot, trigger) + quit() + + """ # Run the function for all splits for argsdict in argsdict_list: trigger.sb = copy.deepcopy(argsdict) @@ -57,9 +70,9 @@ class BotPrerun(): else: self.trigger_hyphen_arg_handler(bot, trigger) quit() + """ return internal_prerun return actual_decorator - quit() def trigger_args(self, triggerargs_one, trigger_command_type='module'): trigger_args = spicemanip.main(triggerargs_one, 'create') @@ -90,6 +103,16 @@ class BotPrerun(): prerun_split.append(argsdict_part) return prerun_split + def trigger_argsdict_single(self, argsdict_default, trigger_args_part): + argsdict_part = copy.deepcopy(argsdict_default) + argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') + if len(argsdict_part["args"]) and argsdict_part["args"][0] == "-a": + argsdict_part["adminswitch"] = True + argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') + else: + argsdict_part["adminswitch"] = False + return argsdict_part + def trigger_runstatus(self, bot, trigger): # Bots can't run commands From 629dcb4f9642b53ff6e0a5e1e40dfb3d74b28424 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:42:52 -0400 Subject: [PATCH 087/127] exit versus quit --- sopel_modules/SpiceBot/Prerun.py | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 9ab2d01..bf35a42 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -40,24 +40,11 @@ class BotPrerun(): argsdict_default["realcom"] = realcom # split into && groupings - # and_split = self.trigger_and_split(trigger_args) + and_split = self.trigger_and_split(trigger_args) # Create dict listings for trigger.sb - # argsdict_list = self.trigger_argsdict_list(argsdict_default, and_split) - argsdict = self.trigger_argsdict_single(argsdict_default, trigger_args) + argsdict_list = self.trigger_argsdict_list(argsdict_default, and_split) - trigger.sb = copy.deepcopy(argsdict) - - trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) - if not trigger.sb["hyphen_arg"]: - # check if anything prohibits the nick from running the command - if self.trigger_runstatus(bot, trigger): - function(bot, trigger, *args, **kwargs) - else: - self.trigger_hyphen_arg_handler(bot, trigger) - quit() - - """ # Run the function for all splits for argsdict in argsdict_list: trigger.sb = copy.deepcopy(argsdict) @@ -69,8 +56,7 @@ class BotPrerun(): function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) - quit() - """ + exit() return internal_prerun return actual_decorator @@ -103,16 +89,6 @@ class BotPrerun(): prerun_split.append(argsdict_part) return prerun_split - def trigger_argsdict_single(self, argsdict_default, trigger_args_part): - argsdict_part = copy.deepcopy(argsdict_default) - argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') - if len(argsdict_part["args"]) and argsdict_part["args"][0] == "-a": - argsdict_part["adminswitch"] = True - argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') - else: - argsdict_part["adminswitch"] = False - return argsdict_part - def trigger_runstatus(self, bot, trigger): # Bots can't run commands From 8b8bc391030d1d0ad76f7dca87b358c4b04537db Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:50:04 -0400 Subject: [PATCH 088/127] test --- sopel_modules/SpiceBot/Prerun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index bf35a42..0a0e9dc 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -56,8 +56,8 @@ class BotPrerun(): function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) - exit() return internal_prerun + quit() return actual_decorator def trigger_args(self, triggerargs_one, trigger_command_type='module'): From 9485c4cbde511314bb0e0fa07e3318c4d4193bcc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 10:57:38 -0400 Subject: [PATCH 089/127] test --- sopel_modules/SpiceBot/Prerun.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 0a0e9dc..d3d2bac 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -40,12 +40,23 @@ class BotPrerun(): argsdict_default["realcom"] = realcom # split into && groupings - and_split = self.trigger_and_split(trigger_args) + # and_split = self.trigger_and_split(trigger_args) # Create dict listings for trigger.sb - argsdict_list = self.trigger_argsdict_list(argsdict_default, and_split) + # argsdict_list = self.trigger_argsdict_list(argsdict_default, and_split) + argsdict = self.trigger_argsdict_single(argsdict_default, trigger_args) - # Run the function for all splits + trigger.sb = copy.deepcopy(argsdict) + + trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) + if not trigger.sb["hyphen_arg"]: + # check if anything prohibits the nick from running the command + if self.trigger_runstatus(bot, trigger): + return function(bot, trigger, *args, **kwargs) + else: + return self.trigger_hyphen_arg_handler(bot, trigger) + + """# Run the function for all splits for argsdict in argsdict_list: trigger.sb = copy.deepcopy(argsdict) @@ -56,8 +67,8 @@ class BotPrerun(): function(bot, trigger, *args, **kwargs) else: self.trigger_hyphen_arg_handler(bot, trigger) + """ return internal_prerun - quit() return actual_decorator def trigger_args(self, triggerargs_one, trigger_command_type='module'): @@ -89,6 +100,16 @@ class BotPrerun(): prerun_split.append(argsdict_part) return prerun_split + def trigger_argsdict_single(self, argsdict_default, trigger_args_part): + argsdict_part = copy.deepcopy(argsdict_default) + argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') + if len(argsdict_part["args"]) and argsdict_part["args"][0] == "-a": + argsdict_part["adminswitch"] = True + argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') + else: + argsdict_part["adminswitch"] = False + return argsdict_part + def trigger_runstatus(self, bot, trigger): # Bots can't run commands From b9d2bc5d6558d8c02a7b6176cb223cdbc91430d6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 11:29:53 -0400 Subject: [PATCH 090/127] test --- sopel_modules/SpiceBot/Prerun.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index d3d2bac..2d249cf 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -70,6 +70,7 @@ class BotPrerun(): """ return internal_prerun return actual_decorator + quit() def trigger_args(self, triggerargs_one, trigger_command_type='module'): trigger_args = spicemanip.main(triggerargs_one, 'create') From 3e9c35870d685c5f624be77635483e56ce5cac24 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 11:38:09 -0400 Subject: [PATCH 091/127] test --- sopel_modules/SpiceBot/Prerun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 2d249cf..8b1f0de 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -69,7 +69,8 @@ class BotPrerun(): self.trigger_hyphen_arg_handler(bot, trigger) """ return internal_prerun - return actual_decorator + # return actual_decorator + actual_decorator(trigger_command_type) quit() def trigger_args(self, triggerargs_one, trigger_command_type='module'): From 1e4d1ce4e1e8771b672950954813a97074398fab Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 11:40:41 -0400 Subject: [PATCH 092/127] test --- sopel_modules/SpiceBot/Prerun.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 8b1f0de..d3d2bac 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -69,9 +69,7 @@ class BotPrerun(): self.trigger_hyphen_arg_handler(bot, trigger) """ return internal_prerun - # return actual_decorator - actual_decorator(trigger_command_type) - quit() + return actual_decorator def trigger_args(self, triggerargs_one, trigger_command_type='module'): trigger_args = spicemanip.main(triggerargs_one, 'create') From 56b6eec19bb6aabf89d8dc495adaf4bb7c072f55 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 12:09:58 -0400 Subject: [PATCH 093/127] test not as class --- sopel_modules/SpiceBot/Prerun.py | 307 +++++++++--------- .../SpiceBot_Core_Commands/BotPrivs.py | 4 +- .../SpiceBot_Core_Commands/Channels.py | 2 +- .../SpiceBot_Core_Commands/Commands.py | 2 +- .../SpiceBot_Core_Commands/CommandsQuery.py | 4 +- .../SpiceBot_Core_Commands/DictComs.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Gif.py | 4 +- sopel_modules/SpiceBot_Core_Commands/Logs.py | 2 +- .../SpiceBot_Core_Commands/Messaging.py | 6 +- .../Runtime_Controls.py | 2 +- .../SpiceBot_Core_Commands/Search.py | 8 +- .../SpiceBot_Core_Commands/Sherlock.py | 2 +- 12 files changed, 172 insertions(+), 173 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index d3d2bac..fdb35e1 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -16,91 +16,77 @@ from .Commands import commands as botcommands from .Database import db as botdb -class BotPrerun(): - def __init__(self): - self.dict = {} +def prerun(trigger_command_type='module'): + def actual_decorator(function): - """Command Splitting""" + @functools.wraps(function) + def internal_prerun(bot, trigger, *args, **kwargs): - def prerun(self, trigger_command_type='module'): - def actual_decorator(function): + # Primary command used for trigger, and a list of all words + trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) - @functools.wraps(function) - def internal_prerun(bot, trigger, *args, **kwargs): + # Argsdict Defaults + argsdict_default = {} + argsdict_default["type"] = trigger_command_type + argsdict_default["com"] = trigger_command - # Primary command used for trigger, and a list of all words - trigger_args, trigger_command = self.trigger_args(trigger.args[1], trigger_command_type) + realcom = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) + argsdict_default["realcom"] = realcom - # Argsdict Defaults - argsdict_default = {} - argsdict_default["type"] = trigger_command_type - argsdict_default["com"] = trigger_command + # split into && groupings + # and_split = trigger_and_split(trigger_args) - realcom = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) - argsdict_default["realcom"] = realcom + # Create dict listings for trigger.sb + # argsdict_list = trigger_argsdict_list(argsdict_default, and_split) + argsdict = trigger_argsdict_single(argsdict_default, trigger_args) - # split into && groupings - # and_split = self.trigger_and_split(trigger_args) + trigger.sb = copy.deepcopy(argsdict) - # Create dict listings for trigger.sb - # argsdict_list = self.trigger_argsdict_list(argsdict_default, and_split) - argsdict = self.trigger_argsdict_single(argsdict_default, trigger_args) + trigger.sb["args"], trigger.sb["hyphen_arg"] = trigger_hyphen_args(trigger.sb["args"]) + if not trigger.sb["hyphen_arg"]: + # check if anything prohibits the nick from running the command + if trigger_runstatus(bot, trigger): + return function(bot, trigger, *args, **kwargs) + else: + return trigger_hyphen_arg_handler(bot, trigger) + """# Run the function for all splits + for argsdict in argsdict_list: trigger.sb = copy.deepcopy(argsdict) - trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) + trigger.sb["args"], trigger.sb["hyphen_arg"] = trigger_hyphen_args(trigger.sb["args"]) if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command - if self.trigger_runstatus(bot, trigger): - return function(bot, trigger, *args, **kwargs) + if trigger_runstatus(bot, trigger): + function(bot, trigger, *args, **kwargs) else: - return self.trigger_hyphen_arg_handler(bot, trigger) + trigger_hyphen_arg_handler(bot, trigger) + """ + return internal_prerun + return actual_decorator - """# Run the function for all splits - for argsdict in argsdict_list: - trigger.sb = copy.deepcopy(argsdict) - trigger.sb["args"], trigger.sb["hyphen_arg"] = self.trigger_hyphen_args(trigger.sb["args"]) - if not trigger.sb["hyphen_arg"]: - # check if anything prohibits the nick from running the command - if self.trigger_runstatus(bot, trigger): - function(bot, trigger, *args, **kwargs) - else: - self.trigger_hyphen_arg_handler(bot, trigger) - """ - return internal_prerun - return actual_decorator +def make_trigger_args(triggerargs_one, trigger_command_type='module'): + trigger_args = spicemanip.main(triggerargs_one, 'create') + if trigger_command_type in ['nickname']: + trigger_command = spicemanip.main(trigger_args, 2).lower() + trigger_args = spicemanip.main(trigger_args, '3+', 'list') + else: + trigger_command = spicemanip.main(trigger_args, 1).lower()[1:] + trigger_args = spicemanip.main(trigger_args, '2+', 'list') + return trigger_args, trigger_command - def trigger_args(self, triggerargs_one, trigger_command_type='module'): - trigger_args = spicemanip.main(triggerargs_one, 'create') - if trigger_command_type in ['nickname']: - trigger_command = spicemanip.main(trigger_args, 2).lower() - trigger_args = spicemanip.main(trigger_args, '3+', 'list') - else: - trigger_command = spicemanip.main(trigger_args, 1).lower()[1:] - trigger_args = spicemanip.main(trigger_args, '2+', 'list') - return trigger_args, trigger_command - def trigger_and_split(self, trigger_args): - trigger_args_list_split = spicemanip.main(trigger_args, "split_&&") - if not len(trigger_args_list_split): - trigger_args_list_split.append([]) - return trigger_args_list_split +def trigger_and_split(trigger_args): + trigger_args_list_split = spicemanip.main(trigger_args, "split_&&") + if not len(trigger_args_list_split): + trigger_args_list_split.append([]) + return trigger_args_list_split - def trigger_argsdict_list(self, argsdict_default, and_split): - prerun_split = [] - for trigger_args_part in and_split: - argsdict_part = copy.deepcopy(argsdict_default) - argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') - if len(argsdict_part["args"]) and argsdict_part["args"][0] == "-a": - argsdict_part["adminswitch"] = True - argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') - else: - argsdict_part["adminswitch"] = False - prerun_split.append(argsdict_part) - return prerun_split - def trigger_argsdict_single(self, argsdict_default, trigger_args_part): +def trigger_argsdict_list(argsdict_default, and_split): + prerun_split = [] + for trigger_args_part in and_split: argsdict_part = copy.deepcopy(argsdict_default) argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') if len(argsdict_part["args"]) and argsdict_part["args"][0] == "-a": @@ -108,113 +94,126 @@ class BotPrerun(): argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') else: argsdict_part["adminswitch"] = False - return argsdict_part + prerun_split.append(argsdict_part) + return prerun_split - def trigger_runstatus(self, bot, trigger): - # Bots can't run commands - if Identifier(trigger.nick) == bot.nick: - return False +def trigger_argsdict_single(argsdict_default, trigger_args_part): + argsdict_part = copy.deepcopy(argsdict_default) + argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') + if len(argsdict_part["args"]) and argsdict_part["args"][0] == "-a": + argsdict_part["adminswitch"] = True + argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') + else: + argsdict_part["adminswitch"] = False + return argsdict_part - # Allow permissions for enabling and disabling commands via hyphenargs - if trigger.sb["adminswitch"]: - if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - return True - else: - bot.osd("The admin switch (-a) is for use by authorized nicks ONLY.", 'notice') - return False - if trigger.sb["hyphen_arg"]: - return False +def trigger_runstatus(bot, trigger): - # don't run commands that are disabled in channels - if not trigger.is_privmsg: - commandused = trigger.sb["realcom"] - disabled_list = botdb.get_channel_value(trigger.sender, 'commands_disabled') or {} - if commandused in list(disabled_list.keys()): - reason = disabled_list[trigger.sb["realcom"]]["reason"] - timestamp = disabled_list[trigger.sb["realcom"]]["timestamp"] - bywhom = disabled_list[trigger.sb["realcom"]]["disabledby"] - message = "The " + str(trigger.sb["com"]) + " command was disabled by " + bywhom + " in " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) - return self.trigger_cant_run(bot, trigger, message) - - return True - - def trigger_cant_run(self, bot, trigger, message=None): - if message: - bot.osd(message, trigger.nick, 'notice') - if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("You however are authorized to bypass this warning with the (-a) admin switch.", trigger.nick, 'notice') + # Bots can't run commands + if Identifier(trigger.nick) == bot.nick: return False - def trigger_hyphen_args(self, trigger_args_part): - valid_hyphen_args = [ - 'check', - 'enable', 'disable' - ] - hyphen_args = [] - trigger_args_unhyphend = [] - for worditem in trigger_args_part: - if str(worditem).startswith("--") and worditem[2:] in valid_hyphen_args: - hyphen_args.append(worditem[2:]) - else: - trigger_args_unhyphend.append(worditem) - if len(hyphen_args): - hyphenarg = hyphen_args[0] + # Allow permissions for enabling and disabling commands via hyphenargs + if trigger.sb["adminswitch"]: + if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): + return True else: - hyphenarg = None - return trigger_args_unhyphend, hyphenarg + bot.osd("The admin switch (-a) is for use by authorized nicks ONLY.", 'notice') + return False - def trigger_hyphen_arg_handler(self, bot, trigger): + if trigger.sb["hyphen_arg"]: + return False - # Commands that cannot run via privmsg - if trigger.sb["hyphen_arg"] in ['check']: - if trigger.sb["com"].lower() != trigger.sb["realcom"]: - bot.osd(trigger.sb["com"] + " is a valid alias command for " + trigger.sb["realcom"]) - else: - bot.osd(trigger.sb["com"] + " is a valid command") - return + # don't run commands that are disabled in channels + if not trigger.is_privmsg: + commandused = trigger.sb["realcom"] + disabled_list = botdb.get_channel_value(trigger.sender, 'commands_disabled') or {} + if commandused in list(disabled_list.keys()): + reason = disabled_list[trigger.sb["realcom"]]["reason"] + timestamp = disabled_list[trigger.sb["realcom"]]["timestamp"] + bywhom = disabled_list[trigger.sb["realcom"]]["disabledby"] + message = "The " + str(trigger.sb["com"]) + " command was disabled by " + bywhom + " in " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + return trigger_cant_run(bot, trigger, message) - elif trigger.sb["hyphen_arg"] in ['enable']: + return True - if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("I was unable to disable this command due to privilege issues.") - return - if trigger.is_privmsg: - bot.osd("This command must be run in a channel you which to enable it in.", trigger.nick, 'notice') - return +def trigger_cant_run(bot, trigger, message=None): + if message: + bot.osd(message, trigger.nick, 'notice') + if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): + bot.osd("You however are authorized to bypass this warning with the (-a) admin switch.", trigger.nick, 'notice') + return False - if not botcommands.check_commands_disabled(trigger.sb["realcom"], trigger.sender): - bot.osd(trigger.sb["com"] + " is already enabled in " + str(trigger.sender), trigger.nick, 'notice') - return - botcommands.unset_command_disabled(trigger.sb["realcom"], trigger.sender) - bot.osd(trigger.sb["com"] + " is now enabled in " + str(trigger.sender)) - return +def trigger_hyphen_args(trigger_args_part): + valid_hyphen_args = [ + 'check', + 'enable', 'disable' + ] + hyphen_args = [] + trigger_args_unhyphend = [] + for worditem in trigger_args_part: + if str(worditem).startswith("--") and worditem[2:] in valid_hyphen_args: + hyphen_args.append(worditem[2:]) + else: + trigger_args_unhyphend.append(worditem) + if len(hyphen_args): + hyphenarg = hyphen_args[0] + else: + hyphenarg = None + return trigger_args_unhyphend, hyphenarg - elif trigger.sb["hyphen_arg"] in ['disable']: - if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("I was unable to disable this command due to privilege issues.") - return - - if trigger.is_privmsg: - bot.osd("This command must be run in a channel you which to disable it in.", trigger.nick, 'notice') - return - - if botcommands.check_commands_disabled(trigger.sb["realcom"], trigger.sender): - bot.osd(trigger.sb["com"] + " is already disabled in " + str(trigger.sender), trigger.nick, 'notice') - return - - trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given." - timestamp = str(datetime.datetime.utcnow()) - - botcommands.set_command_disabled(trigger.sb["realcom"], trigger.sender, timestamp, trailingmessage, trigger.nick) - bot.osd(trigger.sb["com"] + " is now disabled in " + str(trigger.sender)) - return +def trigger_hyphen_arg_handler(bot, trigger): + # Commands that cannot run via privmsg + if trigger.sb["hyphen_arg"] in ['check']: + if trigger.sb["com"].lower() != trigger.sb["realcom"]: + bot.osd(trigger.sb["com"] + " is a valid alias command for " + trigger.sb["realcom"]) + else: + bot.osd(trigger.sb["com"] + " is a valid command") return + elif trigger.sb["hyphen_arg"] in ['enable']: -prerun = BotPrerun() + if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): + bot.osd("I was unable to disable this command due to privilege issues.") + return + + if trigger.is_privmsg: + bot.osd("This command must be run in a channel you which to enable it in.", trigger.nick, 'notice') + return + + if not botcommands.check_commands_disabled(trigger.sb["realcom"], trigger.sender): + bot.osd(trigger.sb["com"] + " is already enabled in " + str(trigger.sender), trigger.nick, 'notice') + return + + botcommands.unset_command_disabled(trigger.sb["realcom"], trigger.sender) + bot.osd(trigger.sb["com"] + " is now enabled in " + str(trigger.sender)) + return + + elif trigger.sb["hyphen_arg"] in ['disable']: + + if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): + bot.osd("I was unable to disable this command due to privilege issues.") + return + + if trigger.is_privmsg: + bot.osd("This command must be run in a channel you which to disable it in.", trigger.nick, 'notice') + return + + if botcommands.check_commands_disabled(trigger.sb["realcom"], trigger.sender): + bot.osd(trigger.sb["com"] + " is already disabled in " + str(trigger.sender), trigger.nick, 'notice') + return + + trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given." + timestamp = str(datetime.datetime.utcnow()) + + botcommands.set_command_disabled(trigger.sb["realcom"], trigger.sender, timestamp, trailingmessage, trigger.nick) + bot.osd(trigger.sb["com"] + " is now disabled in " + str(trigger.sender)) + return + + return diff --git a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py index 396e839..84d98c8 100644 --- a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py +++ b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py @@ -9,13 +9,13 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('owners', 'owner') def bot_command_owners(bot, trigger): bot_command_process(bot, trigger) -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('admins', 'admin') def bot_command_admins(bot, trigger): bot_command_process(bot, trigger) diff --git a/sopel_modules/SpiceBot_Core_Commands/Channels.py b/sopel_modules/SpiceBot_Core_Commands/Channels.py index dea730f..cd8f156 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Channels.py +++ b/sopel_modules/SpiceBot_Core_Commands/Channels.py @@ -11,7 +11,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('channels', 'channel') def nickname_comand_channels(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index 8a1feef..1ecd5aa 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -15,7 +15,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('commands', 'command') def nickname_comand_commands(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py index f06ce70..72fcaa8 100644 --- a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py +++ b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py @@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger): @@ -79,7 +79,7 @@ def query_detection_nick(bot, trigger): @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) -@SpiceBot.prerun.prerun('query') +@SpiceBot.prerun('query') @sopel.module.rule('^\?(.*)') def query_detection(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 1c66e65..2d84f2a 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -10,7 +10,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.prerun('prefix') +@SpiceBot.prerun('prefix') @sopel.module.commands('(.*)') def command_dictcom(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 755822c..b349172 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -11,7 +11,7 @@ import spicemanip # TODO custom gif shortcut commands -@SpiceBot.prerun.prerun('gif_prefix') +@SpiceBot.prerun('gif_prefix') @sopel.module.commands('gif') def gif_trigger(bot, trigger): @@ -30,7 +30,7 @@ def gif_trigger(bot, trigger): bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) -@SpiceBot.prerun.prerun('gif_prefix') +@SpiceBot.prerun('gif_prefix') @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Logs.py b/sopel_modules/SpiceBot_Core_Commands/Logs.py index 59b454f..e66b69b 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Logs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Logs.py @@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOGS]) -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('logs', 'debug') def bot_command_logs(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Messaging.py b/sopel_modules/SpiceBot_Core_Commands/Messaging.py index 3d8a45e..9083841 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Messaging.py +++ b/sopel_modules/SpiceBot_Core_Commands/Messaging.py @@ -9,19 +9,19 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('action') def bot_command_action(bot, trigger): bot_command_process(bot, trigger) -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('notice') def bot_command_notice(bot, trigger): bot_command_process(bot, trigger) -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('privmsg', 'say', 'msg') def bot_command_privmsg(bot, trigger): bot_command_process(bot, trigger) diff --git a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py index 54dce6c..fa36758 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py +++ b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py @@ -9,7 +9,7 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.prerun('nickname') +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('update') def nickname_comand_update(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Search.py b/sopel_modules/SpiceBot_Core_Commands/Search.py index 9f2f622..d33b673 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Search.py +++ b/sopel_modules/SpiceBot_Core_Commands/Search.py @@ -10,7 +10,7 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.prerun('module') +@SpiceBot.prerun('module') @sopel.module.commands('search', 'find', 'google', 'lookup') def search_main(bot, trigger): @@ -26,7 +26,7 @@ def search_main(bot, trigger): bot.osd(["[Information search for '" + str(searchterm) + "']", str(searchreturn)]) -@SpiceBot.prerun.prerun('module') +@SpiceBot.prerun('module') @sopel.module.commands("where", "whereis") def search_where(bot, trigger): @@ -42,7 +42,7 @@ def search_where(bot, trigger): bot.osd(["[Location search for " + str(searchterm) + "]", str(searchreturn)]) -@SpiceBot.prerun.prerun('module') +@SpiceBot.prerun('module') @sopel.module.commands("what", "whatis") def search_what(bot, trigger): @@ -58,7 +58,7 @@ def search_what(bot, trigger): bot.osd(["[Information search for '" + str(searchterm) + "']", str(searchreturn)]) -@SpiceBot.prerun.prerun('module') +@SpiceBot.prerun('module') @sopel.module.commands("youtube", "video") def search_video(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py index d38f32d..d4a19cb 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py +++ b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py @@ -9,7 +9,7 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun.prerun('module') +@SpiceBot.prerun('module') @sopel.module.commands('sherlock', 'username') def bot_command_sherlock(bot, trigger): From 0890c6fe01adb1d4edde777a9718b0b67750d500 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 12:12:18 -0400 Subject: [PATCH 094/127] fix ai --- sopel_modules/SpiceBot_Core_Commands/AI.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index bd182de..e4e80cb 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -36,7 +36,7 @@ def bot_command_rule_ai(bot, trigger): if str(message).lower().startswith(str(bot.nick).lower()): command_type = 'nickname' - trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'nickname') + trigger_args, trigger_command = SpiceBot.make_trigger_args(message, 'nickname') trigger_args.insert(0, trigger_command) fulltrigger = bot.nick + " " + spicemanip.main(trigger_args, 0) if str(trigger_command).startswith("?"): @@ -50,7 +50,7 @@ def bot_command_rule_ai(bot, trigger): return elif str(message).startswith(tuple(bot.config.core.prefix_list)): command_type = 'module' - trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') + trigger_args, trigger_command = SpiceBot.make_trigger_args(message, 'module') trigger_args.insert(0, trigger_command) fulltrigger = spicemanip.main(trigger_args, 0) # patch for people typing "...", maybe other stuff, but this verifies that there is still a command here From 95783afc506001f2d8cb9ca343fb589eaef561db Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 15:03:09 -0400 Subject: [PATCH 095/127] test --- sopel_modules/SpiceBot/Prerun.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index fdb35e1..452bc07 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -20,7 +20,10 @@ def prerun(trigger_command_type='module'): def actual_decorator(function): @functools.wraps(function) - def internal_prerun(bot, trigger, *args, **kwargs): + def internal_prerun(*args, **kwargs): + + # Assign trigger and bot for easy access later + bot, trigger = args[0:2] # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) @@ -62,7 +65,7 @@ def prerun(trigger_command_type='module'): else: trigger_hyphen_arg_handler(bot, trigger) """ - return internal_prerun + internal_prerun() return actual_decorator From 119a6d80d8e403586a04f068279ae8b3c17c6347 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 15:08:01 -0400 Subject: [PATCH 096/127] test --- sopel_modules/SpiceBot/Prerun.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 452bc07..e832b7f 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -16,7 +16,7 @@ from .Commands import commands as botcommands from .Database import db as botdb -def prerun(trigger_command_type='module'): +def prerun_old(trigger_command_type='module'): def actual_decorator(function): @functools.wraps(function) @@ -65,7 +65,30 @@ def prerun(trigger_command_type='module'): else: trigger_hyphen_arg_handler(bot, trigger) """ - internal_prerun() + return internal_prerun + return actual_decorator + + +def prerun(message="this is not privmsg", reply=False): + + def actual_decorator(function): + @functools.wraps(function) + def _nop(*args, **kwargs): + # Assign trigger and bot for easy access later + bot, trigger = args[0:2] + if not trigger.is_privmsg: + if message and not callable(message): + if reply: + bot.reply(message) + else: + bot.say(message) + else: + return function(*args, **kwargs) + return _nop + + # Hack to allow decorator without parens + if callable(message): + return actual_decorator(message) return actual_decorator From 6a3e6cf2102a84220595d5641b8675d16e2cfafa Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 15:10:56 -0400 Subject: [PATCH 097/127] test --- sopel_modules/SpiceBot/Prerun.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index e832b7f..12a9169 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -69,7 +69,7 @@ def prerun_old(trigger_command_type='module'): return actual_decorator -def prerun(message="this is not privmsg", reply=False): +def prerun(trigger_command_type="this is not privmsg"): def actual_decorator(function): @functools.wraps(function) @@ -77,18 +77,15 @@ def prerun(message="this is not privmsg", reply=False): # Assign trigger and bot for easy access later bot, trigger = args[0:2] if not trigger.is_privmsg: - if message and not callable(message): - if reply: - bot.reply(message) - else: - bot.say(message) + if trigger_command_type and not callable(trigger_command_type): + bot.say(trigger_command_type) else: return function(*args, **kwargs) return _nop # Hack to allow decorator without parens - if callable(message): - return actual_decorator(message) + if callable(trigger_command_type): + return actual_decorator(trigger_command_type) return actual_decorator From 0998228adc23946472920f19cd2c02190819a2e0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 15:15:39 -0400 Subject: [PATCH 098/127] test --- sopel_modules/SpiceBot/Prerun.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 12a9169..95a6e86 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -69,7 +69,8 @@ def prerun_old(trigger_command_type='module'): return actual_decorator -def prerun(trigger_command_type="this is not privmsg"): +def prerun(message="this is not privmsg"): + message = "this is not privmsg" def actual_decorator(function): @functools.wraps(function) @@ -77,15 +78,15 @@ def prerun(trigger_command_type="this is not privmsg"): # Assign trigger and bot for easy access later bot, trigger = args[0:2] if not trigger.is_privmsg: - if trigger_command_type and not callable(trigger_command_type): - bot.say(trigger_command_type) + if message and not callable(message): + bot.say(message) else: return function(*args, **kwargs) return _nop # Hack to allow decorator without parens - if callable(trigger_command_type): - return actual_decorator(trigger_command_type) + if callable(message): + return actual_decorator(message) return actual_decorator From 09133221a4f430dbb8956948b24334d0aa8b348c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 24 Jun 2019 15:18:27 -0400 Subject: [PATCH 099/127] test --- sopel_modules/SpiceBot/Prerun.py | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 95a6e86..8bbcf87 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -16,7 +16,7 @@ from .Commands import commands as botcommands from .Database import db as botdb -def prerun_old(trigger_command_type='module'): +def prerun(trigger_command_type='module'): def actual_decorator(function): @functools.wraps(function) @@ -51,7 +51,7 @@ def prerun_old(trigger_command_type='module'): if trigger_runstatus(bot, trigger): return function(bot, trigger, *args, **kwargs) else: - return trigger_hyphen_arg_handler(bot, trigger) + trigger_hyphen_arg_handler(bot, trigger) """# Run the function for all splits for argsdict in argsdict_list: @@ -69,27 +69,6 @@ def prerun_old(trigger_command_type='module'): return actual_decorator -def prerun(message="this is not privmsg"): - message = "this is not privmsg" - - def actual_decorator(function): - @functools.wraps(function) - def _nop(*args, **kwargs): - # Assign trigger and bot for easy access later - bot, trigger = args[0:2] - if not trigger.is_privmsg: - if message and not callable(message): - bot.say(message) - else: - return function(*args, **kwargs) - return _nop - - # Hack to allow decorator without parens - if callable(message): - return actual_decorator(message) - return actual_decorator - - def make_trigger_args(triggerargs_one, trigger_command_type='module'): trigger_args = spicemanip.main(triggerargs_one, 'create') if trigger_command_type in ['nickname']: From 5542635d65bea382ed11855e09e86c04b1744f53 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 07:57:45 -0400 Subject: [PATCH 100/127] test uptime --- sopel_modules/SpiceBot/Prerun.py | 20 +++++++++++++++++-- .../SpiceBot_Core_Commands/Uptime.py | 4 +--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 8bbcf87..e58615c 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -16,7 +16,23 @@ from .Commands import commands as botcommands from .Database import db as botdb -def prerun(trigger_command_type='module'): +def prerun(command_list, trigger_command_type='module'): + + if trigger_command_type == 'nickname': + def add_attribute(function): + if not hasattr(function, "nickname_commands"): + function.nickname_commands = [] + function.nickname_commands.extend(command_list) + return function + return add_attribute + else: + def add_attribute(function): + if not hasattr(function, "commands"): + function.commands = [] + function.commands.extend(command_list) + return function + return add_attribute + def actual_decorator(function): @functools.wraps(function) @@ -49,7 +65,7 @@ def prerun(trigger_command_type='module'): if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command if trigger_runstatus(bot, trigger): - return function(bot, trigger, *args, **kwargs) + function(*args, **kwargs) else: trigger_hyphen_arg_handler(bot, trigger) diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index 4bde934..2ad65e4 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -2,14 +2,12 @@ from __future__ import unicode_literals, absolute_import, division, print_function -import sopel.module - import time import sopel_modules.SpiceBot as SpiceBot -@sopel.module.nickname_commands('uptime') +@SpiceBot.prerun(['uptime'], 'module') def bot_command_uptime(bot, trigger): timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." bot.osd("I have been running since " + timesince) From 92fad5eb8f1262403df0f418dc10c5e5d94bcc6b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 08:24:32 -0400 Subject: [PATCH 101/127] revert changes --- sopel_modules/SpiceBot/Prerun.py | 24 +++---------------- .../SpiceBot_Core_Commands/Uptime.py | 4 +++- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index e58615c..b16fe7a 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -16,30 +16,12 @@ from .Commands import commands as botcommands from .Database import db as botdb -def prerun(command_list, trigger_command_type='module'): - - if trigger_command_type == 'nickname': - def add_attribute(function): - if not hasattr(function, "nickname_commands"): - function.nickname_commands = [] - function.nickname_commands.extend(command_list) - return function - return add_attribute - else: - def add_attribute(function): - if not hasattr(function, "commands"): - function.commands = [] - function.commands.extend(command_list) - return function - return add_attribute +def prerun(trigger_command_type='module'): def actual_decorator(function): @functools.wraps(function) - def internal_prerun(*args, **kwargs): - - # Assign trigger and bot for easy access later - bot, trigger = args[0:2] + def internal_prerun(bot, trigger, *args, **kwargs): # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) @@ -65,7 +47,7 @@ def prerun(command_list, trigger_command_type='module'): if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command if trigger_runstatus(bot, trigger): - function(*args, **kwargs) + function(bot, trigger, *args, **kwargs) else: trigger_hyphen_arg_handler(bot, trigger) diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index 2ad65e4..4bde934 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -2,12 +2,14 @@ from __future__ import unicode_literals, absolute_import, division, print_function +import sopel.module + import time import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun(['uptime'], 'module') +@sopel.module.nickname_commands('uptime') def bot_command_uptime(bot, trigger): timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." bot.osd("I have been running since " + timesince) From 7d095db3b5c0f08b66249b5b91ce17c18457f819 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 08:26:58 -0400 Subject: [PATCH 102/127] reapply && split --- sopel_modules/SpiceBot/Prerun.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index b16fe7a..206248d 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -35,10 +35,11 @@ def prerun(trigger_command_type='module'): argsdict_default["realcom"] = realcom # split into && groupings - # and_split = trigger_and_split(trigger_args) + and_split = trigger_and_split(trigger_args) # Create dict listings for trigger.sb - # argsdict_list = trigger_argsdict_list(argsdict_default, and_split) + argsdict_list = trigger_argsdict_list(argsdict_default, and_split) + """ argsdict = trigger_argsdict_single(argsdict_default, trigger_args) trigger.sb = copy.deepcopy(argsdict) @@ -50,8 +51,9 @@ def prerun(trigger_command_type='module'): function(bot, trigger, *args, **kwargs) else: trigger_hyphen_arg_handler(bot, trigger) + """ - """# Run the function for all splits + # Run the function for all splits for argsdict in argsdict_list: trigger.sb = copy.deepcopy(argsdict) @@ -62,7 +64,7 @@ def prerun(trigger_command_type='module'): function(bot, trigger, *args, **kwargs) else: trigger_hyphen_arg_handler(bot, trigger) - """ + return internal_prerun return actual_decorator From aa8b8ec61e46147ebe542107aee04e4e9fa3d888 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 08:53:45 -0400 Subject: [PATCH 103/127] test --- sopel_modules/SpiceBot_Core_Commands/Uptime.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index 4bde934..ecf823a 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -9,6 +9,7 @@ import time import sopel_modules.SpiceBot as SpiceBot +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('uptime') def bot_command_uptime(bot, trigger): timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." From d53c293dc41410ac79ca986355b7e0956a5ae468 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 08:55:06 -0400 Subject: [PATCH 104/127] test --- sopel_modules/SpiceBot_Core_Commands/Uptime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index ecf823a..336a0f3 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -9,8 +9,8 @@ import time import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('uptime') +@SpiceBot.prerun('nickname') def bot_command_uptime(bot, trigger): timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." bot.osd("I have been running since " + timesince) From 11ce6e720c8dc7653489ddd15183e006dbac51c7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 09:02:26 -0400 Subject: [PATCH 105/127] test none --- sopel_modules/SpiceBot/Prerun.py | 1 + sopel_modules/SpiceBot_Core_Commands/Uptime.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 206248d..7da3b68 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -22,6 +22,7 @@ def prerun(trigger_command_type='module'): @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): + return # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index 336a0f3..ecf823a 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -9,8 +9,8 @@ import time import sopel_modules.SpiceBot as SpiceBot -@sopel.module.nickname_commands('uptime') @SpiceBot.prerun('nickname') +@sopel.module.nickname_commands('uptime') def bot_command_uptime(bot, trigger): timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." bot.osd("I have been running since " + timesince) From 9591b34cb154c329d72ddb226237b46ee238c495 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 09:07:36 -0400 Subject: [PATCH 106/127] test --- sopel_modules/SpiceBot/Prerun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 7da3b68..f387ae9 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -22,10 +22,11 @@ def prerun(trigger_command_type='module'): @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): - return # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) + if trigger_command == 'uptime': + return # Argsdict Defaults argsdict_default = {} From 264187299dbcbef99d4c2af54b7130f239ab2873 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 11:21:06 -0400 Subject: [PATCH 107/127] first _match test --- sopel_modules/SpiceBot/Prerun.py | 7 ++++++- sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py | 2 +- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Gif.py | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index f387ae9..3872ee4 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -16,13 +16,18 @@ from .Commands import commands as botcommands from .Database import db as botdb -def prerun(trigger_command_type='module'): +def prerun(t_command_type='module'): def actual_decorator(function): @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): + if t_command_type.endswith("_match"): + trigger_command_type = t_command_type.replace("_match", '') + else: + trigger_command_type = t_command_type + # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) if trigger_command == 'uptime': diff --git a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py index 72fcaa8..b6fa9b0 100644 --- a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py +++ b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py @@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) -@SpiceBot.prerun('nickname') +@SpiceBot.prerun('nickname_match') @sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 2d84f2a..201b094 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -10,7 +10,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun('prefix') +@SpiceBot.prerun('prefix_match') @sopel.module.commands('(.*)') def command_dictcom(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index b349172..d02b179 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -30,7 +30,7 @@ def gif_trigger(bot, trigger): bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) -@SpiceBot.prerun('gif_prefix') +@SpiceBot.prerun('gif_prefix_match') @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): From 6ff40daffaeb3d8761dde55dfdc75a0e78c8d471 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 11:29:15 -0400 Subject: [PATCH 108/127] test --- sopel_modules/SpiceBot/Prerun.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 3872ee4..f26808b 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -28,10 +28,15 @@ def prerun(t_command_type='module'): else: trigger_command_type = t_command_type + if trigger_command_type not in list(botcommands.dict["commands"].keys()): + return + # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) - if trigger_command == 'uptime': - return + + if t_command_type.endswith("_match"): + if trigger_command in list(botcommands.dict["commands"][trigger_command_type].keys()): + return # Argsdict Defaults argsdict_default = {} From 89d3aa33b49281d2ccbb2df72c3e892e63da5b32 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 11:31:09 -0400 Subject: [PATCH 109/127] test --- sopel_modules/SpiceBot/Prerun.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index f26808b..754d898 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -29,6 +29,7 @@ def prerun(t_command_type='module'): trigger_command_type = t_command_type if trigger_command_type not in list(botcommands.dict["commands"].keys()): + bot.say(str(trigger_command_type) + " not valid command type") return # Primary command used for trigger, and a list of all words From 0a1d9403bc673ffd8d3f3641c8b234c898a83fee Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 11:32:15 -0400 Subject: [PATCH 110/127] test --- sopel_modules/SpiceBot/Prerun.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 754d898..1737f46 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -27,9 +27,8 @@ def prerun(t_command_type='module'): trigger_command_type = t_command_type.replace("_match", '') else: trigger_command_type = t_command_type - + bot.say(str(trigger_command_type)) if trigger_command_type not in list(botcommands.dict["commands"].keys()): - bot.say(str(trigger_command_type) + " not valid command type") return # Primary command used for trigger, and a list of all words From ee411b8502243c67c5c32893a7b59ead237b0c2c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 11:33:41 -0400 Subject: [PATCH 111/127] test --- sopel_modules/SpiceBot/Prerun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 1737f46..ddab243 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -27,12 +27,13 @@ def prerun(t_command_type='module'): trigger_command_type = t_command_type.replace("_match", '') else: trigger_command_type = t_command_type - bot.say(str(trigger_command_type)) + if trigger_command_type not in list(botcommands.dict["commands"].keys()): return # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) + bot.say(str(trigger_command)) if t_command_type.endswith("_match"): if trigger_command in list(botcommands.dict["commands"][trigger_command_type].keys()): From dca0ca7c362c83916fc296e13bc64e8592742861 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 11:35:47 -0400 Subject: [PATCH 112/127] test --- sopel_modules/SpiceBot/Prerun.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index ddab243..1a6e5fa 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -33,10 +33,9 @@ def prerun(t_command_type='module'): # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) - bot.say(str(trigger_command)) if t_command_type.endswith("_match"): - if trigger_command in list(botcommands.dict["commands"][trigger_command_type].keys()): + if trigger_command_type in ["module", "nickname"]: return # Argsdict Defaults From 11844ced4ef000e0d896f92851f53e9ae25dd7dc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 11:58:11 -0400 Subject: [PATCH 113/127] test --- sopel_modules/SpiceBot/Prerun.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 1a6e5fa..a7a028f 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -34,6 +34,9 @@ def prerun(t_command_type='module'): # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) + if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): + return + if t_command_type.endswith("_match"): if trigger_command_type in ["module", "nickname"]: return From 868bc0e23cfd6f07e4d846d334463b6cbc1691ff Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:13:48 -0400 Subject: [PATCH 114/127] test --- sopel_modules/SpiceBot/Prerun.py | 15 +++++---------- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Gif.py | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index a7a028f..2014827 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -23,22 +23,17 @@ def prerun(t_command_type='module'): @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): - if t_command_type.endswith("_match"): - trigger_command_type = t_command_type.replace("_match", '') - else: - trigger_command_type = t_command_type - - if trigger_command_type not in list(botcommands.dict["commands"].keys()): - return + trigger_command_type = str(t_command_type) # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) - if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): + trigger_command_type = botcommands.find_command_type(trigger_command) + if not trigger_command_type: return - if t_command_type.endswith("_match"): - if trigger_command_type in ["module", "nickname"]: + if t_command_type != trigger_command_type: + if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): return # Argsdict Defaults diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 201b094..9f71e96 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -10,7 +10,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun('prefix_match') +@SpiceBot.prerun('module') @sopel.module.commands('(.*)') def command_dictcom(bot, trigger): diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index d02b179..948338b 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -11,7 +11,7 @@ import spicemanip # TODO custom gif shortcut commands -@SpiceBot.prerun('gif_prefix') +@SpiceBot.prerun('module') @sopel.module.commands('gif') def gif_trigger(bot, trigger): @@ -30,7 +30,7 @@ def gif_trigger(bot, trigger): bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) -@SpiceBot.prerun('gif_prefix_match') +@SpiceBot.prerun('module') @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): From 81ef4bd1398cc54d9bd6de4d50fc5aac61ac6a8b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:14:04 -0400 Subject: [PATCH 115/127] test --- sopel_modules/SpiceBot/Prerun.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 2014827..71f7e35 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -49,19 +49,6 @@ def prerun(t_command_type='module'): # Create dict listings for trigger.sb argsdict_list = trigger_argsdict_list(argsdict_default, and_split) - """ - argsdict = trigger_argsdict_single(argsdict_default, trigger_args) - - trigger.sb = copy.deepcopy(argsdict) - - trigger.sb["args"], trigger.sb["hyphen_arg"] = trigger_hyphen_args(trigger.sb["args"]) - if not trigger.sb["hyphen_arg"]: - # check if anything prohibits the nick from running the command - if trigger_runstatus(bot, trigger): - function(bot, trigger, *args, **kwargs) - else: - trigger_hyphen_arg_handler(bot, trigger) - """ # Run the function for all splits for argsdict in argsdict_list: From 9a9bf6001a7fa4ddfbe2ba53ea5914de721c16d8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:18:54 -0400 Subject: [PATCH 116/127] test --- sopel_modules/SpiceBot/Prerun.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 71f7e35..615ca65 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -32,9 +32,8 @@ def prerun(t_command_type='module'): if not trigger_command_type: return - if t_command_type != trigger_command_type: - if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): - return + if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): + return # Argsdict Defaults argsdict_default = {} From 0e12d6f0e054a0193a9a58d9c0a6f43f68d60426 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:25:45 -0400 Subject: [PATCH 117/127] test --- sopel_modules/SpiceBot/Prerun.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 615ca65..9c10910 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -32,8 +32,13 @@ def prerun(t_command_type='module'): if not trigger_command_type: return - if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): - return + for comtype in [trigger_command_type, t_command_type]: + + if comtype not in list(botcommands.dict["commands"].keys()): + return + + if trigger_command not in list(botcommands.dict["commands"][comtype].keys()): + return # Argsdict Defaults argsdict_default = {} From fc719b6ee0d95f708bd7c42a00aad1b7c4194956 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:28:54 -0400 Subject: [PATCH 118/127] test --- sopel_modules/SpiceBot/Prerun.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 9c10910..35bff14 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -35,9 +35,11 @@ def prerun(t_command_type='module'): for comtype in [trigger_command_type, t_command_type]: if comtype not in list(botcommands.dict["commands"].keys()): + bot.say(str(comtype) + " not valid comtype") return if trigger_command not in list(botcommands.dict["commands"][comtype].keys()): + bot.say(str(trigger_command) + " not in " + str(comtype)) return # Argsdict Defaults From 046d9f7be0f0fc48c14086ae626d63d7aa48e99f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:32:49 -0400 Subject: [PATCH 119/127] test --- sopel_modules/SpiceBot/Commands.py | 12 +++++++----- sopel_modules/SpiceBot/Prerun.py | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 092f526..3271c45 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -58,11 +58,13 @@ class BotCommands(): self.dict['nickrules'].append(command) def find_command_type(self, command): - for commandstype in list(self.dict['commands'].keys()): - if commandstype not in ['rule']: - for com in list(self.dict['commands'][commandstype].keys()): - if com.lower() == command.lower(): - return commandstype + commandtype_list = list(self.dict['commands'].keys()) + if 'rule' in commandtype_list: + commandtype_list.remove('rule') + for commandstype in commandtype_list: + for com in list(self.dict['commands'][commandstype].keys()): + if com.lower() == command.lower(): + return commandstype return None def get_commands_disabled(self, channel): diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 35bff14..cde81b3 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -28,9 +28,11 @@ def prerun(t_command_type='module'): # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) + bot.say(str(trigger_command_type)) trigger_command_type = botcommands.find_command_type(trigger_command) if not trigger_command_type: return + bot.say(str(trigger_command_type)) for comtype in [trigger_command_type, t_command_type]: From 77e12602264dd32449bf43d3e4bd183dd0cbacd5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:34:24 -0400 Subject: [PATCH 120/127] test --- sopel_modules/SpiceBot/Prerun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index cde81b3..312a0a7 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -34,7 +34,8 @@ def prerun(t_command_type='module'): return bot.say(str(trigger_command_type)) - for comtype in [trigger_command_type, t_command_type]: + for comtypecheck in [trigger_command_type, t_command_type]: + comtype = eval(comtypecheck) if comtype not in list(botcommands.dict["commands"].keys()): bot.say(str(comtype) + " not valid comtype") From 4a15bffd013c2e25445caf163d5336201b5d0775 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:34:36 -0400 Subject: [PATCH 121/127] test --- sopel_modules/SpiceBot/Prerun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 312a0a7..62b66c0 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -34,7 +34,7 @@ def prerun(t_command_type='module'): return bot.say(str(trigger_command_type)) - for comtypecheck in [trigger_command_type, t_command_type]: + for comtypecheck in ["trigger_command_type", "t_command_type"]: comtype = eval(comtypecheck) if comtype not in list(botcommands.dict["commands"].keys()): From a546a739b3c6a708cf257c8327553e7f98603012 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 12:40:37 -0400 Subject: [PATCH 122/127] test --- sopel_modules/SpiceBot/Prerun.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 62b66c0..851d30b 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -28,21 +28,20 @@ def prerun(t_command_type='module'): # Primary command used for trigger, and a list of all words trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type) - bot.say(str(trigger_command_type)) trigger_command_type = botcommands.find_command_type(trigger_command) if not trigger_command_type: return - bot.say(str(trigger_command_type)) - for comtypecheck in ["trigger_command_type", "t_command_type"]: - comtype = eval(comtypecheck) + if trigger_command_type not in list(botcommands.dict["commands"].keys()): + return - if comtype not in list(botcommands.dict["commands"].keys()): - bot.say(str(comtype) + " not valid comtype") + if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): + return + + if trigger_command_type != t_command_type: + if t_command_type not in list(botcommands.dict["commands"].keys()): return - - if trigger_command not in list(botcommands.dict["commands"][comtype].keys()): - bot.say(str(trigger_command) + " not in " + str(comtype)) + if trigger_command in list(botcommands.dict["commands"][t_command_type].keys()): return # Argsdict Defaults From 99960263cc90050418fd4584203c1f2775345b56 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 25 Jun 2019 14:24:32 -0400 Subject: [PATCH 123/127] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 1 + sopel_modules/SpiceBot_Core_Commands/Gif.py | 1 + 2 files changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 9f71e96..52f80b8 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -13,6 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('module') @sopel.module.commands('(.*)') def command_dictcom(bot, trigger): + bot.say("here") if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()): return diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 948338b..40cd25e 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -33,6 +33,7 @@ def gif_trigger(bot, trigger): @SpiceBot.prerun('module') @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): + bot.say("here") if trigger.sb['com'] not in list(SpiceBot.gif.valid_api.keys()): return From 980fce89d56e72f907e95d6b1e5869b61d107801 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 08:11:03 -0400 Subject: [PATCH 124/127] test --- sopel_modules/SpiceBot/DictComs.py | 4 ++-- sopel_modules/SpiceBot/Prerun.py | 15 ++++----------- sopel_modules/SpiceBot/Tools.py | 1 - sopel_modules/SpiceBot_Core_Commands/DictComs.py | 5 ++--- sopel_modules/SpiceBot_Core_Commands/Gif.py | 3 +-- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 4267700..cf776cc 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -50,7 +50,7 @@ class BotDictCommands(): # simplify usage of the bot command going forward # copy dict to not overwrite - triggersb['comdict'] = copy.deepcopy(botcommands.dict['commands']["prefix"][triggersb['realcom']]) + triggersb['comdict'] = copy.deepcopy(botcommands.dict['commands']["dictcom"][triggersb['realcom']]) # execute function based on command type triggersb['comtype'] = triggersb['comdict']["type"].lower() @@ -71,7 +71,7 @@ class BotDictCommands(): dict_from_file = self.valid_dictcom_dict[jsondict] - dict_from_file["comtype"] = "prefix" + dict_from_file["comtype"] = "dictcom" # default command to filename if "validcoms" not in list(dict_from_file.keys()): diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 851d30b..a36830c 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -9,6 +9,7 @@ from sopel.tools import Identifier import functools import copy import datetime + import spicemanip from .Tools import command_permissions_check @@ -16,7 +17,7 @@ from .Commands import commands as botcommands from .Database import db as botdb -def prerun(t_command_type='module'): +def prerun(t_command_type='module', t_command_subtype=None): def actual_decorator(function): @@ -32,16 +33,8 @@ def prerun(t_command_type='module'): if not trigger_command_type: return - if trigger_command_type not in list(botcommands.dict["commands"].keys()): - return - - if trigger_command not in list(botcommands.dict["commands"][trigger_command_type].keys()): - return - - if trigger_command_type != t_command_type: - if t_command_type not in list(botcommands.dict["commands"].keys()): - return - if trigger_command in list(botcommands.dict["commands"][t_command_type].keys()): + if t_command_subtype: + if trigger_command_type != trigger_command_type: return # Argsdict Defaults diff --git a/sopel_modules/SpiceBot/Tools.py b/sopel_modules/SpiceBot/Tools.py index 84464e6..79b24c0 100644 --- a/sopel_modules/SpiceBot/Tools.py +++ b/sopel_modules/SpiceBot/Tools.py @@ -9,7 +9,6 @@ import sopel import collections import os import sys -import codecs from difflib import SequenceMatcher from operator import itemgetter from collections import abc diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 52f80b8..ffff1a4 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -10,12 +10,11 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.prerun('module') +@SpiceBot.prerun('module', 'dictcom') @sopel.module.commands('(.*)') def command_dictcom(bot, trigger): - bot.say("here") - if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()): + if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["dictcom"].keys()): return trigger.sb = SpiceBot.dictcoms.get_dict(trigger.sb) diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 40cd25e..5188f8e 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -11,7 +11,7 @@ import spicemanip # TODO custom gif shortcut commands -@SpiceBot.prerun('module') +@SpiceBot.prerun('module', "gif_prefix") @sopel.module.commands('gif') def gif_trigger(bot, trigger): @@ -33,7 +33,6 @@ def gif_trigger(bot, trigger): @SpiceBot.prerun('module') @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): - bot.say("here") if trigger.sb['com'] not in list(SpiceBot.gif.valid_api.keys()): return From 6578b394a2702dd25d3ae34ec6f03498da0f0e56 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 08:13:48 -0400 Subject: [PATCH 125/127] test --- sopel_modules/SpiceBot/Prerun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index a36830c..cacccd1 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -34,7 +34,7 @@ def prerun(t_command_type='module', t_command_subtype=None): return if t_command_subtype: - if trigger_command_type != trigger_command_type: + if trigger_command_type != t_command_subtype: return # Argsdict Defaults From a18662508497077eb12fb3db673cac5ebe918f93 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 08:21:53 -0400 Subject: [PATCH 126/127] test --- sopel_modules/SpiceBot_Core_Commands/Gif.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 5188f8e..5ab145a 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -11,7 +11,7 @@ import spicemanip # TODO custom gif shortcut commands -@SpiceBot.prerun('module', "gif_prefix") +@SpiceBot.prerun('module') @sopel.module.commands('gif') def gif_trigger(bot, trigger): @@ -30,7 +30,7 @@ def gif_trigger(bot, trigger): bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) -@SpiceBot.prerun('module') +@SpiceBot.prerun('module', "gif_prefix") @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): From aaa0a55c9bca28654f58585227d161231b60e8db Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 08:38:50 -0400 Subject: [PATCH 127/127] quality patch for pushing --- sopel_modules/SpiceBot_Core_Commands/{DictComs.py => DictComs} | 0 sopel_modules/SpiceBot_Core_Commands/__init__.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename sopel_modules/SpiceBot_Core_Commands/{DictComs.py => DictComs} (100%) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs similarity index 100% rename from sopel_modules/SpiceBot_Core_Commands/DictComs.py rename to sopel_modules/SpiceBot_Core_Commands/DictComs diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index e4b9d44..97c416c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -21,7 +21,7 @@ from .AI import * from .Gif import * from .Sherlock import * from .Reddit import * -from .DictComs import * +# from .DictComs import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net'