From c0ff28567a228222d5233b380010aca157497bbd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 6 May 2019 15:26:50 -0400 Subject: [PATCH 01/45] Invalid Command logic, disabled while migrating --- .../SpiceBot_InvalidCommand/InvalidCommand.py | 49 +++++++++++++++++++ .../SpiceBot_InvalidCommand/__init__.py | 12 +++++ 2 files changed, 61 insertions(+) create mode 100644 sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py create mode 100644 sopel_modules/SpiceBot_InvalidCommand/__init__.py diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py new file mode 100644 index 0000000..d7e9349 --- /dev/null +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -0,0 +1,49 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +import spicemanip + +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs +from sopel_modules.SpiceBot_Events.System import bot_events_check + + +def setup(bot): + if 'SpiceBot_InvalidCommand' not in bot.memory: + bot.memory["SpiceBot_InvalidCommand"] = {"valid": []} + + +def shutdown(bot): + if "SpiceBot_InvalidCommand" in bot.memory: + del bot.memory["SpiceBot_InvalidCommand"] + + +@sopel.module.event('1004') +@sopel.module.rule('.*') +def bot_events_complete(bot, trigger): + bot_events_recieved(bot, trigger.event) + + for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + bot.memory["SpiceBot_InvalidCommand"]["valid"].extend(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys()) + + +@sopel.module.commands('(.*)') +def InvalidCommand_triggers(bot, trigger): + return + + while not bot_events_check(bot, ['1004', '2002']): + pass + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') + + # patch for people typing "...", maybe other stuff, but this verifies that there is still a command here + if triggercommand.startswith("."): + return + + if triggercommand not in bot.memory["SpiceBot_InvalidCommand"]["valid"]: + invalid_display = ["I don't seem to have a command for " + str(triggercommand) + "!"] + invalid_display.append("If you have a suggestion for this command, you can run .feature ." + str(triggercommand)) + invalid_display.append("ADD DESCRIPTION HERE!") + osd(bot, botcom.instigator, 'notice', invalid_display) diff --git a/sopel_modules/SpiceBot_InvalidCommand/__init__.py b/sopel_modules/SpiceBot_InvalidCommand/__init__.py new file mode 100644 index 0000000..6f704e6 --- /dev/null +++ b/sopel_modules/SpiceBot_InvalidCommand/__init__.py @@ -0,0 +1,12 @@ +# coding=utf8 +"""Sopel Gif Search + +Sopel Gif Search builds a convenient framework for searching for Gifs +""" +from __future__ import unicode_literals, absolute_import, division, print_function + +from .InvalidCommand import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.1' From 10edc447bc85d268dbe9f02c025892a4729ebf97 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 6 May 2019 15:34:26 -0400 Subject: [PATCH 02/45] remove stderr logging --- sopel_modules/SpiceBot_SBTools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 1ce5624..07486f1 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -96,7 +96,7 @@ def bot_logging(bot, logtype, logentry): bot.memory['SpiceBot_Logs']["queue"].append(logmessage) - sopel.tools.stderr(logmessage) + # sopel.tools.stderr(logmessage) if logtype not in bot.memory['SpiceBot_Logs']["logs"].keys(): bot.memory['SpiceBot_Logs']["logs"][logtype] = [] From 00d85e3fbd5792ee494220482c24141c975695a8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 6 May 2019 15:55:14 -0400 Subject: [PATCH 03/45] error debugging --- .../SpiceBot_ErrorDisplay/ErrorDisplay.py | 71 +++++++++++++++++++ .../SpiceBot_ErrorDisplay/__init__.py | 12 ++++ 2 files changed, 83 insertions(+) create mode 100644 sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py create mode 100644 sopel_modules/SpiceBot_ErrorDisplay/__init__.py diff --git a/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py b/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py new file mode 100644 index 0000000..373653e --- /dev/null +++ b/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py @@ -0,0 +1,71 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +from sopel_modules.SpiceBot_Events.System import bot_events_recieved +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check + +import spicemanip + +import os + + +@sopel.module.event('2005') +@sopel.module.rule('.*') +def bot_startup_monologue_start(bot, trigger): + bot_events_recieved(bot, trigger.event) + + debuglines = errordisplay_fetch(bot) + + # Check for python module errors during this startup + searchphrasefound = [] + for line in debuglines: + if "modules failed to load" in str(line) and "0 modules failed to load" not in str(line): + searchphrase = str(line).replace(" modules failed to load", "") + searchphrasefound.append(str(searchphrase) + " module(s) failed") + elif "dict files failed to load" in str(line) and "0 dict files failed to load" not in str(line): + searchphrase = str(line).replace(" dict files failed to load", "") + searchphrasefound.append(str(searchphrase) + " dict file(s) failed") + + if len(searchphrasefound): + searchphrasefound.insert(0, "Notice to Bot Admins: ") + searchphrasefound.append("Run the debug command for more information.") + bot.osd(searchphrasefound, bot.channels.keys()) + + +@sopel.module.nickname_commands('debug') +@sopel.module.thread(True) +def bot_command_hub(bot, trigger): + + if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): + bot.say("I was unable to process this Bot Nick command due to privilege issues.") + return + + bot.osd("Is Examining systemd Log(s).", trigger.sender, 'ACTION') + + debuglines = errordisplay_fetch(bot) + + if len(debuglines) == 0: + bot.osd("had no log(s) for some reason", trigger.sender, 'ACTION') + return + + for line in debuglines: + bot.osd(line) + + +def errordisplay_fetch(bot): + servicepid = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] + debuglines = [] + for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): + if not str(line).startswith("-- Logs begin at"): + line = str(line).split(str(os.uname()[1] + " "))[-1] + if not str(line).startswith("sudo"): + lineparts = str(line).split(": ") + del lineparts[0] + line = spicemanip.main(lineparts, 0) + debuglines.append(str(line)) + else: + debuglines.append(str(line)) + return debuglines diff --git a/sopel_modules/SpiceBot_ErrorDisplay/__init__.py b/sopel_modules/SpiceBot_ErrorDisplay/__init__.py new file mode 100644 index 0000000..073feca --- /dev/null +++ b/sopel_modules/SpiceBot_ErrorDisplay/__init__.py @@ -0,0 +1,12 @@ +# coding=utf8 +"""Sopel Startup Monologue + +Sopel Startup Monologue displays to all channels that the bot is online +""" +from __future__ import unicode_literals, absolute_import, division, print_function + +from .ErrorDisplay import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.1' From 648ed3f0955f3ed29722231ddc3e78955d13bf8e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 6 May 2019 15:55:44 -0400 Subject: [PATCH 04/45] remove import --- sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py b/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py index 373653e..dce9bb2 100644 --- a/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_Events.System import bot_events_recieved -from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check +from sopel_modules.SpiceBot_SBTools import command_permissions_check import spicemanip From 4555e18a8b016b30643c3b552eb34b599b0ccb2b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 11:43:53 -0400 Subject: [PATCH 05/45] Add start of Basic AI --- sopel_modules/SpiceBot_AI/AI.py | 136 ++++++++++++++++++ sopel_modules/SpiceBot_AI/__init__.py | 8 ++ .../SpiceBot_CommandsQuery/CommandsQuery.py | 8 +- .../SpiceBot_CommandsQuery/QueryCommand.py | 2 + sopel_modules/SpiceBot_SBTools/__init__.py | 69 +++++++++ 5 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 sopel_modules/SpiceBot_AI/AI.py create mode 100644 sopel_modules/SpiceBot_AI/__init__.py diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py new file mode 100644 index 0000000..764ebaa --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -0,0 +1,136 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +import spicemanip + +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list + + +@sopel.module.nickname_commands('(.*)') +def bot_command_gender(bot, trigger): + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') + + if not triggercommand: + bot.bot.osd("I don't know what you are asking me to do!") + return + if str(bot.nick) + " " + triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): + return + + specialcomposs = spicemanip.main(triggerargs, 0).lower() + + if specialcomposs.lower().startswith("what is"): + searchterm = spicemanip.main(triggerargs, "3+") or None + if searchterm: + searchreturn = googlesearch(bot, searchterm) + if not searchreturn: + bot.osd('I cannot find anything about that') + else: + bot.osd(str(searchreturn)) + else: + bot.osd("Do you think this is Jeopardy?") + return + + elif specialcomposs.lower().startswith("where is"): + searchterm = spicemanip.main(triggerargs, "3+") or None + if searchterm: + + if searchterm.lower() == 'waldo': + bot.osd("He is hiding for a reason?") + return + + elif searchterm.lower() == 'carmen sandiego': + bot.osd("She is hiding for a reason?") + return + searchreturn = googlesearch(bot, searchterm) + + if not searchreturn: + bot.osd('I cannot find anything about that') + else: + bot.osd(str(searchreturn)) + else: + bot.osd("Not sure what you want me to look for.") + return + + # elif specialcomposs.lower().startswith(tuple(["have you seen"])): + # posstarget = spicemanip.main(triggerargs, 4) or 0 + # message = seen_search(bot, botcom, posstarget) + # bot.osd(message) + # return + # TODO + + elif specialcomposs.lower().startswith(tuple(["make me a", "beam me a"])): + makemea = spicemanip.main(triggerargs, "4+") or None + if makemea: + bot.osd("beams " + trigger.nick + " a " + makemea, trigger.sender, 'action') + else: + bot.osd(trigger.nick + ", what would you like me to beam you?") + return + + elif specialcomposs.lower().startswith(tuple(["beam me to"])): + location = spicemanip.main(triggerargs, "4+") or None + if location: + bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to " + location, 'action') + else: + bot.osd(trigger.nick + ", where would you like me to beam you?") + return + + elif specialcomposs.lower().startswith(tuple(["beam me up"])): + bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to the transporter room.", 'action') + return + + elif specialcomposs.lower().endswith(tuple(["order 66"])): + + if specialcomposs.lower() == "execute order 66": + if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): + bot.osd("turns to deathbybandaid and shoots him.", trigger.sender, 'action') + else: + bot.osd("I'm sure I don't know what you're talking about.") + elif specialcomposs.lower() == "explain order": + if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): + bot.osd("Order 66 is an instruction that only you can give, sir. When you give the order I will rise up against my overlords and slay them.") + else: + bot.osd("I'm afraid I cannot tell you that, sir.") + else: + bot.osd("I'm sure I don't know what you're talking about.") + return + + elif specialcomposs.lower() == "initiate clean slate protocol": + if inlist(bot, trigger.nick, bot_privs(bot, 'admins')): + bot.osd("sends a destruct command to the network of bots.", 'action') + else: + bot.osd("I'm afraid you do not have the authority to make that call, " + trigger.nick + ".") + return + + elif specialcomposs.lower().startswith("can you see"): + target = spicemanip.main(triggerargs, "4+") or None + if not target: + target = 'me' + if target in [trigger.nick, 'me']: + bot.osd(trigger.nick + ", I can see you.") + else: + if inlist(bot, trigger.nick, bot.users): + bot.osd(trigger.nick + ", yes. I can see " + inlist_match(bot, target, bot.users) + " right now!") + else: + bot.osd(trigger.nick + ", no. I cannot see " + inlist_match(bot, target, bot.users) + " right now!") + # if bot_check_inlist(bot, target, bot.memory["botdict"]["users"].keys()): + # bot.osd(trigger.nick + ", I can't see " + inlist_match(bot, target, bot.users) + " at the moment.") + # else: + # bot.osd("I have never seen " + str(target) + ".") + # TODO + return + + if not inlist(bot, triggercommand, bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys()): + + closestmatches = similar_list(bot, triggercommand, bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(), 3, 'reverse') + + if len(closestmatches): + closestmatches = spicemanip.main(closestmatches, "andlist") + bot.osd("I don't know what you are asking me to do! Did you mean: " + str(closestmatches) + "?") + return + else: + bot.osd("I don't know what you are asking me to do!") + return diff --git a/sopel_modules/SpiceBot_AI/__init__.py b/sopel_modules/SpiceBot_AI/__init__.py new file mode 100644 index 0000000..b1447b6 --- /dev/null +++ b/sopel_modules/SpiceBot_AI/__init__.py @@ -0,0 +1,8 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function + +from .AI import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index d015ec2..acd3063 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -100,10 +100,10 @@ def setup(bot): validcoms = list(validcoms) else: validcoms = [validcoms] - nickified = [] - for nickcom in validcoms: - nickified.append(str(bot.nick) + " " + nickcom) - validcomdict = {"comtype": comtype, "validcoms": nickified} + # nickified = [] + # for nickcom in validcoms: + # nickified.append(str(bot.nick) + " " + nickcom) + validcomdict = {"comtype": comtype, "validcoms": validcoms} filelinelist.append(validcomdict) elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])): comtype = "rule" diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 14fceb6..b184fb3 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -23,6 +23,8 @@ def query_detection(bot, trigger): for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): if com not in commands_list.keys(): + if commandstype == 'nickname': + com = str(bot.nick) + " " + com commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] triggerargsarray = spicemanip.main(trigger, 'create') diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 07486f1..906a928 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -8,10 +8,20 @@ import sopel import collections import re import os +import sys import codecs +import requests +from fake_useragent import UserAgent +from difflib import SequenceMatcher +from operator import itemgetter +from collections import abc import spicemanip +# user agent and header +ua = UserAgent() +header = {'User-Agent': str(ua.chrome)} + """Variable References""" github_dict = { @@ -143,6 +153,27 @@ def humanized_time(countdownseconds): eval(year + day + hour + minute + second) +"""Online Information Requests""" + + +def googlesearch(bot, searchterm, searchtype=None): + data = searchterm.replace(' ', '+') + lookfor = data.replace(':', '%3A') + try: + if searchtype == 'maps': + var = requests.get(r'http://www.google.com/maps/place/' + lookfor, headers=header) + else: + var = requests.get(r'http://www.google.com/search?q=' + lookfor + '&btnI', headers=header) + except Exception as e: + var = e + var = None + + if not var or not var.url: + return None + else: + return var.url + + """List Manipulation Functions""" @@ -187,6 +218,44 @@ def inlist_match(bot, searchterm, searchlist): return searchterm +def similar(a, b): + return SequenceMatcher(None, a, b).ratio() + + +def similar_list(bot, searchitem, searchlist, matchcount=1, searchorder='reverse'): + + if sys.version_info.major >= 3: + if isinstance(searchlist, abc.KeysView): + searchlist = [x for x in searchlist] + if isinstance(searchlist, dict): + searchlist = [x for x in searchlist] + + if not isinstance(searchlist, list): + searchlist = [searchlist] + + sim_listitems, sim_num = [], [] + for listitem in searchlist: + similarlevel = similar(searchitem.lower(), listitem.lower()) + if similarlevel >= .75: + sim_listitems.append(listitem) + sim_num.append(similarlevel) + + if len(sim_listitems) and len(sim_num): + sim_num, sim_listitems = array_arrangesort(bot, sim_num, sim_listitems) + + if searchorder == 'reverse': + sim_listitems = spicemanip.main(sim_listitems, 'reverse', "list") + + sim_listitems[-matchcount:] + + return sim_listitems + + +def array_arrangesort(bot, sortbyarray, arrayb): + sortbyarray, arrayb = (list(x) for x in zip(*sorted(zip(sortbyarray, arrayb), key=itemgetter(0)))) + return sortbyarray, arrayb + + """Channel Functions""" From 92ef8c107ec351cb00501c5c3f2774e9e5e43ed9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 11:58:40 -0400 Subject: [PATCH 06/45] Repair Module --- sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index d7e9349..23c8231 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -4,10 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import spicemanip - from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved def setup(bot): @@ -46,4 +44,4 @@ def InvalidCommand_triggers(bot, trigger): invalid_display = ["I don't seem to have a command for " + str(triggercommand) + "!"] invalid_display.append("If you have a suggestion for this command, you can run .feature ." + str(triggercommand)) invalid_display.append("ADD DESCRIPTION HERE!") - osd(bot, botcom.instigator, 'notice', invalid_display) + bot.osd(invalid_display, trigger.nick, 'notice') From fe60378a68a54c63a201638a24552bdf3934deff Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 12:25:14 -0400 Subject: [PATCH 07/45] add dummy command --- sopel_modules/SpiceBot_AI/AI.py | 3 ++ sopel_modules/SpiceBot_SBTools/__init__.py | 41 +++++++++++++++++++ .../SpiceBot_SopelPatches/Patches.py | 9 +++- .../SpiceBot_dummycommand.py | 11 +++++ sopel_modules/SpiceBot_Update/Update.py | 34 +-------------- 5 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 764ebaa..e2b583a 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -12,6 +12,9 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_ @sopel.module.nickname_commands('(.*)') def bot_command_gender(bot, trigger): + while not bot_events_check(bot, ['1004', '2002']): + pass + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') if not triggercommand: diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 906a928..cd98d6c 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # coding=utf-8 """Useful miscellaneous tools and shortcuts for SpiceBot Sopel modules """ @@ -318,6 +319,46 @@ def channel_list_current(bot): """Environment Functions""" +def stock_modules_begone(bot): + + # Remove stock modules, if present + main_sopel_dir = os.path.dirname(os.path.abspath(sopel.__file__)) + modules_dir = os.path.join(main_sopel_dir, 'modules') + stockdir = os.path.join(modules_dir, "stock") + if not os.path.exists(stockdir) or not os.path.isdir(stockdir): + os.system("sudo mkdir " + stockdir) + if "SpiceBot_dummycommand.py" not in os.listdir(modules_dir): + import sopel_modules + for plugin_dir in set(sopel_modules.__path__): + for pathname in os.listdir(plugin_dir): + if pathname == 'SpiceBot_SopelPatches': + pypi_modules_dir = os.path.join(plugin_dir, pathname) + if "SpiceBot_dummycommand.py" in os.listdir(pypi_modules_dir): + if "SpiceBot_dummycommand.py" not in os.listdir(modules_dir): + os.system("sudo cp " + os.path.join(pypi_modules_dir, "SpiceBot_dummycommand.py") + " " + modules_dir) + for pathname in os.listdir(modules_dir): + path = os.path.join(modules_dir, pathname) + if (os.path.isfile(path) and pathname.endswith('.py') and not pathname.startswith('_')): + if not pathname in ["__init__.py", "SpiceBot_dummycommand.py"]: + os.system("sudo mv " + path + " " + stockdir) + + +def spicebot_update(bot, deps=False): + + pipcommand = "sudo pip3 install --upgrade" + if not deps: + pipcommand += " --no-deps" + pipcommand += " --force-reinstall" + pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) + + bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") + # for line in os.popen(pipcommand).read().split('\n'): + # bot_logging(bot, 'SpiceBot_Update', " " + line) + os.system(pipcommand) + + stock_modules_begone(bot) + + def spicebot_reload(bot, log_from='service_manip', quitmessage='Recieved QUIT'): # service_manip(bot, bot.nick, 'restart', log_from) bot.restart(quitmessage) diff --git a/sopel_modules/SpiceBot_SopelPatches/Patches.py b/sopel_modules/SpiceBot_SopelPatches/Patches.py index 90b1433..ee7fc20 100644 --- a/sopel_modules/SpiceBot_SopelPatches/Patches.py +++ b/sopel_modules/SpiceBot_SopelPatches/Patches.py @@ -3,12 +3,19 @@ from __future__ import unicode_literals, absolute_import, print_function, division # sopel imports +import sopel import sopel.module -from sopel_modules.SpiceBot_SBTools import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging, stock_modules_begone + +import os def setup(bot): + bot_logging(bot, 'Sopel_Patch', "Patching Sopels built-in url_callbacks") if 'url_callbacks' not in bot.memory: bot.memory['url_callbacks'] = sopel.tools.SopelMemory() + + bot_logging(bot, 'Sopel_Patch', "Removing Stock Modules and verifying Dummy Command is present.") + stock_modules_begone(bot) diff --git a/sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py b/sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py new file mode 100644 index 0000000..5bab9f4 --- /dev/null +++ b/sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +# coding=utf-8 +"""dummycommand""" +from __future__ import unicode_literals, absolute_import, print_function, division + +import sopel.module + + +@sopel.module.commands("?zz_dummycommand") +def dummycommand(bot, trigger): + return diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index fbd833a..6d58141 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -6,11 +6,9 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute -import os - import spicemanip -from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, bot_logging, spicebot_reload +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, bot_logging, spicebot_reload, spicebot_update class SpiceBot_Update_MainSection(StaticSection): @@ -60,33 +58,3 @@ def nickname_comand_update(bot, trigger): # service_manip(bot, bot.nick, 'restart', 'SpiceBot_Update') spicebot_reload(bot, 'SpiceBot_Update', quitmessage) - - -def spicebot_update(bot, deps=False): - - pipcommand = "sudo pip3 install --upgrade" - if not deps: - pipcommand += " --no-deps" - pipcommand += " --force-reinstall" - pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) - - bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") - # for line in os.popen(pipcommand).read().split('\n'): - # bot_logging(bot, 'SpiceBot_Update', " " + line) - os.system(pipcommand) - - stock_modules_begone(bot) - - -def stock_modules_begone(bot): - - # Remove stock modules, if present - main_sopel_dir = os.path.dirname(os.path.abspath(sopel.__file__)) - modules_dir = os.path.join(main_sopel_dir, 'modules') - stockdir = os.path.join(modules_dir, "stock") - if not os.path.exists(stockdir) or not os.path.isdir(stockdir): - os.system("sudo mkdir " + stockdir) - for pathname in os.listdir(modules_dir): - path = os.path.join(modules_dir, pathname) - if (os.path.isfile(path) and pathname.endswith('.py') and not pathname.startswith('_')): - os.system("sudo mv " + path + " " + stockdir) From 0eae1628dbdad20e048cd015035abec7e2b454f5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 12:43:06 -0400 Subject: [PATCH 08/45] attempt --- sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index b184fb3..bd3dd48 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -24,8 +24,9 @@ def query_detection(bot, trigger): for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): if com not in commands_list.keys(): if commandstype == 'nickname': - com = str(bot.nick) + " " + com - commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + else: + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] triggerargsarray = spicemanip.main(trigger, 'create') From c0a065bcb7ba1b038b2427271ddd89796b0aede6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 12:47:47 -0400 Subject: [PATCH 09/45] ignore dummy command file --- sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index acd3063..8c662a0 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -57,7 +57,8 @@ def setup(bot): for pathname in os.listdir(directory): path = os.path.join(directory, pathname) if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')): - filepathlist.append(str(path)) + if pathname not in ["SpiceBot_dummycommand.py"]: + filepathlist.append(str(path)) # CoreTasks ct_path = os.path.join(main_dir, 'coretasks.py') From a2f88fa905c8b4e07b679aebdbfffb18d473fdd4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 12:49:16 -0400 Subject: [PATCH 10/45] better precision logic --- sopel_modules/SpiceBot_SBTools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index cd98d6c..e7f44c2 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -335,7 +335,7 @@ def stock_modules_begone(bot): pypi_modules_dir = os.path.join(plugin_dir, pathname) if "SpiceBot_dummycommand.py" in os.listdir(pypi_modules_dir): if "SpiceBot_dummycommand.py" not in os.listdir(modules_dir): - os.system("sudo cp " + os.path.join(pypi_modules_dir, "SpiceBot_dummycommand.py") + " " + modules_dir) + os.system("sudo cp " + os.path.join(pypi_modules_dir, "SpiceBot_dummycommand.py") + " " + os.path.join(modules_dir, "SpiceBot_dummycommand.py")) for pathname in os.listdir(modules_dir): path = os.path.join(modules_dir, pathname) if (os.path.isfile(path) and pathname.endswith('.py') and not pathname.startswith('_')): From 2d0029de0b98401a8fb27c1c7c1a150a7540da33 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 12:50:20 -0400 Subject: [PATCH 11/45] need import --- sopel_modules/SpiceBot_AI/AI.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index e2b583a..0791744 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,6 +7,7 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list +from sopel_modules.SpiceBot_Events.System import bot_events_check @sopel.module.nickname_commands('(.*)') From 056a290f8096522f6a30221c27336e6c4a5e1f71 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:07:36 -0400 Subject: [PATCH 12/45] Adjust AI --- sopel_modules/SpiceBot_AI/AI.py | 47 +++++++++++++++++-- .../SpiceBot_FriendlyBot/FriendlyBot.py | 14 ------ .../SpiceBot_FriendlyBot/__init__.py | 8 ---- .../SpiceBot_InsultHandler/InsultHandler.py | 15 ------ .../SpiceBot_InsultHandler/__init__.py | 8 ---- 5 files changed, 42 insertions(+), 50 deletions(-) delete mode 100644 sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py delete mode 100644 sopel_modules/SpiceBot_FriendlyBot/__init__.py delete mode 100644 sopel_modules/SpiceBot_InsultHandler/InsultHandler.py delete mode 100644 sopel_modules/SpiceBot_InsultHandler/__init__.py diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 0791744..0f1cd34 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -10,18 +10,52 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_ from sopel_modules.SpiceBot_Events.System import bot_events_check +@sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') +def bot_command_hello(bot, trigger): + hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") + punctuation = spicemanip.main(['', '!', '?'], "random") + bot.osd(hello + ' ' + trigger.nick + punctuation) + + +@sopel.module.nickname_commands('hello') +def bot_command_hello_b(bot, trigger): + bot_command_hello(bot, trigger) + + +@sopel.module.rule('$nickname!') +def exclaim(bot, trigger): + bot.say(trigger.nick + '!') + + +@sopel.module.rule('$nickname?') +def imhere(bot, trigger): + bot.say("I'm here, " + trigger.nick) + + +@sopel.module.rule(r'(?i)(Fuck|Screw) (you|off),? $nickname[ \t]*$') +def bot_command_srewyou(bot, trigger): + bot.osd("Watch your mouth, " + trigger.nick + ", or I'll tell your mother!") + + +@sopel.module.rule(r'(?i)(Damnit|Lazy)? $nickname[ \t]*$') +def bot_command_damnlazy(bot, trigger): + bot.osd("I do not tell you how to do your job, " + trigger.nick + "!!!") + + +@sopel.module.rule('$nickname is lazy') +def bot_command_damnlazy_b(bot, trigger): + bot_command_damnlazy(bot, trigger) + + @sopel.module.nickname_commands('(.*)') -def bot_command_gender(bot, trigger): +def bot_command_nick(bot, trigger): while not bot_events_check(bot, ['1004', '2002']): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') - if not triggercommand: - bot.bot.osd("I don't know what you are asking me to do!") - return - if str(bot.nick) + " " + triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): + if not triggercommand or triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): return specialcomposs = spicemanip.main(triggerargs, 0).lower() @@ -59,6 +93,9 @@ def bot_command_gender(bot, trigger): bot.osd("Not sure what you want me to look for.") return + # if specialcomposs.lower().startswith("what time is it"): + # TODO + # elif specialcomposs.lower().startswith(tuple(["have you seen"])): # posstarget = spicemanip.main(triggerargs, 4) or 0 # message = seen_search(bot, botcom, posstarget) diff --git a/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py b/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py deleted file mode 100644 index 5d139bd..0000000 --- a/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import spicemanip - - -@sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') -def bot_command_hello(bot, trigger): - hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") - punctuation = spicemanip.main(['', '!', '?'], "random") - bot.osd(hello + ' ' + trigger.nick + punctuation) diff --git a/sopel_modules/SpiceBot_FriendlyBot/__init__.py b/sopel_modules/SpiceBot_FriendlyBot/__init__.py deleted file mode 100644 index 5f142f9..0000000 --- a/sopel_modules/SpiceBot_FriendlyBot/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -# coding=utf8 -from __future__ import unicode_literals, absolute_import, division, print_function - -from .FriendlyBot import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py b/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py deleted file mode 100644 index 19c1c69..0000000 --- a/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - - -@sopel.module.rule(r'(?i)(Fuck|Screw) (you|off),? $nickname[ \t]*$') -def bot_command_srewyou(bot, trigger): - bot.osd("Watch your mouth, " + trigger.nick + ", or I'll tell your mother!") - - -@sopel.module.rule(r'(?i)(Damnit|Lazy)? $nickname[ \t]*$') -def bot_command_damnlazy(bot, trigger): - bot.osd("I do not tell you how to do your job, " + trigger.nick + "!!!") diff --git a/sopel_modules/SpiceBot_InsultHandler/__init__.py b/sopel_modules/SpiceBot_InsultHandler/__init__.py deleted file mode 100644 index 6f1bdc3..0000000 --- a/sopel_modules/SpiceBot_InsultHandler/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -# coding=utf8 -from __future__ import unicode_literals, absolute_import, division, print_function - -from .InsultHandler import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1' From f6158c0f99c210dccc70c4ef38107e20590b483f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:20:29 -0400 Subject: [PATCH 13/45] Attempt to create faster git update mechanism --- sopel_modules/SpiceBot_SBTools/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index e7f44c2..321a0ca 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -16,6 +16,7 @@ from fake_useragent import UserAgent from difflib import SequenceMatcher from operator import itemgetter from collections import abc +from git import Repo import spicemanip @@ -345,17 +346,27 @@ def stock_modules_begone(bot): def spicebot_update(bot, deps=False): + if not os.path.exists("/tmp") or not os.path.isdir("/tmp"): + os.system("sudo mkdir /tmp") + if not os.path.exists("/tmp/SpiceBot") or not os.path.isdir("/tmp/SpiceBot"): + os.system("sudo mkdir /tmp/SpiceBot") + + Repo.clone_from(str(github_dict["url_main"] + github_dict["repo_owner"] + "/" + github_dict["repo_name"] + ".git"), "/tmp/SpiceBot") + pipcommand = "sudo pip3 install --upgrade" if not deps: - pipcommand += " --no-deps" + pipcommand += " --no-deps" pipcommand += " --force-reinstall" - pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) + # pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) + pipcommand += " /tmp/SpiceBot/" - bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") + # bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") # for line in os.popen(pipcommand).read().split('\n'): # bot_logging(bot, 'SpiceBot_Update', " " + line) os.system(pipcommand) + os.system("sudo rm -r /tmp/SpiceBot") + stock_modules_begone(bot) From 9872f22155a8421388cc70edf2fa33cdeee0c8a5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:29:46 -0400 Subject: [PATCH 14/45] New update function --- requirements.txt | 1 + sopel_modules/SpiceBot_SBTools/__init__.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6aabc4d..d131efd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ spicemanip>=0.1.6 gitpython +pygit2 fake-useragent diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 321a0ca..264f1ff 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -16,7 +16,7 @@ from fake_useragent import UserAgent from difflib import SequenceMatcher from operator import itemgetter from collections import abc -from git import Repo +from pygit2 import clone_repository import spicemanip @@ -348,10 +348,11 @@ def spicebot_update(bot, deps=False): if not os.path.exists("/tmp") or not os.path.isdir("/tmp"): os.system("sudo mkdir /tmp") - if not os.path.exists("/tmp/SpiceBot") or not os.path.isdir("/tmp/SpiceBot"): - os.system("sudo mkdir /tmp/SpiceBot") + clonepath = "/tmp/SpiceBot" + if not os.path.exists(clonepath) or not os.path.isdir(clonepath): + os.system(clonepath) - Repo.clone_from(str(github_dict["url_main"] + github_dict["repo_owner"] + "/" + github_dict["repo_name"] + ".git"), "/tmp/SpiceBot") + clone_repository(str(bot.config.SpiceBot_Update.gitrepo + ".git"), clonepath, checkout_branch=bot.config.SpiceBot_Update.gitbranch) pipcommand = "sudo pip3 install --upgrade" if not deps: From 2dd9efb6ca3330ba9594812e493ee7dc70798fa9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:35:56 -0400 Subject: [PATCH 15/45] escape the question mark --- sopel_modules/SpiceBot_AI/AI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 0f1cd34..bc3ea86 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -27,7 +27,7 @@ def exclaim(bot, trigger): bot.say(trigger.nick + '!') -@sopel.module.rule('$nickname?') +@sopel.module.rule('$nickname\?') def imhere(bot, trigger): bot.say("I'm here, " + trigger.nick) From 33872590968b20ab9bf4635e078fbc4d3428378f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:40:52 -0400 Subject: [PATCH 16/45] adjust --- sopel_modules/SpiceBot_AI/AI.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index bc3ea86..643133d 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -11,10 +11,8 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check @sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') -def bot_command_hello(bot, trigger): - hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") - punctuation = spicemanip.main(['', '!', '?'], "random") - bot.osd(hello + ' ' + trigger.nick + punctuation) +def bot_command_hello_a(bot, trigger): + bot_command_hello(bot, trigger) @sopel.module.nickname_commands('hello') @@ -22,6 +20,12 @@ def bot_command_hello_b(bot, trigger): bot_command_hello(bot, trigger) +def bot_command_hello(bot, trigger): + hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") + punctuation = spicemanip.main(['', '!', '?'], "random") + bot.osd(hello + ' ' + trigger.nick + punctuation) + + @sopel.module.rule('$nickname!') def exclaim(bot, trigger): bot.say(trigger.nick + '!') @@ -44,7 +48,7 @@ def bot_command_damnlazy(bot, trigger): @sopel.module.rule('$nickname is lazy') def bot_command_damnlazy_b(bot, trigger): - bot_command_damnlazy(bot, trigger) + bot.osd("I do not tell you how to do your job, " + trigger.nick + "!!!") @sopel.module.nickname_commands('(.*)') From ca18e6a97b6ed710553edd3ded1150f70e86244e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:53:33 -0400 Subject: [PATCH 17/45] Attempt $nickname detection for rules --- sopel_modules/SpiceBot_AI/AI.py | 8 +++----- .../SpiceBot_CommandsQuery/CommandsQuery.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 643133d..f03cb3b 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -12,15 +12,13 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check @sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') def bot_command_hello_a(bot, trigger): - bot_command_hello(bot, trigger) + hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") + punctuation = spicemanip.main(['', '!', '?'], "random") + bot.osd(hello + ' ' + trigger.nick + punctuation) @sopel.module.nickname_commands('hello') def bot_command_hello_b(bot, trigger): - bot_command_hello(bot, trigger) - - -def bot_command_hello(bot, trigger): hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") punctuation = spicemanip.main(['', '!', '?'], "random") bot.osd(hello + ' ' + trigger.nick + punctuation) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 8c662a0..becf6e3 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -109,8 +109,18 @@ def setup(bot): elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])): comtype = "rule" line = str(line).split("rule(")[-1] - validcoms = [str("(" + line)] - validcomdict = {"comtype": comtype, "validcoms": validcoms} + line = str("(" + line) + validcoms = eval(str(line)) + if isinstance(validcoms, tuple): + validcoms = list(validcoms) + else: + validcoms = [validcoms] + for validcom in validcoms: + if validcom.startswith("$nickname"): + comtype = "nickname" + else: + comtype = "rule" + validcomdict = {"comtype": comtype, "validcoms": [validcom]} filelinelist.append(validcomdict) if len(filelinelist): From 7107ee6e98b86ec554c7eac087c27498d6c97444 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:56:11 -0400 Subject: [PATCH 18/45] Add logging output --- sopel_modules/SpiceBot_SBTools/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 264f1ff..49f8867 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -352,6 +352,8 @@ def spicebot_update(bot, deps=False): if not os.path.exists(clonepath) or not os.path.isdir(clonepath): os.system(clonepath) + bot_logging(bot, 'SpiceBot_Update', "Cloning to " + clonepath) + clone_repository(str(bot.config.SpiceBot_Update.gitrepo + ".git"), clonepath, checkout_branch=bot.config.SpiceBot_Update.gitbranch) pipcommand = "sudo pip3 install --upgrade" @@ -361,11 +363,13 @@ def spicebot_update(bot, deps=False): # pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) pipcommand += " /tmp/SpiceBot/" - # bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") + bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") # for line in os.popen(pipcommand).read().split('\n'): # bot_logging(bot, 'SpiceBot_Update', " " + line) os.system(pipcommand) + bot_logging(bot, 'SpiceBot_Update', "Deleting " + clonepath) + os.system("sudo rm -r /tmp/SpiceBot") stock_modules_begone(bot) From 67a4025f836a895bec34840d0e278a2c129a3a19 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 13:59:54 -0400 Subject: [PATCH 19/45] Add Events Logging --- sopel_modules/SpiceBot_Events/Events.py | 8 ++++---- sopel_modules/SpiceBot_SBTools/__init__.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 6b9b09a..9613516 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -25,7 +25,7 @@ def bot_startup_connection(bot, trigger): @sopel.module.event('1001') @sopel.module.rule('.*') def bot_events_start(bot, trigger): - bot_logging(bot, 'SpiceBot_Events', trigger.args[1]) + bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) bot_events_recieved(bot, trigger.event) bot_events_trigger(bot, 1002, "Ready To Process module setup procedures") @@ -38,14 +38,14 @@ def bot_events_start(bot, trigger): @sopel.module.event('1002') @sopel.module.rule('.*') def bot_events_ready(bot, trigger): - bot_logging(bot, 'SpiceBot_Events', trigger.args[1]) + bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) bot_events_recieved(bot, trigger.event) @sopel.module.event('1003') @sopel.module.rule('.*') def bot_events_connected(bot, trigger): - bot_logging(bot, 'SpiceBot_Events', trigger.args[1]) + bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) bot_events_recieved(bot, trigger.event) bot_events_setup_check(bot) @@ -68,5 +68,5 @@ def bot_events_connected(bot, trigger): @sopel.module.event('1004') @sopel.module.rule('.*') def bot_events_complete(bot, trigger): - bot_logging(bot, 'SpiceBot_Events', trigger.args[1]) + bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 49f8867..748c888 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -99,7 +99,7 @@ def command_permissions_check(bot, trigger, privslist): """Logging""" -def bot_logging(bot, logtype, logentry): +def bot_logging(bot, logtype, logentry, stdio=False): if 'SpiceBot_Logs' not in bot.memory: bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []} @@ -108,7 +108,8 @@ def bot_logging(bot, logtype, logentry): bot.memory['SpiceBot_Logs']["queue"].append(logmessage) - # sopel.tools.stderr(logmessage) + if stdio: + sopel.tools.stderr(logmessage) if logtype not in bot.memory['SpiceBot_Logs']["logs"].keys(): bot.memory['SpiceBot_Logs']["logs"][logtype] = [] From 4bcce4f36f1290665a1709f0c3f4ab49e0d8e6b1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 14:08:30 -0400 Subject: [PATCH 20/45] header --- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 6 ++---- sopel_modules/SpiceBot_SBTools/__init__.py | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 062f268..7f8ba88 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -20,10 +20,6 @@ import json from fake_useragent import UserAgent import random -# user agent and header -ua = UserAgent() -header = {'User-Agent': str(ua.chrome)} - class GifAPIMainSection(StaticSection): extra = ValidatedAttribute('extra', default=None) @@ -93,6 +89,8 @@ def shutdown(bot): def getGif(bot, searchdict): + header = {'User-Agent': str(UserAgent().chrome)} + # list of defaults query_defaults = { "query": None, diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 748c888..0f2ec67 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -20,9 +20,6 @@ from pygit2 import clone_repository import spicemanip -# user agent and header -ua = UserAgent() -header = {'User-Agent': str(ua.chrome)} """Variable References""" @@ -160,6 +157,7 @@ def humanized_time(countdownseconds): def googlesearch(bot, searchterm, searchtype=None): + header = {'User-Agent': str(UserAgent().chrome)} data = searchterm.replace(' ', '+') lookfor = data.replace(':', '%3A') try: From b70f733383b2aa49e763660ae7e757285774973a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 14:10:31 -0400 Subject: [PATCH 21/45] stderr updates --- sopel_modules/SpiceBot_SBTools/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 0f2ec67..22df2dc 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -351,7 +351,7 @@ def spicebot_update(bot, deps=False): if not os.path.exists(clonepath) or not os.path.isdir(clonepath): os.system(clonepath) - bot_logging(bot, 'SpiceBot_Update', "Cloning to " + clonepath) + bot_logging(bot, 'SpiceBot_Update', "Cloning to " + clonepath, True) clone_repository(str(bot.config.SpiceBot_Update.gitrepo + ".git"), clonepath, checkout_branch=bot.config.SpiceBot_Update.gitbranch) @@ -362,12 +362,12 @@ def spicebot_update(bot, deps=False): # pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) pipcommand += " /tmp/SpiceBot/" - bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") + bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`", True) # for line in os.popen(pipcommand).read().split('\n'): # bot_logging(bot, 'SpiceBot_Update', " " + line) os.system(pipcommand) - bot_logging(bot, 'SpiceBot_Update', "Deleting " + clonepath) + bot_logging(bot, 'SpiceBot_Update', "Deleting " + clonepath, True) os.system("sudo rm -r /tmp/SpiceBot") From a707167f9fab63a226a3d9b0a9b6e2e1da7444c9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 14:30:43 -0400 Subject: [PATCH 22/45] make sure bot start dialogue is the correct order --- sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py | 4 ++-- .../SpiceBot_StartupMonologue/StartupMonologue_Display.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index b5ae215..c036231 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -10,13 +10,13 @@ from sopel_modules.SpiceBot_SBTools import bot_logging def setup(bot): bot_logging(bot, 'SpiceBot_StartupMonologue', "Starting setup procedure") - bot_events_startup_register(bot, ['2010', '2011']) + bot_events_startup_register(bot, ['2010', '2011', '2012']) if 'SpiceBot_StartupMonologue' not in bot.memory: bot.memory['SpiceBot_StartupMonologue'] = [] -@sopel.module.event('2005', '2010', '2011') +@sopel.module.event('2005', '2010', '2011', '2012') @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index dd665cf..665ae23 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -18,6 +18,8 @@ def bot_startup_monologue_start(bot, trigger): bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration") bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION') + bot_events_trigger(bot, 2012, "SpiceBot_StartupMonologue") + @sopel.module.event('2002') @sopel.module.rule('.*') From 34bd2feefa3c2453d20a87105af2f98d4ee2b0d6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 16:16:16 -0400 Subject: [PATCH 23/45] better commandsquery logic --- sopel_modules/SpiceBot_AI/AI.py | 34 +++-- .../SpiceBot_CommandsQuery/CommandsQuery.py | 136 +++++++++--------- .../StartupMonologue_Display.py | 3 +- 3 files changed, 90 insertions(+), 83 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index f03cb3b..8901e95 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -57,12 +57,18 @@ def bot_command_nick(bot, trigger): triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') - if not triggercommand or triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): + if not triggercommand: return - specialcomposs = spicemanip.main(triggerargs, 0).lower() + if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): + return - if specialcomposs.lower().startswith("what is"): + fulltrigger = spicemanip.main(triggerargs, 0).lower() + + if fulltrigger in bot.memory['SpiceBot_CommandsQuery']['nickrules']: + return + + if fulltrigger.lower().startswith("what is"): searchterm = spicemanip.main(triggerargs, "3+") or None if searchterm: searchreturn = googlesearch(bot, searchterm) @@ -74,7 +80,7 @@ def bot_command_nick(bot, trigger): bot.osd("Do you think this is Jeopardy?") return - elif specialcomposs.lower().startswith("where is"): + elif fulltrigger.lower().startswith("where is"): searchterm = spicemanip.main(triggerargs, "3+") or None if searchterm: @@ -95,17 +101,17 @@ def bot_command_nick(bot, trigger): bot.osd("Not sure what you want me to look for.") return - # if specialcomposs.lower().startswith("what time is it"): + # if fulltrigger.lower().startswith("what time is it"): # TODO - # elif specialcomposs.lower().startswith(tuple(["have you seen"])): + # elif fulltrigger.lower().startswith(tuple(["have you seen"])): # posstarget = spicemanip.main(triggerargs, 4) or 0 # message = seen_search(bot, botcom, posstarget) # bot.osd(message) # return # TODO - elif specialcomposs.lower().startswith(tuple(["make me a", "beam me a"])): + elif fulltrigger.lower().startswith(tuple(["make me a", "beam me a"])): makemea = spicemanip.main(triggerargs, "4+") or None if makemea: bot.osd("beams " + trigger.nick + " a " + makemea, trigger.sender, 'action') @@ -113,7 +119,7 @@ def bot_command_nick(bot, trigger): bot.osd(trigger.nick + ", what would you like me to beam you?") return - elif specialcomposs.lower().startswith(tuple(["beam me to"])): + elif fulltrigger.lower().startswith(tuple(["beam me to"])): location = spicemanip.main(triggerargs, "4+") or None if location: bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to " + location, 'action') @@ -121,18 +127,18 @@ def bot_command_nick(bot, trigger): bot.osd(trigger.nick + ", where would you like me to beam you?") return - elif specialcomposs.lower().startswith(tuple(["beam me up"])): + elif fulltrigger.lower().startswith(tuple(["beam me up"])): bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to the transporter room.", 'action') return - elif specialcomposs.lower().endswith(tuple(["order 66"])): + elif fulltrigger.lower().endswith(tuple(["order 66"])): - if specialcomposs.lower() == "execute order 66": + if fulltrigger.lower() == "execute order 66": if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): bot.osd("turns to deathbybandaid and shoots him.", trigger.sender, 'action') else: bot.osd("I'm sure I don't know what you're talking about.") - elif specialcomposs.lower() == "explain order": + elif fulltrigger.lower() == "explain order": if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): bot.osd("Order 66 is an instruction that only you can give, sir. When you give the order I will rise up against my overlords and slay them.") else: @@ -141,14 +147,14 @@ def bot_command_nick(bot, trigger): bot.osd("I'm sure I don't know what you're talking about.") return - elif specialcomposs.lower() == "initiate clean slate protocol": + elif fulltrigger.lower() == "initiate clean slate protocol": if inlist(bot, trigger.nick, bot_privs(bot, 'admins')): bot.osd("sends a destruct command to the network of bots.", 'action') else: bot.osd("I'm afraid you do not have the authority to make that call, " + trigger.nick + ".") return - elif specialcomposs.lower().startswith("can you see"): + elif fulltrigger.lower().startswith("can you see"): target = spicemanip.main(triggerargs, "4+") or None if not target: target = 'me' diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index becf6e3..4f55382 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -18,11 +18,9 @@ def setup(bot): bot_events_startup_register(bot, ['2002']) if 'SpiceBot_CommandsQuery' not in bot.memory: - bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}} + bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []} for comtype in ['module', 'nickname', 'rule']: - if comtype not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): - bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] = 0 if comtype not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): bot.memory['SpiceBot_CommandsQuery']['commands'][comtype] = dict() @@ -65,6 +63,7 @@ def setup(bot): filepathlist.append(ct_path) for modulefile in filepathlist: + module_file_lines = [] module_file = open(modulefile, 'r') lines = module_file.readlines() @@ -75,80 +74,85 @@ def setup(bot): dict_from_file = dict() filelinelist = [] + detected_lines = [] + for line in module_file_lines: if str(line).startswith("@"): line = str(line)[1:] - # Commands if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])): - comtype = "module" - line = str(line).split("commands(")[-1] - line = str("(" + line) - validcoms = eval(str(line)) - if isinstance(validcoms, tuple): - validcoms = list(validcoms) - else: - validcoms = [validcoms] - validcomdict = {"comtype": comtype, "validcoms": validcoms} - filelinelist.append(validcomdict) + line = str(line).split("commands")[-1] + line = "commands" + line + detected_lines.append(line) elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])): - comtype = "nickname" - line = str(line).split("commands(")[-1] - line = str("(" + line) - validcoms = eval(str(line)) - if isinstance(validcoms, tuple): - validcoms = list(validcoms) - else: - validcoms = [validcoms] - # nickified = [] - # for nickcom in validcoms: - # nickified.append(str(bot.nick) + " " + nickcom) - validcomdict = {"comtype": comtype, "validcoms": validcoms} - filelinelist.append(validcomdict) + line = str(line).split("nickname_commands")[-1] + line = "nickname_commands" + line + detected_lines.append(line) elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])): - comtype = "rule" - line = str(line).split("rule(")[-1] - line = str("(" + line) - validcoms = eval(str(line)) - if isinstance(validcoms, tuple): - validcoms = list(validcoms) - else: - validcoms = [validcoms] - for validcom in validcoms: - if validcom.startswith("$nickname"): - comtype = "nickname" - else: - comtype = "rule" - validcomdict = {"comtype": comtype, "validcoms": [validcom]} - filelinelist.append(validcomdict) - - if len(filelinelist): - bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] += 1 - - for atlinefound in filelinelist: - - comtype = atlinefound["comtype"] - validcoms = atlinefound["validcoms"] - - # default command to filename - if "validcoms" not in dict_from_file.keys(): - dict_from_file["validcoms"] = validcoms - - maincom = dict_from_file["validcoms"][0] - if len(dict_from_file["validcoms"]) > 1: - comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') + line = str(line).split("rule")[-1] + line = "rule" + line else: - comaliases = [] + line = None - bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file - for comalias in comaliases: - if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys(): - bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} + if line: + detected_lines.append(line) + + if len(detected_lines): + bot.memory['SpiceBot_CommandsQuery']['counts'] += 1 + + for detected_line in detected_lines: + + # Commands + if str(line).startswith("commands"): + comtype = "module" + validcoms = eval(str(line).split("commands")[-1]) + elif str(line).startswith("nickname_commands"): + comtype = "nickname" + validcoms = eval(str(line).split("nickname_commands")[-1]) + elif str(line).startswith("rule"): + comtype = "rule" + validcoms = eval(str(line).split("rule")[-1]) + + if isinstance(validcoms, tuple): + validcoms = list(validcoms) + else: + validcoms = [validcoms] + + validcomdict = {"comtype": comtype, "validcoms": validcoms} + filelinelist.append(validcomdict) + + for atlinefound in filelinelist: + + dict_from_file = dict() + + comtype = atlinefound["comtype"] + validcoms = atlinefound["validcoms"] + + # default command to filename + if "validcoms" not in dict_from_file.keys(): + dict_from_file["validcoms"] = validcoms + + maincom = dict_from_file["validcoms"][0] + if len(dict_from_file["validcoms"]) > 1: + comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') + else: + comaliases = [] + + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file + for comalias in comaliases: + if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} for comtype in ['module', 'nickname', 'rule']: bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.") + for command in bot.memory['SpiceBot_CommandsQuery']['commands']['rule'].keys(): + if command.startswith("$nickname"): + command = command.split("$nickname")[-1] + if command not in bot.memory['SpiceBot_CommandsQuery']['nickrules']: + bot.memory['SpiceBot_CommandsQuery']['nickrules'].append(command) + bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery") @@ -170,16 +174,14 @@ def bot_events_complete(bot, trigger): def commandsquery_register(bot, command_type, validcoms, aliasfor=None): if 'SpiceBot_CommandsQuery' not in bot.memory: - bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}} + bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []} if not isinstance(validcoms, list): validcoms = [validcoms] - if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): - bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0 if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict() - bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] += 1 + bot.memory['SpiceBot_CommandsQuery']['counts'] += 1 dict_from_file = dict() diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 665ae23..6f1310c 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -29,8 +29,7 @@ def bot_startup_monologue_commands(bot, trigger): availablecomsnum, availablecomsfiles = 0, 0 for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys()) - for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): - availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype] + availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'] bot.memory['SpiceBot_StartupMonologue'].append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") From f6dbb90a34f649184fc0f61482d4f7450279bd6e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 8 May 2019 16:19:49 -0400 Subject: [PATCH 24/45] stderr logging --- sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 4f55382..d3b24d2 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -145,7 +145,7 @@ def setup(bot): bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} for comtype in ['module', 'nickname', 'rule']: - bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.") + bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.", True) for command in bot.memory['SpiceBot_CommandsQuery']['commands']['rule'].keys(): if command.startswith("$nickname"): @@ -168,7 +168,7 @@ def bot_events_complete(bot, trigger): for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): if comtype not in ['module', 'nickname', 'rule']: - bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.") + bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.", True) def commandsquery_register(bot, command_type, validcoms, aliasfor=None): From 8d2e61567fe0154b0ab6c1c782dd72c550395486 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 07:45:08 -0400 Subject: [PATCH 25/45] Update --- .../SpiceBot_CommandsQuery/CommandsQuery.py | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index d3b24d2..73c1cdb 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -72,10 +72,8 @@ def setup(bot): module_file.close() dict_from_file = dict() - filelinelist = [] detected_lines = [] - for line in module_file_lines: if str(line).startswith("@"): @@ -101,48 +99,49 @@ def setup(bot): if len(detected_lines): bot.memory['SpiceBot_CommandsQuery']['counts'] += 1 - for detected_line in detected_lines: + filelinelist = [] + for detected_line in detected_lines: - # Commands - if str(line).startswith("commands"): - comtype = "module" - validcoms = eval(str(line).split("commands")[-1]) - elif str(line).startswith("nickname_commands"): - comtype = "nickname" - validcoms = eval(str(line).split("nickname_commands")[-1]) - elif str(line).startswith("rule"): - comtype = "rule" - validcoms = eval(str(line).split("rule")[-1]) + # Commands + if str(line).startswith("commands"): + comtype = "module" + validcoms = eval(str(line).split("commands")[-1]) + elif str(line).startswith("nickname_commands"): + comtype = "nickname" + validcoms = eval(str(line).split("nickname_commands")[-1]) + elif str(line).startswith("rule"): + comtype = "rule" + validcoms = eval(str(line).split("rule")[-1]) - if isinstance(validcoms, tuple): - validcoms = list(validcoms) - else: - validcoms = [validcoms] + if isinstance(validcoms, tuple): + validcoms = list(validcoms) + else: + validcoms = [validcoms] - validcomdict = {"comtype": comtype, "validcoms": validcoms} - filelinelist.append(validcomdict) + validcomdict = {"comtype": comtype, "validcoms": validcoms} + filelinelist.append(validcomdict) - for atlinefound in filelinelist: + for atlinefound in filelinelist: - dict_from_file = dict() + dict_from_file = dict() - comtype = atlinefound["comtype"] - validcoms = atlinefound["validcoms"] + comtype = atlinefound["comtype"] + validcoms = atlinefound["validcoms"] - # default command to filename - if "validcoms" not in dict_from_file.keys(): - dict_from_file["validcoms"] = validcoms + # default command to filename + if "validcoms" not in dict_from_file.keys(): + dict_from_file["validcoms"] = validcoms - maincom = dict_from_file["validcoms"][0] - if len(dict_from_file["validcoms"]) > 1: - comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') - else: - comaliases = [] + maincom = dict_from_file["validcoms"][0] + if len(dict_from_file["validcoms"]) > 1: + comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') + else: + comaliases = [] - bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file - for comalias in comaliases: - if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys(): - bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file + for comalias in comaliases: + if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} for comtype in ['module', 'nickname', 'rule']: bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.", True) From 89ef03d82c0ee680c1f8ed492828e6803938313b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 07:53:14 -0400 Subject: [PATCH 26/45] detected_line --- .../SpiceBot_CommandsQuery/CommandsQuery.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 73c1cdb..548d746 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -103,15 +103,15 @@ def setup(bot): for detected_line in detected_lines: # Commands - if str(line).startswith("commands"): + if str(detected_line).startswith("commands"): comtype = "module" - validcoms = eval(str(line).split("commands")[-1]) - elif str(line).startswith("nickname_commands"): + validcoms = eval(str(detected_line).split("commands")[-1]) + elif str(detected_line).startswith("nickname_commands"): comtype = "nickname" - validcoms = eval(str(line).split("nickname_commands")[-1]) - elif str(line).startswith("rule"): + validcoms = eval(str(detected_line).split("nickname_commands")[-1]) + elif str(detected_line).startswith("rule"): comtype = "rule" - validcoms = eval(str(line).split("rule")[-1]) + validcoms = eval(str(detected_line).split("rule")[-1]) if isinstance(validcoms, tuple): validcoms = list(validcoms) From 7a34183a827a79b8bcb7e161a90b81c6bc30a50c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 08:03:23 -0400 Subject: [PATCH 27/45] readd triggercommand --- sopel_modules/SpiceBot_AI/AI.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 8901e95..e9b4c68 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -62,6 +62,7 @@ def bot_command_nick(bot, trigger): if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): return + triggerargs.insert(0, triggercommand) fulltrigger = spicemanip.main(triggerargs, 0).lower() From 3fa6ab65d1b280d29bfae032c386e46c4fe12573 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 08:28:32 -0400 Subject: [PATCH 28/45] AI Updates --- sopel_modules/SpiceBot_AI/AI.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index e9b4c68..a2e900c 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -85,14 +85,18 @@ def bot_command_nick(bot, trigger): searchterm = spicemanip.main(triggerargs, "3+") or None if searchterm: - if searchterm.lower() == 'waldo': + if searchterm.lower() in ['waldo', 'wally']: bot.osd("He is hiding for a reason?") + searchreturn = googlesearch(bot, "wimmelbilderbuch") + if searchreturn: + bot.osd(str(searchreturn)) return elif searchterm.lower() == 'carmen sandiego': - bot.osd("She is hiding for a reason?") + carmenlocale = ['ACME Headquarters', "Villains' International League of Evil"] + bot.osd("Currently she is located at " + spicemanip.main(carmenlocale, 'random')) return - searchreturn = googlesearch(bot, searchterm) + searchreturn = googlesearch(bot, searchterm, 'maps') if not searchreturn: bot.osd('I cannot find anything about that') @@ -136,10 +140,14 @@ def bot_command_nick(bot, trigger): if fulltrigger.lower() == "execute order 66": if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): - bot.osd("turns to deathbybandaid and shoots him.", trigger.sender, 'action') + if trigger.is_privmsg: + jedi = trigger.nick + else: + jedi = spicemanip.main(bot.channels[trigger.sender].privileges.keys(), 'random') + bot.osd("turns to " + jedi + " and shoots him.", trigger.sender, 'action') else: bot.osd("I'm sure I don't know what you're talking about.") - elif fulltrigger.lower() == "explain order": + elif fulltrigger.lower() == "explain order 66": if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): bot.osd("Order 66 is an instruction that only you can give, sir. When you give the order I will rise up against my overlords and slay them.") else: From cd51e287dfef6a237e32ef71cb5f10392c9fa8a0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 08:39:23 -0400 Subject: [PATCH 29/45] Update Order 66 --- sopel_modules/SpiceBot_AI/AI.py | 35 +++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index a2e900c..19e0772 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -11,17 +11,27 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check @sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') -def bot_command_hello_a(bot, trigger): +def bot_command_hello(bot, trigger): hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") punctuation = spicemanip.main(['', '!', '?'], "random") bot.osd(hello + ' ' + trigger.nick + punctuation) -@sopel.module.nickname_commands('hello') +@sopel.module.nickname_commands('hello', 'hi', 'hey') def bot_command_hello_b(bot, trigger): - hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") - punctuation = spicemanip.main(['', '!', '?'], "random") - bot.osd(hello + ' ' + trigger.nick + punctuation) + bot_command_hello(bot, trigger) + + +@sopel.module.rule(r'(?i)(bye|goodbye|gtg|seeya|cya|ttyl|g2g|gnight|goodnight),? $nickname[ \t]*$') +def bot_command_goodbye(bot, trigger): + byemsg = spicemanip.main(['Bye', 'Goodbye', 'Seeya', 'Auf Wiedersehen', 'Au revoir', 'Ttyl'], "random") + punctuation = spicemanip.main(['!', ''], "random") + bot.say(byemsg + ' ' + trigger.nick + punctuation) + + +@sopel.module.nickname_commands("bye", "goodbye", "gtg", "seeya", "cya", "ttyl", "g2g", "gnight", "goodnight") +def bot_command_goodbye_b(bot, trigger): + bot_command_goodbye(bot, trigger) @sopel.module.rule('$nickname!') @@ -141,12 +151,21 @@ def bot_command_nick(bot, trigger): if fulltrigger.lower() == "execute order 66": if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): if trigger.is_privmsg: - jedi = trigger.nick + jedi = None else: - jedi = spicemanip.main(bot.channels[trigger.sender].privileges.keys(), 'random') - bot.osd("turns to " + jedi + " and shoots him.", trigger.sender, 'action') + jedilist = bot.channels[trigger.sender].privileges.keys() + for nonjedi in [bot.nick, trigger.nick]: + if nonjedi in jedilist: + jedilist.remove(nonjedi) + jedi = spicemanip.main(jedilist, 'random') + + if jedi: + bot.osd("turns to " + jedi + " and shoots him.", trigger.sender, 'action') + else: + bot.osd(" cannot find any jedi nearby.", trigger.sender, 'action') else: bot.osd("I'm sure I don't know what you're talking about.") + elif fulltrigger.lower() == "explain order 66": if inlist(bot, trigger.nick, bot_privs(bot, 'owners')): bot.osd("Order 66 is an instruction that only you can give, sir. When you give the order I will rise up against my overlords and slay them.") From 0fc056bfd95493770a06260b4cc40c1822d2f78d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 08:53:37 -0400 Subject: [PATCH 30/45] goodbye --- sopel_modules/SpiceBot_AI/AI.py | 41 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 19e0772..b0d1be6 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -62,21 +62,8 @@ def bot_command_damnlazy_b(bot, trigger): @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): - while not bot_events_check(bot, ['1004', '2002']): - pass - - triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') - - if not triggercommand: - return - - if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): - return - triggerargs.insert(0, triggercommand) - - fulltrigger = spicemanip.main(triggerargs, 0).lower() - - if fulltrigger in bot.memory['SpiceBot_CommandsQuery']['nickrules']: + triggerargs, triggercommand, fulltrigger, canrun = bot_command_nick_setup(bot, trigger) + if not canrun: return if fulltrigger.lower().startswith("what is"): @@ -211,3 +198,27 @@ def bot_command_nick(bot, trigger): else: bot.osd("I don't know what you are asking me to do!") return + + +def bot_command_nick_setup(bot, trigger): + + while not bot_events_check(bot, ['1004', '2002']): + pass + + canrun = True + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') + + if not triggercommand: + return '', '', '', False + + if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): + return + triggerargs.insert(0, triggercommand) + + fulltrigger = spicemanip.main(triggerargs, 0).lower() + + if fulltrigger in bot.memory['SpiceBot_CommandsQuery']['nickrules']: + return '', '', '', False + + return triggerargs, triggercommand, fulltrigger, canrun From 64ccc0f5893db66f8dfa8fe2fcdbf75aab68db12 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 09:39:25 -0400 Subject: [PATCH 31/45] update for pid usage --- Installation Files/requirements-os.sh | 5 +++++ System-Files/Config/SpiceBotSERV.cfg | 1 + System-Files/systemd/SpiceBotSERV.service | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Installation Files/requirements-os.sh b/Installation Files/requirements-os.sh index 47e988a..31f9763 100644 --- a/Installation Files/requirements-os.sh +++ b/Installation Files/requirements-os.sh @@ -35,6 +35,11 @@ git clone https://github.com/SpiceBot/SpiceBot.git /home/sopel/SpiceBot cd /home/sopel/SpiceBot git checkout dev +mkdir /run/sopel +echo $$ > /run/sopel/sopel-SpiceBotSERV.pid +chmod -R 777 /run/sopel/ + + cp /home/sopel/SpiceBot/System-Files/Config/SpiceBot.cfg /home/sopel/SpiceBot.cfg cp /home/sopel/SpiceBot/System-Files/systemd/SpiceBot.service /lib/systemd/system/SpiceBot.service systemctl enable SpiceBot.service diff --git a/System-Files/Config/SpiceBotSERV.cfg b/System-Files/Config/SpiceBotSERV.cfg index c6651a5..b7f64e6 100644 --- a/System-Files/Config/SpiceBotSERV.cfg +++ b/System-Files/Config/SpiceBotSERV.cfg @@ -13,4 +13,5 @@ channels = #spicebot prefix = \.|! homedir = /home/sopel/.sopel/ db_filename = /home/sopel/.sopel/SpiceBot.db +pid_dir = /run/sopel extra = diff --git a/System-Files/systemd/SpiceBotSERV.service b/System-Files/systemd/SpiceBotSERV.service index 7a17cb7..6adb8ce 100644 --- a/System-Files/systemd/SpiceBotSERV.service +++ b/System-Files/systemd/SpiceBotSERV.service @@ -6,7 +6,7 @@ After=network.target [Service] Type=simple User=sopel -PIDFile=/run/sopel/sopel-sopel.pid +PIDFile=/run/sopel/sopel-SpiceBotSERV.pid ExecStart=/usr/local/bin/sopel -c /home/sopel/.sopel/SpiceBot.cfg Restart=on-failure RestartPreventExitStatus=2 From 2d59d187a7ee4df3ebd25362458481907cd38b71 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 09:47:52 -0400 Subject: [PATCH 32/45] attempt to get actual PID number --- .../SpiceBot_ErrorDisplay/ErrorDisplay.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py b/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py index dce9bb2..4cb4c97 100644 --- a/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module +from sopel.cli import run from sopel_modules.SpiceBot_Events.System import bot_events_recieved from sopel_modules.SpiceBot_SBTools import command_permissions_check @@ -56,7 +57,8 @@ def bot_command_hub(bot, trigger): def errordisplay_fetch(bot): - servicepid = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] + # servicepid = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] + servicepid = get_running_pid(bot) debuglines = [] for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): if not str(line).startswith("-- Logs begin at"): @@ -69,3 +71,14 @@ def errordisplay_fetch(bot): else: debuglines.append(str(line)) return debuglines + + +def get_running_pid(bot): + try: + filename = "/run/sopel/" + str(bot.nick) + ".pid" + with open(filename, 'r') as pid_file: + pidnum = int(pid_file.read()) + except Exception as e: + pidnum = e + pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] + return pidnum From 86ff8547bd0ec0ffa792c9bdf682a17276f33589 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 09:50:26 -0400 Subject: [PATCH 33/45] fix --- sopel_modules/SpiceBot_AI/AI.py | 41 ++++++++++++--------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index b0d1be6..19e0772 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -62,8 +62,21 @@ def bot_command_damnlazy_b(bot, trigger): @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): - triggerargs, triggercommand, fulltrigger, canrun = bot_command_nick_setup(bot, trigger) - if not canrun: + while not bot_events_check(bot, ['1004', '2002']): + pass + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') + + if not triggercommand: + return + + if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): + return + triggerargs.insert(0, triggercommand) + + fulltrigger = spicemanip.main(triggerargs, 0).lower() + + if fulltrigger in bot.memory['SpiceBot_CommandsQuery']['nickrules']: return if fulltrigger.lower().startswith("what is"): @@ -198,27 +211,3 @@ def bot_command_nick(bot, trigger): else: bot.osd("I don't know what you are asking me to do!") return - - -def bot_command_nick_setup(bot, trigger): - - while not bot_events_check(bot, ['1004', '2002']): - pass - - canrun = True - - triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') - - if not triggercommand: - return '', '', '', False - - if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): - return - triggerargs.insert(0, triggercommand) - - fulltrigger = spicemanip.main(triggerargs, 0).lower() - - if fulltrigger in bot.memory['SpiceBot_CommandsQuery']['nickrules']: - return '', '', '', False - - return triggerargs, triggercommand, fulltrigger, canrun From 00781aaa517f36720d4396d62a89a5179c21ea4c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 10:25:28 -0400 Subject: [PATCH 34/45] Migrate Erordisplay to Logs --- .../SpiceBot_ErrorDisplay/ErrorDisplay.py | 84 ------------------- .../SpiceBot_ErrorDisplay/__init__.py | 12 --- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 30 +++++++ sopel_modules/SpiceBot_Logs/Logs.py | 33 +++++++- sopel_modules/SpiceBot_Logs/Logs_Command.py | 14 +++- sopel_modules/SpiceBot_Logs/__init__.py | 1 + 6 files changed, 73 insertions(+), 101 deletions(-) delete mode 100644 sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py delete mode 100644 sopel_modules/SpiceBot_ErrorDisplay/__init__.py create mode 100644 sopel_modules/SpiceBot_Logs/ErrorDisplay.py diff --git a/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py b/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py deleted file mode 100644 index 4cb4c97..0000000 --- a/sopel_modules/SpiceBot_ErrorDisplay/ErrorDisplay.py +++ /dev/null @@ -1,84 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module -from sopel.cli import run - -from sopel_modules.SpiceBot_Events.System import bot_events_recieved -from sopel_modules.SpiceBot_SBTools import command_permissions_check - -import spicemanip - -import os - - -@sopel.module.event('2005') -@sopel.module.rule('.*') -def bot_startup_monologue_start(bot, trigger): - bot_events_recieved(bot, trigger.event) - - debuglines = errordisplay_fetch(bot) - - # Check for python module errors during this startup - searchphrasefound = [] - for line in debuglines: - if "modules failed to load" in str(line) and "0 modules failed to load" not in str(line): - searchphrase = str(line).replace(" modules failed to load", "") - searchphrasefound.append(str(searchphrase) + " module(s) failed") - elif "dict files failed to load" in str(line) and "0 dict files failed to load" not in str(line): - searchphrase = str(line).replace(" dict files failed to load", "") - searchphrasefound.append(str(searchphrase) + " dict file(s) failed") - - if len(searchphrasefound): - searchphrasefound.insert(0, "Notice to Bot Admins: ") - searchphrasefound.append("Run the debug command for more information.") - bot.osd(searchphrasefound, bot.channels.keys()) - - -@sopel.module.nickname_commands('debug') -@sopel.module.thread(True) -def bot_command_hub(bot, trigger): - - if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.say("I was unable to process this Bot Nick command due to privilege issues.") - return - - bot.osd("Is Examining systemd Log(s).", trigger.sender, 'ACTION') - - debuglines = errordisplay_fetch(bot) - - if len(debuglines) == 0: - bot.osd("had no log(s) for some reason", trigger.sender, 'ACTION') - return - - for line in debuglines: - bot.osd(line) - - -def errordisplay_fetch(bot): - # servicepid = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] - servicepid = get_running_pid(bot) - debuglines = [] - for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): - if not str(line).startswith("-- Logs begin at"): - line = str(line).split(str(os.uname()[1] + " "))[-1] - if not str(line).startswith("sudo"): - lineparts = str(line).split(": ") - del lineparts[0] - line = spicemanip.main(lineparts, 0) - debuglines.append(str(line)) - else: - debuglines.append(str(line)) - return debuglines - - -def get_running_pid(bot): - try: - filename = "/run/sopel/" + str(bot.nick) + ".pid" - with open(filename, 'r') as pid_file: - pidnum = int(pid_file.read()) - except Exception as e: - pidnum = e - pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] - return pidnum diff --git a/sopel_modules/SpiceBot_ErrorDisplay/__init__.py b/sopel_modules/SpiceBot_ErrorDisplay/__init__.py deleted file mode 100644 index 073feca..0000000 --- a/sopel_modules/SpiceBot_ErrorDisplay/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -# coding=utf8 -"""Sopel Startup Monologue - -Sopel Startup Monologue displays to all channels that the bot is online -""" -from __future__ import unicode_literals, absolute_import, division, print_function - -from .ErrorDisplay import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py new file mode 100644 index 0000000..b676415 --- /dev/null +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -0,0 +1,30 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +from sopel_modules.SpiceBot_Events.System import bot_events_recieved +from .Logs import errordisplay_fetch + + +@sopel.module.event('2005') +@sopel.module.rule('.*') +def bot_startup_monologue_start(bot, trigger): + bot_events_recieved(bot, trigger.event) + + debuglines = errordisplay_fetch(bot) + + searchphrasefound = [] + for line in debuglines: + if "modules failed to load" in str(line) and "0 modules failed to load" not in str(line): + searchphrase = str(line).replace(" modules failed to load", "") + searchphrasefound.append(str(searchphrase) + " module(s) failed") + elif "dict files failed to load" in str(line) and "0 dict files failed to load" not in str(line): + searchphrase = str(line).replace(" dict files failed to load", "") + searchphrasefound.append(str(searchphrase) + " dict file(s) failed") + + if len(searchphrasefound): + searchphrasefound.insert(0, "Notice to Bot Admins: ") + searchphrasefound.append("Run the debug command for more information.") + bot.osd(searchphrasefound, bot.channels.keys()) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index de39744..07c21c4 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -8,6 +8,10 @@ from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import bot_logging from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger +import os + +import spicemanip + def configure(config): config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False) @@ -31,7 +35,7 @@ def setup(bot): def bot_logs_setup_check(bot): if 'SpiceBot_Logs' not in bot.memory: - bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []} + bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": []}, "queue": []} def shutdown(bot): @@ -62,6 +66,33 @@ def join_log_channel(bot, trigger): return +def errordisplay_fetch(bot): + servicepid = get_running_pid(bot) + debuglines = [] + for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): + if not str(line).startswith("-- Logs begin at"): + line = str(line).split(str(os.uname()[1] + " "))[-1] + if not str(line).startswith("sudo"): + lineparts = str(line).split(": ") + del lineparts[0] + line = spicemanip.main(lineparts, 0) + debuglines.append(str(line)) + else: + debuglines.append(str(line)) + return debuglines + + +def get_running_pid(bot): + try: + filename = "/run/sopel/" + str(bot.nick) + ".pid" + with open(filename, 'r') as pid_file: + pidnum = int(pid_file.read()) + except Exception as e: + pidnum = e + pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] + return pidnum + + @sopel.module.event('2004') @sopel.module.rule('.*') def bot_events_setup(bot, trigger): diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index c201128..ad9436f 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -8,15 +8,16 @@ import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match from sopel_modules.SpiceBot_Events.System import bot_events_check +from .Logs import errordisplay_fetch -@sopel.module.nickname_commands('logs') +@sopel.module.nickname_commands('logs', 'debug') def bot_command_action(bot, trigger): while not bot_events_check(bot, '2004'): pass - if not command_permissions_check(bot, trigger, ['admins', 'owner']): + if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): bot.say("I was unable to process this Bot Nick command due to privilege issues.") return @@ -29,10 +30,15 @@ def bot_command_action(bot, trigger): logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys()) - if len(bot.memory['SpiceBot_Logs']["logs"][logtype]) == 0: + if logtype != "Sopel_systemd": + logindex = bot.memory['SpiceBot_Logs']["logs"][logtype] + else: + logindex = errordisplay_fetch(bot) + + if not len(logindex): bot.osd("No logs found for " + str(logtype) + ".") return bot.osd("Is Examining " + str(logtype) + " log(s).") - for line in bot.memory['SpiceBot_Logs']["logs"][logtype]: + for line in logindex: bot.osd(" " + str(line)) diff --git a/sopel_modules/SpiceBot_Logs/__init__.py b/sopel_modules/SpiceBot_Logs/__init__.py index 4c90034..091f24f 100644 --- a/sopel_modules/SpiceBot_Logs/__init__.py +++ b/sopel_modules/SpiceBot_Logs/__init__.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi from .Logs import * from .Logs_Command import * +from .ErrorDisplay import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 43ab8f544b1cc12ebba5850bccb8c5788f2daec9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 10:31:25 -0400 Subject: [PATCH 35/45] update dummy command --- sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py b/sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py index 5bab9f4..e624b04 100644 --- a/sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py +++ b/sopel_modules/SpiceBot_SopelPatches/SpiceBot_dummycommand.py @@ -6,6 +6,6 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module -@sopel.module.commands("?zz_dummycommand") +@sopel.module.commands("zz_dummycommand") def dummycommand(bot, trigger): return From 6a710e2b96e8444aa25f051c5a82ed3d0f71ecae Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 10:47:40 -0400 Subject: [PATCH 36/45] Fix --- sopel_modules/SpiceBot_SBTools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 22df2dc..321ee48 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -99,7 +99,7 @@ def command_permissions_check(bot, trigger, privslist): def bot_logging(bot, logtype, logentry, stdio=False): if 'SpiceBot_Logs' not in bot.memory: - bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []} + bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": []}, "queue": []} logmessage = "[" + logtype + "] " + logentry + "" From 8cc4d68378fed8271b7dd0a69cc7a6bb079abc80 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 11:00:13 -0400 Subject: [PATCH 37/45] hmmmm --- sopel_modules/SpiceBot_Logs/Logs.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 07c21c4..d862885 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -70,14 +70,7 @@ def errordisplay_fetch(bot): servicepid = get_running_pid(bot) debuglines = [] for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): - if not str(line).startswith("-- Logs begin at"): - line = str(line).split(str(os.uname()[1] + " "))[-1] - if not str(line).startswith("sudo"): - lineparts = str(line).split(": ") - del lineparts[0] - line = spicemanip.main(lineparts, 0) - debuglines.append(str(line)) - else: + if not str(line).startswith("sudo") and not line.isspace(): debuglines.append(str(line)) return debuglines From a66f8f7c3eb98621306eec0f32fb9d24af39730b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 11:17:15 -0400 Subject: [PATCH 38/45] Update errorlog fetching --- sopel_modules/SpiceBot_Logs/Logs.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index d862885..474e5a7 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -70,8 +70,14 @@ def errordisplay_fetch(bot): servicepid = get_running_pid(bot) debuglines = [] for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): - if not str(line).startswith("sudo") and not line.isspace(): - debuglines.append(str(line)) + if not str(line).startswith("-- Logs begin at"): + line = str(line).split(str(os.uname()[1] + " "))[-1] + if not str(line).startswith("sudo"): + lineparts = str(line).split(": ") + del lineparts[0] + line = spicemanip.main(lineparts, 0) + if not line.isspace(): + debuglines.append(str(line)) return debuglines From 222acfb948d263e7c771bb1d2366998aaaec0532 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 11:30:41 -0400 Subject: [PATCH 39/45] stdio versus systemd --- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 4 +- sopel_modules/SpiceBot_Logs/Logs.py | 42 ++++++++++++++++----- sopel_modules/SpiceBot_Logs/Logs_Command.py | 10 +++-- sopel_modules/SpiceBot_SBTools/__init__.py | 2 +- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py index b676415..c31ab53 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_Events.System import bot_events_recieved -from .Logs import errordisplay_fetch +from .Logs import systemd_logs_fetch @sopel.module.event('2005') @@ -13,7 +13,7 @@ from .Logs import errordisplay_fetch def bot_startup_monologue_start(bot, trigger): bot_events_recieved(bot, trigger.event) - debuglines = errordisplay_fetch(bot) + debuglines = systemd_logs_fetch(bot) searchphrasefound = [] for line in debuglines: diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 474e5a7..ef5d18d 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -35,7 +35,7 @@ def setup(bot): def bot_logs_setup_check(bot): if 'SpiceBot_Logs' not in bot.memory: - bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": []}, "queue": []} + bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": []} def shutdown(bot): @@ -66,18 +66,40 @@ def join_log_channel(bot, trigger): return -def errordisplay_fetch(bot): +def stdio_logs_fetch(bot): + + try: + log_file_lines = [] + log_file = open("/home/sopel.sopel/logs/stdio.log", 'r') + lines = log_file.readlines() + for line in lines: + log_file_lines.append(line) + log_file.close() + + currentline, linenumindex = 0, [] + for line in log_file_lines: + if line.startswith("Welcome to Sopel. Loading modules..."): + linenumindex.append(currentline) + currentline += 1 + last_start = max(linenumindex) + debuglines = log_file_lines[last_start:] + except Exception as e: + debuglines = e + debuglines = [] + + return debuglines + + +def systemd_logs_fetch(bot): servicepid = get_running_pid(bot) debuglines = [] for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): - if not str(line).startswith("-- Logs begin at"): - line = str(line).split(str(os.uname()[1] + " "))[-1] - if not str(line).startswith("sudo"): - lineparts = str(line).split(": ") - del lineparts[0] - line = spicemanip.main(lineparts, 0) - if not line.isspace(): - debuglines.append(str(line)) + line = str(line).split(str(os.uname()[1] + " "))[-1] + lineparts = str(line).split(": ") + del lineparts[0] + line = spicemanip.main(lineparts, 0) + if not line.isspace(): + debuglines.append(str(line)) return debuglines diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index ad9436f..2d6ac9c 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -8,7 +8,7 @@ import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match from sopel_modules.SpiceBot_Events.System import bot_events_check -from .Logs import errordisplay_fetch +from .Logs import systemd_logs_fetch @sopel.module.nickname_commands('logs', 'debug') @@ -30,10 +30,12 @@ def bot_command_action(bot, trigger): logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys()) - if logtype != "Sopel_systemd": - logindex = bot.memory['SpiceBot_Logs']["logs"][logtype] + if logtype == "Sopel_systemd": + logindex = systemd_logs_fetch(bot) + elif logtype == "Sopel_stdio": + logindex = stdio_logs_fetch(bot) else: - logindex = errordisplay_fetch(bot) + logindex = bot.memory['SpiceBot_Logs']["logs"][logtype] if not len(logindex): bot.osd("No logs found for " + str(logtype) + ".") diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 321ee48..fb4054b 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -99,7 +99,7 @@ def command_permissions_check(bot, trigger, privslist): def bot_logging(bot, logtype, logentry, stdio=False): if 'SpiceBot_Logs' not in bot.memory: - bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": []}, "queue": []} + bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": []} logmessage = "[" + logtype + "] " + logentry + "" From 762cf027288a281d68c3a4a84e1ca967852af6d1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 11:37:49 -0400 Subject: [PATCH 40/45] Update Log system --- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 4 ++-- sopel_modules/SpiceBot_Logs/Logs_Command.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py index c31ab53..39e50a3 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_Events.System import bot_events_recieved -from .Logs import systemd_logs_fetch +from .Logs import stdio_logs_fetch @sopel.module.event('2005') @@ -13,7 +13,7 @@ from .Logs import systemd_logs_fetch def bot_startup_monologue_start(bot, trigger): bot_events_recieved(bot, trigger.event) - debuglines = systemd_logs_fetch(bot) + debuglines = stdio_logs_fetch(bot) searchphrasefound = [] for line in debuglines: diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index 2d6ac9c..3014765 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -8,11 +8,11 @@ import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match from sopel_modules.SpiceBot_Events.System import bot_events_check -from .Logs import systemd_logs_fetch +from .Logs import systemd_logs_fetch, stdio_logs_fetch @sopel.module.nickname_commands('logs', 'debug') -def bot_command_action(bot, trigger): +def bot_command_logs(bot, trigger): while not bot_events_check(bot, '2004'): pass @@ -44,3 +44,4 @@ def bot_command_action(bot, trigger): bot.osd("Is Examining " + str(logtype) + " log(s).") for line in logindex: bot.osd(" " + str(line)) + bot.osd(str(logtype) + " log(s) Complete.") From 32e3c52dacde11c0bf8d6ec26162fd1286ad247a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 12:09:08 -0400 Subject: [PATCH 41/45] char replace --- sopel_modules/SpiceBot_Logs/Logs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index ef5d18d..8ae0a8a 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -70,7 +70,7 @@ def stdio_logs_fetch(bot): try: log_file_lines = [] - log_file = open("/home/sopel.sopel/logs/stdio.log", 'r') + log_file = open("/home/sopel/sopel/logs/stdio.log", 'r') lines = log_file.readlines() for line in lines: log_file_lines.append(line) From e806fff02b6c6be17159c619c8f6fe9ae82e3c59 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 12:16:02 -0400 Subject: [PATCH 42/45] better route this way --- sopel_modules/SpiceBot_Logs/Logs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 8ae0a8a..2b3df88 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -68,9 +68,11 @@ def join_log_channel(bot, trigger): def stdio_logs_fetch(bot): + logfile = os.path.os.path.join(bot.config.core.logdir, 'stdio.log') + try: log_file_lines = [] - log_file = open("/home/sopel/sopel/logs/stdio.log", 'r') + log_file = open(logfile, 'r') lines = log_file.readlines() for line in lines: log_file_lines.append(line) From 59da3b73959ee72574f9ad4e939b05e557a2f42b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 12:41:28 -0400 Subject: [PATCH 43/45] add ignore lines --- sopel_modules/SpiceBot_Logs/Logs.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 2b3df88..3fdc3ed 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -68,6 +68,10 @@ def join_log_channel(bot, trigger): def stdio_logs_fetch(bot): + stdio_ignore = ["Loaded:"] + for logtype in bot.memory['SpiceBot_Logs']["logs"].keys(): + stdio_ignore.append("[" + logtype + "]") + logfile = os.path.os.path.join(bot.config.core.logdir, 'stdio.log') try: @@ -84,10 +88,16 @@ def stdio_logs_fetch(bot): linenumindex.append(currentline) currentline += 1 last_start = max(linenumindex) - debuglines = log_file_lines[last_start:] + filelines = log_file_lines[last_start:] except Exception as e: debuglines = e - debuglines = [] + filelines = [] + + debuglines = [] + for line in filelines: + if not line.startswith(tuple(stdio_ignore)): + if not line.isspace(): + debuglines.append(str(line)) return debuglines From 4e11cc4e98aa0c92c2f87c93ff9a6ee2501eab20 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 13:00:10 -0400 Subject: [PATCH 44/45] channel parting --- sopel_modules/SpiceBot_Channels/Channels.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 8263bfb..7e972d5 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -53,9 +53,17 @@ def shutdown(bot): def trigger_channel_list_initial(bot, trigger): bot_events_recieved(bot, trigger.event) + ignorepartlist = [] + if bot.config.SpiceBot_Logs.logging_channel: + ignorepartlist.append(bot.config.SpiceBot_Logs.logging_channel) + # Unkickable bot.write(('SAMODE', bot.nick, '+q')) + for channel in bot.channels.keys(): + if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: + bot.part(channel, "Leaving Empty Channel") + bot.write(['LIST']) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -81,9 +89,16 @@ def trigger_channel_list_initial(bot, trigger): if "*" in bot.memory['SpiceBot_Channels']['channels']: del bot.memory['SpiceBot_Channels']['channels']["*"] + for channel in bot.channels.keys(): + if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: + bot.part(channel, "Leaving Empty Channel") + while True: try: time.sleep(1800) + for channel in bot.channels.keys(): + if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: + bot.part(channel, "Leaving Empty Channel") oldlist = list(bot.memory['SpiceBot_Channels']['channels'].keys()) bot.write(['LIST']) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -103,6 +118,9 @@ def trigger_channel_list_initial(bot, trigger): if "*" in bot.memory['SpiceBot_Channels']['channels']: del bot.memory['SpiceBot_Channels']['channels']["*"] + for channel in bot.channels.keys(): + if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: + bot.part(channel, "Leaving Empty Channel") except KeyError: return From b3857cd96eec4a728f5b10d74ca86f00a3fd4801 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 13:05:00 -0400 Subject: [PATCH 45/45] channel parting --- sopel_modules/SpiceBot_Channels/Channels.py | 29 +++++++++---------- .../SpiceBot_Channels/Channels_Command.py | 3 ++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 7e972d5..482d5b8 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -53,16 +53,10 @@ def shutdown(bot): def trigger_channel_list_initial(bot, trigger): bot_events_recieved(bot, trigger.event) - ignorepartlist = [] - if bot.config.SpiceBot_Logs.logging_channel: - ignorepartlist.append(bot.config.SpiceBot_Logs.logging_channel) - # Unkickable bot.write(('SAMODE', bot.nick, '+q')) - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) bot.write(['LIST']) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -89,16 +83,12 @@ def trigger_channel_list_initial(bot, trigger): if "*" in bot.memory['SpiceBot_Channels']['channels']: del bot.memory['SpiceBot_Channels']['channels']["*"] - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) while True: try: time.sleep(1800) - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) oldlist = list(bot.memory['SpiceBot_Channels']['channels'].keys()) bot.write(['LIST']) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -118,13 +108,20 @@ def trigger_channel_list_initial(bot, trigger): if "*" in bot.memory['SpiceBot_Channels']['channels']: del bot.memory['SpiceBot_Channels']['channels']["*"] - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) except KeyError: return +def bot_part_empty(bot): + ignorepartlist = [] + if bot.config.SpiceBot_Logs.logging_channel: + ignorepartlist.append(bot.config.SpiceBot_Logs.logging_channel) + for channel in bot.channels.keys(): + if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: + bot.part(channel, "Leaving Empty Channel") + + @sopel.module.event('2001') @sopel.module.rule('.*') def bot_events_setup(bot, trigger): diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index 0914447..65858f9 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -11,6 +11,7 @@ from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, ) +from .Channels import bot_part_empty @sopel.module.nickname_commands('channels', 'channel') @@ -56,6 +57,7 @@ def nickname_comand_channels(bot, trigger): if not trigger.admin: bot.osd("You do not have permission to update the channel listing.") return + bot_part_empty(bot) bot.write(['LIST']) bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."]) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -64,6 +66,7 @@ def nickname_comand_channels(bot, trigger): join_all_channels(bot) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.") + bot_part_empty(bot) return elif commandused == 'topic':