From 6df41438e91a054846d4285ca55a31332daec861 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 11:10:25 -0400 Subject: [PATCH 01/33] test --- sopel_modules/SpiceBot_Core_Commands/Commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index 6863112..44a8443 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -12,7 +12,7 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) +# @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun.prerun('nickname') @sopel.module.nickname_commands('commands', 'command') def nickname_comand_channels(bot, trigger): From ef39f23f5dc28d17e846def456c1f63843d58ceb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 11:13:14 -0400 Subject: [PATCH 02/33] fix --- sopel_modules/SpiceBot_Core_Commands/Commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index 44a8443..c851908 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -12,10 +12,10 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -# @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) +@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun.prerun('nickname') @sopel.module.nickname_commands('commands', 'command') -def nickname_comand_channels(bot, trigger): +def nickname_comand_commands(bot, trigger): if not len(trigger.sb['args']): commandused = 'list' From 7d8744e9279132fd5b071fe2c42562daa42478e1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 11:15:30 -0400 Subject: [PATCH 03/33] migrate botprivs --- sopel_modules/SpiceBot_BotPrivs/__init__.py | 8 -------- .../BotPrivs.py | 0 sopel_modules/SpiceBot_Core_Commands/__init__.py | 1 + 3 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 sopel_modules/SpiceBot_BotPrivs/__init__.py rename sopel_modules/{SpiceBot_BotPrivs => SpiceBot_Core_Commands}/BotPrivs.py (100%) diff --git a/sopel_modules/SpiceBot_BotPrivs/__init__.py b/sopel_modules/SpiceBot_BotPrivs/__init__.py deleted file mode 100644 index d8f5712..0000000 --- a/sopel_modules/SpiceBot_BotPrivs/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -# coding=utf8 -from __future__ import unicode_literals, absolute_import, division, print_function - -from .BotPrivs import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py similarity index 100% rename from sopel_modules/SpiceBot_BotPrivs/BotPrivs.py rename to sopel_modules/SpiceBot_Core_Commands/BotPrivs.py diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index c66a8b5..e4a8f3c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -15,6 +15,7 @@ from .Logs import * from .Runtime_Controls import * from .Messaging import * from .Docs import * +from .BotPrivs import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 6980076a75f7c102ecd9993dc9406235284d3d36 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 11:16:41 -0400 Subject: [PATCH 04/33] keys --- sopel_modules/SpiceBot_Core_Commands/Commands.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index c851908..33d0b34 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -21,7 +21,6 @@ def nickname_comand_commands(bot, trigger): commandused = 'list' else: commandused = spicemanip.main(trigger.sb['args'], 1).lower() - bot.say(str(commandused)) commands_list = [] for commandstype in SpiceBot.commands.dict['commands'].keys(): @@ -38,9 +37,9 @@ def nickname_comand_commands(bot, trigger): return elif commandused == 'total': - bot.osd("I have " + str(len(commands_list)) + " commands available.") + bot.osd("I have " + str(len(commands_list.keys())) + " commands available.") return elif commandused == 'random': - bot.osd(["Here's a random command for you:", + spicemanip.main(commands_list, 'random')]) + bot.osd(["Here's a random command for you:", + spicemanip.main(commands_list.keys(), 'random')]) return From f2d4307bfcdf07f2cf351e2bad148ec9e7aaf4b8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 11:21:41 -0400 Subject: [PATCH 05/33] fix --- sopel_modules/SpiceBot_Core_Commands/Commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index 33d0b34..994888e 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -37,9 +37,9 @@ def nickname_comand_commands(bot, trigger): return elif commandused == 'total': - bot.osd("I have " + str(len(commands_list.keys())) + " commands available.") + bot.osd("I have " + str(len(commands_list)) + " commands available.") return elif commandused == 'random': - bot.osd(["Here's a random command for you:", + spicemanip.main(commands_list.keys(), 'random')]) + bot.osd(["Here's a random command for you:", spicemanip.main(commands_list, 'random')]) return From 94964aadc089a6033e8853c5d375fe5b42b4e626 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 13:10:15 -0400 Subject: [PATCH 06/33] test --- sopel_modules/SpiceBot/Users.py | 107 ++++++++++++++++++ sopel_modules/SpiceBot/__init__.py | 1 + sopel_modules/SpiceBot_AI/AI.py | 19 ---- sopel_modules/SpiceBot_AI/AI_aiml.py | 22 ++++ .../aiml/nickname_acknowledge.aiml | 20 ++++ .../aiml/nickname_canyousee.aiml | 16 +++ .../SpiceBot_Core_Commands/__init__.py | 1 + .../SpiceBot_Core_Processing/Users.py | 36 ++++++ 8 files changed, 203 insertions(+), 19 deletions(-) create mode 100644 sopel_modules/SpiceBot/Users.py create mode 100644 sopel_modules/SpiceBot_Configs/aiml/nickname_canyousee.aiml create mode 100644 sopel_modules/SpiceBot_Core_Processing/Users.py diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py new file mode 100644 index 0000000..3e1c08e --- /dev/null +++ b/sopel_modules/SpiceBot/Users.py @@ -0,0 +1,107 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +"""A way to track users""" + +from sopel.tools import Identifier + +from .Database import db as botdb +from .Tools import inlist, inlist_match + + +class BotUsers(): + + def __init__(self): + self.all = botdb.get_bot_value('users') or [] + self.online = [] + self.save_user_db() + + def whois(self, nick): + nick = Identifier(nick) + nick_id = botdb.db.get_nick_id(nick, create=True) + return nick_id + + def save_user_db(self): + botdb.set_bot_value('users', self.all) + + def join(self, bot, trigger): + # bot block + if trigger.nick == bot.nick: + return + # Identify + nick_id = self.whois(trigger.nick) + # mark online + self.mark_online(trigger.nick, nick_id) + + def quit(self, bot, trigger): + # bot block + if trigger.nick == bot.nick: + return + # Identify + nick_id = self.whois(trigger.nick) + # mark offline + self.mark_offline(trigger.nick, nick_id) + + def part(self, bot, trigger): + # bot block + if trigger.nick == bot.nick: + return + # Identify + nick_id = self.whois(trigger.nick) + # mark offline + if trigger.nick not in bot.users: + self.mark_offline(trigger.nick, nick_id) + + def kick(self, bot, trigger): + target = str(trigger.args[1]) + # bot block + if target == bot.nick: + return + # Identify + nick_id = self.whois(target) + # mark offline + if target not in bot.users: + self.mark_offline(target, nick_id) + + def add_to_all(self, nick, nick_id=None): + if not nick_id: + nick_id = self.whois(nick) + # add to all if not there + if nick_id not in self.all.keys(): + self.all[nick_id] = {"aliases": []} + # add nick alias + if nick not in self.all[nick_id]: + self.all[nick_id]["aliases"].append(nick) + + def mark_online(self, nick, nick_id=None): + if not nick_id: + nick_id = self.whois(nick) + self.add_to_all(nick, nick_id) + if nick_id not in self.online: + self.online.append(nick_id) + + def mark_offline(self, nick, nick_id=None): + if not nick_id: + nick_id = self.whois(nick) + self.add_to_all(nick, nick_id) + if nick_id in self.online: + self.online.remove(nick_id) + + def current(self, bot, reqchannel='all'): + user_list = [] + if reqchannel == 'all': + for channel in bot.channels.keys(): + for user in bot.channels[channel].privileges.keys(): + user_id = self.whois(user) + user_list.append(user_id) + return user_list + elif not inlist(reqchannel, bot.channels.keys()): + return user_list + else: + channel = inlist_match(reqchannel, bot.channels.keys()) + for user in bot.channels[channel].privileges.keys(): + user_id = self.whois(user) + user_list.append(user_id) + return user_list + + +users = BotUsers() diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index 18b52f7..239248b 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -20,6 +20,7 @@ from .Commands import * from .Events import * from .StartupMonologue import * from .Channels import * +from .Users import * from .AI import * diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index cf1b6c9..cd66c8c 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -87,22 +87,3 @@ def bot_command_nick(bot, trigger): else: bot.osd("I'm afraid you do not have the authority to make that call, " + trigger.nick + ".") return - - elif fulltrigger.lower().startswith("can you see"): - target = spicemanip.main(trigger.sb['args'], "4+") or None - if not target: - bot.osd(trigger.nick + ", I can see clearly.") - return - if target in [trigger.nick, 'me']: - bot.osd(trigger.nick + ", I can see you.") - else: - if SpiceBot.inlist(trigger.nick, bot.users): - bot.osd(trigger.nick + ", yes. I can see " + SpiceBot.inlist_match(target, bot.users) + " right now!") - else: - bot.osd(trigger.nick + ", no. I cannot see " + SpiceBot.inlist_match(target, bot.users) + " right now!") - # if bot_check_inlist(target, bot.memory["botdict"]["users"].keys()): - # bot.osd(trigger.nick + ", I can't see " + inlist_match(target, bot.users) + " at the moment.") - # else: - # bot.osd("I have never seen " + str(target) + ".") - # TODO - return diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 2c9948e..94cfc35 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -83,6 +83,28 @@ def bot_command_rule(bot, trigger): bot.osd(str(searchreturn)) return + elif trigger_args[0].lower() in ["can"] and trigger_args[1].lower() in ["you"] and trigger_args[2].lower() in ["see"]: + target = spicemanip.main(trigger_args, "4+") or None + if target: + if SpiceBot.inlist(trigger.nick, bot.users): + realtarget = SpiceBot.inlist_match(target, bot.users) + dispmsg = [trigger.nick + ", yes. I can see " + realtarget] + targetchannels = [] + for channel in bot.channels.keys(): + if SpiceBot.inlist(trigger.nick, bot.channels[channel].privileges.keys()): + targetchannels.append(channel) + dispmsg.append(realtarget + " is in " + spicemanip.main(targetchannels, 'andlist')) + bot.osd(dispmsg) + else: + bot.osd(trigger.nick + ", no. I cannot see " + target + " right now!") + # if bot_check_inlist(target, bot.memory["botdict"]["users"].keys()): + # bot.osd(trigger.nick + ", I can't see " + inlist_match(target, bot.users) + " at the moment.") + # else: + # bot.osd("I have never seen " + str(target) + ".") + # user in bot.channels[channel].privileges.keys() + # TODO + return + closestmatches = SpiceBot.similar_list(trigger_command, SpiceBot.commands.dict['commands']["nickname"].keys(), 3, 'reverse') if len(closestmatches): closestmatches = spicemanip.main(closestmatches, "andlist") diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_acknowledge.aiml b/sopel_modules/SpiceBot_Configs/aiml/nickname_acknowledge.aiml index 12f1a57..5dfc586 100644 --- a/sopel_modules/SpiceBot_Configs/aiml/nickname_acknowledge.aiml +++ b/sopel_modules/SpiceBot_Configs/aiml/nickname_acknowledge.aiml @@ -22,4 +22,24 @@ + + BOTNICK you there + + + + + you there BOTNICK + + + diff --git a/sopel_modules/SpiceBot_Configs/aiml/nickname_canyousee.aiml b/sopel_modules/SpiceBot_Configs/aiml/nickname_canyousee.aiml new file mode 100644 index 0000000..088609a --- /dev/null +++ b/sopel_modules/SpiceBot_Configs/aiml/nickname_canyousee.aiml @@ -0,0 +1,16 @@ + + + + + + BOTNICK can you see me + + + + + BOTNICK can you see + + + + + diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index e4a8f3c..2b6cee3 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -8,6 +8,7 @@ This module contains references only for other modules to utilize. from .CommandsQuery import * from .Commands import * +from .Users import * from .Channels import * from .Database import * from .Uptime import * diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py new file mode 100644 index 0000000..a1fbff1 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -0,0 +1,36 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Channels system. +""" +import sopel + +import sopel_modules.SpiceBot as SpiceBot + + +@sopel.module.event('JOIN') +@sopel.module.rule('.*') +def users_join(bot, trigger): + bot.say(str(trigger.args)) + # SpiceBot.users.join(bot, trigger) + + +@sopel.module.event('QUIT') +@sopel.module.rule('.*') +def users_quit(bot, trigger): + bot.say(str(trigger.args)) + # SpiceBot.users.quit(bot, trigger) + + +@sopel.module.event('PART') +@sopel.module.rule('.*') +def users_part(bot, trigger): + bot.say(str(trigger.args)) + # SpiceBot.users.part(bot, trigger) + + +@sopel.module.event('KICK') +@sopel.module.rule('.*') +def users_kick(bot, trigger): + bot.say(str(trigger.args)) + # SpiceBot.users.kick(bot, trigger) From 38a34e61d0367868e50a721735d8d94d94a43a5b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 13:13:39 -0400 Subject: [PATCH 07/33] test name --- sopel_modules/SpiceBot_Core_Commands/Docs.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Uptime.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/Docs.py b/sopel_modules/SpiceBot_Core_Commands/Docs.py index b17328f..8895123 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Docs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Docs.py @@ -8,7 +8,7 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.nickname_commands('help', 'docs', 'wiki') -def bot_command_owners(bot, trigger): +def bot_command_docs(bot, trigger): bot.osd(["IRC Modules Repository", str(SpiceBot.github_dict["url_main"] + SpiceBot.github_dict["repo_owner"] + "/" + diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index b8aa223..4bde934 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -10,6 +10,6 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.nickname_commands('uptime') -def bot_command_srewyou(bot, trigger): +def bot_command_uptime(bot, trigger): timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." bot.osd("I have been running since " + timesince) From 2c22227d38520e8e1e5a96b90c0431e58868ce6f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 13:15:24 -0400 Subject: [PATCH 08/33] wrong init --- sopel_modules/SpiceBot_Core_Commands/__init__.py | 1 - sopel_modules/SpiceBot_Core_Processing/__init__.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index 2b6cee3..e4a8f3c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -8,7 +8,6 @@ This module contains references only for other modules to utilize. from .CommandsQuery import * from .Commands import * -from .Users import * from .Channels import * from .Database import * from .Uptime import * diff --git a/sopel_modules/SpiceBot_Core_Processing/__init__.py b/sopel_modules/SpiceBot_Core_Processing/__init__.py index df953ff..06d806d 100644 --- a/sopel_modules/SpiceBot_Core_Processing/__init__.py +++ b/sopel_modules/SpiceBot_Core_Processing/__init__.py @@ -7,6 +7,7 @@ This module contains references only for other modules to utilize. """ from .Channels import * +from .Users import * from .Events import * from .Modules import * from .AI import * From ec8fe0ae4d9c7cc2fa74a6cb0c0f99ea31675ea7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 13:18:36 -0400 Subject: [PATCH 09/33] test --- sopel_modules/SpiceBot_Core_Processing/Users.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index a1fbff1..a90e2a7 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -11,6 +11,7 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.event('JOIN') @sopel.module.rule('.*') def users_join(bot, trigger): + bot.say(str(trigger)) bot.say(str(trigger.args)) # SpiceBot.users.join(bot, trigger) @@ -18,6 +19,7 @@ def users_join(bot, trigger): @sopel.module.event('QUIT') @sopel.module.rule('.*') def users_quit(bot, trigger): + bot.say(str(trigger)) bot.say(str(trigger.args)) # SpiceBot.users.quit(bot, trigger) @@ -25,6 +27,7 @@ def users_quit(bot, trigger): @sopel.module.event('PART') @sopel.module.rule('.*') def users_part(bot, trigger): + bot.say(str(trigger)) bot.say(str(trigger.args)) # SpiceBot.users.part(bot, trigger) @@ -32,5 +35,6 @@ def users_part(bot, trigger): @sopel.module.event('KICK') @sopel.module.rule('.*') def users_kick(bot, trigger): + bot.say(str(trigger)) bot.say(str(trigger.args)) # SpiceBot.users.kick(bot, trigger) From 498f592ef4e5618109991f18fdc89f8f584d2118 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 15:22:08 -0400 Subject: [PATCH 10/33] testing phase --- sopel_modules/SpiceBot/Database.py | 10 + sopel_modules/SpiceBot/Users.py | 177 +++++++++++++----- .../SpiceBot_Core_Processing/Users.py | 13 ++ 3 files changed, 148 insertions(+), 52 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 9c07eda..68283c1 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -525,6 +525,16 @@ class BotDatabase(): def get_nick_id(self, nick, create=True): return self.db.get_nick_id(nick, create) + def alias_nick(self, nick, alias): + return self.alias_nick(nick, alias) + + def check_nick_id(self, nick): + try: + self.db.get_nick_id(nick, create=False) + return True + except ValueError: + return False + def get_nick_value(self, nick, key, namespace='default'): return self.db.get_nick_value(nick, key, namespace) diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index 3e1c08e..058f632 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -5,15 +5,18 @@ from __future__ import unicode_literals, absolute_import, division, print_functi from sopel.tools import Identifier from .Database import db as botdb -from .Tools import inlist, inlist_match class BotUsers(): def __init__(self): - self.all = botdb.get_bot_value('users') or [] + # TODO timestamp for new .seen + self.all = botdb.get_bot_value('users') or dict() self.online = [] - self.save_user_db() + self.offline = [] + for user_id in self.all.keys(): + self.offline.append(user_id) + self.current = {} def whois(self, nick): nick = Identifier(nick) @@ -23,14 +26,57 @@ class BotUsers(): def save_user_db(self): botdb.set_bot_value('users', self.all) + def add_to_all(self, nick, nick_id=None): + if not nick_id: + nick_id = self.whois(nick) + # add to all if not there + if nick_id not in self.all.keys(): + self.all[nick_id] = [] + # add nick alias + if nick not in self.all[nick_id]: + self.all[nick_id].append(nick) + self.save_user_db() + + def add_to_current(self, nick, nick_id=None): + if not nick_id: + nick_id = self.whois(nick) + # add to current if not there + if nick_id not in self.current.keys(): + self.current[nick_id] = {"channels": []} + def join(self, bot, trigger): # bot block if trigger.nick == bot.nick: + for user in bot.channels[trigger.sender].privileges.keys(): + # Identify + nick_id = self.whois(user) + # Verify nick is in the all list + self.add_to_all(user, nick_id) + # Verify nick is in the all list + self.add_to_current(user, nick_id) + # add joined channel to nick list + if trigger.sender not in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].append(trigger.sender) + # mark user as online + if nick_id not in self.online: + self.online.append(nick_id) + if nick_id in self.offline: + self.offline.remove(nick_id) return # Identify nick_id = self.whois(trigger.nick) - # mark online - self.mark_online(trigger.nick, nick_id) + # Verify nick is in the all list + self.add_to_all(trigger.nick, nick_id) + # Verify nick is in the all list + self.add_to_current(trigger.nick, nick_id) + # add joined channel to nick list + if trigger.sender not in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].append(trigger.sender) + # mark user as online + if nick_id not in self.online: + self.online.append(nick_id) + if nick_id in self.offline: + self.offline.remove(nick_id) def quit(self, bot, trigger): # bot block @@ -38,70 +84,97 @@ class BotUsers(): return # Identify nick_id = self.whois(trigger.nick) - # mark offline - self.mark_offline(trigger.nick, nick_id) + # Verify nick is in the all list + self.add_to_all(trigger.nick, nick_id) + # Verify nick is in the all list + self.add_to_current(trigger.nick, nick_id) + # empty nicks channel list + if trigger.sender in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].remove(trigger.sender) + self.current[nick_id]["channels"] = [] + # mark user as offline + if nick_id in self.online: + self.online.remove(nick_id) + if nick_id not in self.offline: + self.offline.append(nick_id) def part(self, bot, trigger): # bot block if trigger.nick == bot.nick: + for nick_id in self.current.keys(): + if trigger.sender in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].remove(trigger.sender) + # mark offline + if not len(self.current[nick_id]["channels"]) and nick_id in self.online: + self.online.remove(nick_id) + if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: + self.offline.append(nick_id) return # Identify nick_id = self.whois(trigger.nick) + # Verify nick is in the all list + self.add_to_all(trigger.nick, nick_id) + # Verify nick is in the all list + self.add_to_current(trigger.nick, nick_id) + # remove channel from nick list + if trigger.sender in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].remove(trigger.sender) # mark offline - if trigger.nick not in bot.users: - self.mark_offline(trigger.nick, nick_id) + if not len(self.current[nick_id]["channels"]) and nick_id in self.online: + self.online.remove(nick_id) + if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: + self.offline.append(nick_id) def kick(self, bot, trigger): - target = str(trigger.args[1]) + targetnick = Identifier(str(trigger.args[1])) # bot block - if target == bot.nick: + if targetnick == bot.nick: + for nick_id in self.current.keys(): + if trigger.sender in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].remove(trigger.sender) + # mark offline + if not len(self.current[nick_id]["channels"]) and nick_id in self.online: + self.online.remove(nick_id) + if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: + self.offline.append(nick_id) return # Identify - nick_id = self.whois(target) + nick_id = self.whois(targetnick) + # Verify nick is in the all list + self.add_to_all(targetnick, nick_id) + # Verify nick is in the all list + self.add_to_current(targetnick, nick_id) + # remove channel from nick list + if trigger.sender in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].remove(trigger.sender) # mark offline - if target not in bot.users: - self.mark_offline(target, nick_id) + if not len(self.current[nick_id]["channels"]) and nick_id in self.online: + self.online.remove(nick_id) + if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: + self.offline.append(nick_id) - def add_to_all(self, nick, nick_id=None): - if not nick_id: - nick_id = self.whois(nick) - # add to all if not there - if nick_id not in self.all.keys(): - self.all[nick_id] = {"aliases": []} - # add nick alias - if nick not in self.all[nick_id]: - self.all[nick_id]["aliases"].append(nick) - - def mark_online(self, nick, nick_id=None): - if not nick_id: - nick_id = self.whois(nick) - self.add_to_all(nick, nick_id) + def nick(self, bot, trigger): + newnick = Identifier(trigger) + # bot block + if trigger.nick == bot.nick or newnick == bot.nick: + return + # alias the nick + if not botdb.check_nick_id(newnick): + botdb.alias_nick(trigger.nick, newnick) + # Identify + nick_id = self.whois(newnick) + # Verify nick is in the all list + self.add_to_all(newnick, nick_id) + # Verify nick is in the all list + self.add_to_current(newnick, nick_id) + # add joined channel to nick list + if trigger.sender not in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].append(trigger.sender) + # mark user as online if nick_id not in self.online: self.online.append(nick_id) - - def mark_offline(self, nick, nick_id=None): - if not nick_id: - nick_id = self.whois(nick) - self.add_to_all(nick, nick_id) - if nick_id in self.online: - self.online.remove(nick_id) - - def current(self, bot, reqchannel='all'): - user_list = [] - if reqchannel == 'all': - for channel in bot.channels.keys(): - for user in bot.channels[channel].privileges.keys(): - user_id = self.whois(user) - user_list.append(user_id) - return user_list - elif not inlist(reqchannel, bot.channels.keys()): - return user_list - else: - channel = inlist_match(reqchannel, bot.channels.keys()) - for user in bot.channels[channel].privileges.keys(): - user_id = self.whois(user) - user_list.append(user_id) - return user_list + if nick_id in self.offline: + self.offline.remove(nick_id) users = BotUsers() diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index a90e2a7..f0b6547 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -12,6 +12,7 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.rule('.*') def users_join(bot, trigger): bot.say(str(trigger)) + bot.say(str(trigger.nick)) bot.say(str(trigger.args)) # SpiceBot.users.join(bot, trigger) @@ -20,6 +21,7 @@ def users_join(bot, trigger): @sopel.module.rule('.*') def users_quit(bot, trigger): bot.say(str(trigger)) + bot.say(str(trigger.nick)) bot.say(str(trigger.args)) # SpiceBot.users.quit(bot, trigger) @@ -28,6 +30,7 @@ def users_quit(bot, trigger): @sopel.module.rule('.*') def users_part(bot, trigger): bot.say(str(trigger)) + bot.say(str(trigger.nick)) bot.say(str(trigger.args)) # SpiceBot.users.part(bot, trigger) @@ -36,5 +39,15 @@ def users_part(bot, trigger): @sopel.module.rule('.*') def users_kick(bot, trigger): bot.say(str(trigger)) + bot.say(str(trigger.nick)) bot.say(str(trigger.args)) # SpiceBot.users.kick(bot, trigger) + + +@sopel.module.event('NICK') +@sopel.module.rule('.*') +def users_nick(bot, trigger): + bot.say(str(trigger)) + bot.say(str(trigger.nick)) + bot.say(str(trigger.args)) + # SpiceBot.users.nick(bot, trigger) From ec84f00c67bad33f9857ed06f1b80f3a48ae1bf8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 15:32:42 -0400 Subject: [PATCH 11/33] better test --- .../SpiceBot_Core_Processing/Users.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index f0b6547..42d8a5c 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -11,43 +11,43 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.event('JOIN') @sopel.module.rule('.*') def users_join(bot, trigger): - bot.say(str(trigger)) - bot.say(str(trigger.nick)) - bot.say(str(trigger.args)) + bot.say(str(trigger), "#deathbybandaid") + bot.say(str(trigger.nick), "#deathbybandaid") + bot.say(str(trigger.args), "#deathbybandaid") # SpiceBot.users.join(bot, trigger) @sopel.module.event('QUIT') @sopel.module.rule('.*') def users_quit(bot, trigger): - bot.say(str(trigger)) - bot.say(str(trigger.nick)) - bot.say(str(trigger.args)) + bot.say(str(trigger), "#deathbybandaid") + bot.say(str(trigger.nick), "#deathbybandaid") + bot.say(str(trigger.args), "#deathbybandaid") # SpiceBot.users.quit(bot, trigger) @sopel.module.event('PART') @sopel.module.rule('.*') def users_part(bot, trigger): - bot.say(str(trigger)) - bot.say(str(trigger.nick)) - bot.say(str(trigger.args)) + bot.say(str(trigger), "#deathbybandaid") + bot.say(str(trigger.nick), "#deathbybandaid") + bot.say(str(trigger.args), "#deathbybandaid") # SpiceBot.users.part(bot, trigger) @sopel.module.event('KICK') @sopel.module.rule('.*') def users_kick(bot, trigger): - bot.say(str(trigger)) - bot.say(str(trigger.nick)) - bot.say(str(trigger.args)) + bot.say(str(trigger), "#deathbybandaid") + bot.say(str(trigger.nick), "#deathbybandaid") + bot.say(str(trigger.args), "#deathbybandaid") # SpiceBot.users.kick(bot, trigger) @sopel.module.event('NICK') @sopel.module.rule('.*') def users_nick(bot, trigger): - bot.say(str(trigger)) - bot.say(str(trigger.nick)) - bot.say(str(trigger.args)) + bot.say(str(trigger), "#deathbybandaid") + bot.say(str(trigger.nick), "#deathbybandaid") + bot.say(str(trigger.args), "#deathbybandaid") # SpiceBot.users.nick(bot, trigger) From fffed158067e46bbc2ea1260125c775d0deeb3aa Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 15:36:07 -0400 Subject: [PATCH 12/33] better user tracking --- .../SpiceBot_Core_Processing/Users.py | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index 42d8a5c..0082e57 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -11,43 +11,28 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.event('JOIN') @sopel.module.rule('.*') def users_join(bot, trigger): - bot.say(str(trigger), "#deathbybandaid") - bot.say(str(trigger.nick), "#deathbybandaid") - bot.say(str(trigger.args), "#deathbybandaid") - # SpiceBot.users.join(bot, trigger) + SpiceBot.users.join(bot, trigger) @sopel.module.event('QUIT') @sopel.module.rule('.*') def users_quit(bot, trigger): - bot.say(str(trigger), "#deathbybandaid") - bot.say(str(trigger.nick), "#deathbybandaid") - bot.say(str(trigger.args), "#deathbybandaid") - # SpiceBot.users.quit(bot, trigger) + SpiceBot.users.quit(bot, trigger) @sopel.module.event('PART') @sopel.module.rule('.*') def users_part(bot, trigger): - bot.say(str(trigger), "#deathbybandaid") - bot.say(str(trigger.nick), "#deathbybandaid") - bot.say(str(trigger.args), "#deathbybandaid") - # SpiceBot.users.part(bot, trigger) + SpiceBot.users.part(bot, trigger) @sopel.module.event('KICK') @sopel.module.rule('.*') def users_kick(bot, trigger): - bot.say(str(trigger), "#deathbybandaid") - bot.say(str(trigger.nick), "#deathbybandaid") - bot.say(str(trigger.args), "#deathbybandaid") - # SpiceBot.users.kick(bot, trigger) + SpiceBot.users.kick(bot, trigger) @sopel.module.event('NICK') @sopel.module.rule('.*') def users_nick(bot, trigger): - bot.say(str(trigger), "#deathbybandaid") - bot.say(str(trigger.nick), "#deathbybandaid") - bot.say(str(trigger.args), "#deathbybandaid") - # SpiceBot.users.nick(bot, trigger) + SpiceBot.users.nick(bot, trigger) From 541cb46e130e08fdb82c22ad43e8e34f94722a78 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 15:53:07 -0400 Subject: [PATCH 13/33] track users in both user and channel classes --- sopel_modules/SpiceBot/Channels.py | 77 +++++++++++++++++++ .../SpiceBot_Core_Processing/Channels.py | 30 ++++++++ 2 files changed, 107 insertions(+) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index ddf89ce..cbe46ab 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -4,12 +4,14 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot Channels system. """ import sopel +from sopel.tools import Identifier from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute import re import threading from .Config import config as botconfig +from .Database import db as botdb class SpiceBot_Channels_MainSection(StaticSection): @@ -95,5 +97,80 @@ class BotChannels(): else: bot.part(channel) + def whois(self, nick): + nick = Identifier(nick) + nick_id = botdb.db.get_nick_id(nick, create=True) + return nick_id + + def add_to_channel(self, channel, nick, nick_id=None): + if not nick_id: + nick_id = self.whois(nick) + if nick_id not in self.dict['list'][channel.lower()]['users']: + self.dict['list'][channel.lower()]['users'].append(nick_id) + + def remove_from_channel(self, channel, nick, nick_id=None): + if not nick_id: + nick_id = self.whois(nick) + if nick_id in self.dict['list'][channel.lower()]['users']: + self.dict['list'][channel.lower()]['users'].remove(nick_id) + + def remove_all_from_channel(self, channel): + self.dict['list'][channel.lower()]['users'] = [] + + def join(self, bot, trigger): + # bot block + if trigger.nick == bot.nick: + for user in bot.channels[trigger.sender].privileges.keys(): + self.add_to_channel(self, trigger.sender, user) + return + # Identify + nick_id = self.whois(trigger.nick) + # Verify nick is in the channel list + self.add_to_channel(self, trigger.sender, trigger.nick, nick_id) + + def quit(self, bot, trigger): + # bot block + if trigger.nick == bot.nick: + self.remove_all_from_channel(trigger.sender) + return + # Identify + nick_id = self.whois(trigger.nick) + # Verify nick is not in the channel list + self.remove_from_channel(self, trigger.sender, trigger.nick, nick_id) + + def part(self, bot, trigger): + # bot block + if trigger.nick == bot.nick: + self.remove_all_from_channel(trigger.sender) + return + # Identify + nick_id = self.whois(trigger.nick) + # Verify nick is not in the channel list + self.remove_from_channel(self, trigger.sender, trigger.nick, nick_id) + + def kick(self, bot, trigger): + targetnick = Identifier(str(trigger.args[1])) + # bot block + if targetnick == bot.nick: + self.remove_all_from_channel(trigger.sender) + return + # Identify + nick_id = self.whois(targetnick) + # Verify nick is not in the channel list + self.remove_from_channel(self, trigger.sender, targetnick, nick_id) + + def nick(self, bot, trigger): + newnick = Identifier(trigger) + # bot block + if trigger.nick == bot.nick or newnick == bot.nick: + return + # alias the nick + if not botdb.check_nick_id(newnick): + botdb.alias_nick(trigger.nick, newnick) + # Identify + nick_id = self.whois(newnick) + # Verify nick is in the channel list + self.add_to_channel(self, trigger.sender, trigger.nick, nick_id) + channels = BotChannels() diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index 927b513..bd44c41 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -95,3 +95,33 @@ def trigger_channel_list_recurring(bot, trigger): if "*" in SpiceBot.channels.dict['list'].keys(): del SpiceBot.channels.dict['list']["*"] SpiceBot.channels.bot_part_empty(bot) + + +@sopel.module.event('JOIN') +@sopel.module.rule('.*') +def channels_users_join(bot, trigger): + SpiceBot.channels.join(bot, trigger) + + +@sopel.module.event('QUIT') +@sopel.module.rule('.*') +def channels_users_quit(bot, trigger): + SpiceBot.channels.quit(bot, trigger) + + +@sopel.module.event('PART') +@sopel.module.rule('.*') +def channels_users_part(bot, trigger): + SpiceBot.channels.part(bot, trigger) + + +@sopel.module.event('KICK') +@sopel.module.rule('.*') +def channels_users_kick(bot, trigger): + SpiceBot.channels.kick(bot, trigger) + + +@sopel.module.event('NICK') +@sopel.module.rule('.*') +def channels_users_nick(bot, trigger): + SpiceBot.channels.nick(bot, trigger) From 4727c3d102a1543e5fc3a2aa6726681f49e45554 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 16:00:11 -0400 Subject: [PATCH 14/33] track current nick --- sopel_modules/SpiceBot/Users.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index 058f632..c85bb15 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -42,7 +42,7 @@ class BotUsers(): nick_id = self.whois(nick) # add to current if not there if nick_id not in self.current.keys(): - self.current[nick_id] = {"channels": []} + self.current[nick_id] = {"channels": [], "nick": nick} def join(self, bot, trigger): # bot block @@ -54,6 +54,8 @@ class BotUsers(): self.add_to_all(user, nick_id) # Verify nick is in the all list self.add_to_current(user, nick_id) + # set current nick + self.current[nick_id]["nick"] = user # add joined channel to nick list if trigger.sender not in self.current[nick_id]["channels"]: self.current[nick_id]["channels"].append(trigger.sender) @@ -69,6 +71,8 @@ class BotUsers(): self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list self.add_to_current(trigger.nick, nick_id) + # set current nick + self.current[nick_id]["nick"] = trigger.nick # add joined channel to nick list if trigger.sender not in self.current[nick_id]["channels"]: self.current[nick_id]["channels"].append(trigger.sender) @@ -167,6 +171,8 @@ class BotUsers(): self.add_to_all(newnick, nick_id) # Verify nick is in the all list self.add_to_current(newnick, nick_id) + # set current nick + self.current[nick_id]["nick"] = newnick # add joined channel to nick list if trigger.sender not in self.current[nick_id]["channels"]: self.current[nick_id]["channels"].append(trigger.sender) From 84bbad5fff0845d9272e2a7e392d5683ded5f3cf Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 16:09:20 -0400 Subject: [PATCH 15/33] test --- sopel_modules/SpiceBot/Channels.py | 16 ++++++++-------- sopel_modules/SpiceBot/Users.py | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index cbe46ab..28d9033 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -97,20 +97,20 @@ class BotChannels(): else: bot.part(channel) - def whois(self, nick): + def whois_id(self, nick): nick = Identifier(nick) nick_id = botdb.db.get_nick_id(nick, create=True) return nick_id def add_to_channel(self, channel, nick, nick_id=None): if not nick_id: - nick_id = self.whois(nick) + nick_id = self.whois_id(nick) if nick_id not in self.dict['list'][channel.lower()]['users']: self.dict['list'][channel.lower()]['users'].append(nick_id) def remove_from_channel(self, channel, nick, nick_id=None): if not nick_id: - nick_id = self.whois(nick) + nick_id = self.whois_id(nick) if nick_id in self.dict['list'][channel.lower()]['users']: self.dict['list'][channel.lower()]['users'].remove(nick_id) @@ -124,7 +124,7 @@ class BotChannels(): self.add_to_channel(self, trigger.sender, user) return # Identify - nick_id = self.whois(trigger.nick) + nick_id = self.whois_id(trigger.nick) # Verify nick is in the channel list self.add_to_channel(self, trigger.sender, trigger.nick, nick_id) @@ -134,7 +134,7 @@ class BotChannels(): self.remove_all_from_channel(trigger.sender) return # Identify - nick_id = self.whois(trigger.nick) + nick_id = self.whois_id(trigger.nick) # Verify nick is not in the channel list self.remove_from_channel(self, trigger.sender, trigger.nick, nick_id) @@ -144,7 +144,7 @@ class BotChannels(): self.remove_all_from_channel(trigger.sender) return # Identify - nick_id = self.whois(trigger.nick) + nick_id = self.whois_id(trigger.nick) # Verify nick is not in the channel list self.remove_from_channel(self, trigger.sender, trigger.nick, nick_id) @@ -155,7 +155,7 @@ class BotChannels(): self.remove_all_from_channel(trigger.sender) return # Identify - nick_id = self.whois(targetnick) + nick_id = self.whois_id(targetnick) # Verify nick is not in the channel list self.remove_from_channel(self, trigger.sender, targetnick, nick_id) @@ -168,7 +168,7 @@ class BotChannels(): if not botdb.check_nick_id(newnick): botdb.alias_nick(trigger.nick, newnick) # Identify - nick_id = self.whois(newnick) + nick_id = self.whois_id(newnick) # Verify nick is in the channel list self.add_to_channel(self, trigger.sender, trigger.nick, nick_id) diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index c85bb15..f44ea23 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -19,6 +19,12 @@ class BotUsers(): self.current = {} def whois(self, nick): + nick_id = self.whois_id(nick) + self.add_to_all(nick, nick_id) + self.add_to_current(nick, nick_id) + return self.current[nick_id]["nick"] + + def whois_id(self, nick): nick = Identifier(nick) nick_id = botdb.db.get_nick_id(nick, create=True) return nick_id @@ -28,7 +34,7 @@ class BotUsers(): def add_to_all(self, nick, nick_id=None): if not nick_id: - nick_id = self.whois(nick) + nick_id = self.whois_id(nick) # add to all if not there if nick_id not in self.all.keys(): self.all[nick_id] = [] @@ -39,7 +45,7 @@ class BotUsers(): def add_to_current(self, nick, nick_id=None): if not nick_id: - nick_id = self.whois(nick) + nick_id = self.whois_id(nick) # add to current if not there if nick_id not in self.current.keys(): self.current[nick_id] = {"channels": [], "nick": nick} @@ -49,7 +55,7 @@ class BotUsers(): if trigger.nick == bot.nick: for user in bot.channels[trigger.sender].privileges.keys(): # Identify - nick_id = self.whois(user) + nick_id = self.whois_id(user) # Verify nick is in the all list self.add_to_all(user, nick_id) # Verify nick is in the all list @@ -66,7 +72,7 @@ class BotUsers(): self.offline.remove(nick_id) return # Identify - nick_id = self.whois(trigger.nick) + nick_id = self.whois_id(trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -87,7 +93,7 @@ class BotUsers(): if trigger.nick == bot.nick: return # Identify - nick_id = self.whois(trigger.nick) + nick_id = self.whois_id(trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -115,7 +121,7 @@ class BotUsers(): self.offline.append(nick_id) return # Identify - nick_id = self.whois(trigger.nick) + nick_id = self.whois_id(trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -143,7 +149,7 @@ class BotUsers(): self.offline.append(nick_id) return # Identify - nick_id = self.whois(targetnick) + nick_id = self.whois_id(targetnick) # Verify nick is in the all list self.add_to_all(targetnick, nick_id) # Verify nick is in the all list @@ -166,7 +172,7 @@ class BotUsers(): if not botdb.check_nick_id(newnick): botdb.alias_nick(trigger.nick, newnick) # Identify - nick_id = self.whois(newnick) + nick_id = self.whois_id(newnick) # Verify nick is in the all list self.add_to_all(newnick, nick_id) # Verify nick is in the all list From efc2db36ecc4ff841430231cca0086a75d73fdf6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 16:14:45 -0400 Subject: [PATCH 16/33] start thinking about modes --- sopel_modules/SpiceBot/Channels.py | 3 +++ sopel_modules/SpiceBot/Users.py | 3 +++ sopel_modules/SpiceBot_Core_Processing/Channels.py | 7 +++++++ sopel_modules/SpiceBot_Core_Processing/Users.py | 7 +++++++ 4 files changed, 20 insertions(+) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index 28d9033..e11a049 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -172,5 +172,8 @@ class BotChannels(): # Verify nick is in the channel list self.add_to_channel(self, trigger.sender, trigger.nick, nick_id) + def mode(self, bot, trigger): + return + channels = BotChannels() diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index f44ea23..cf61d09 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -188,5 +188,8 @@ class BotUsers(): if nick_id in self.offline: self.offline.remove(nick_id) + def mode(self, bot, trigger): + return + users = BotUsers() diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index bd44c41..dd01c94 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -125,3 +125,10 @@ def channels_users_kick(bot, trigger): @sopel.module.rule('.*') def channels_users_nick(bot, trigger): SpiceBot.channels.nick(bot, trigger) + + +@sopel.module.event('MODE') +@sopel.module.rule('.*') +def channels_users_mode(bot, trigger): + SpiceBot.channels.mode(bot, trigger) + # TODO diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index 0082e57..5f8dc47 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -36,3 +36,10 @@ def users_kick(bot, trigger): @sopel.module.rule('.*') def users_nick(bot, trigger): SpiceBot.users.nick(bot, trigger) + + +@sopel.module.event('MODE') +@sopel.module.rule('.*') +def users_mode(bot, trigger): + SpiceBot.users.mode(bot, trigger) + # TODO From 22a0e6f560ae1b76adf388a73a378c54e23aa01e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 16:22:07 -0400 Subject: [PATCH 17/33] more prep --- sopel_modules/SpiceBot/Tools.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sopel_modules/SpiceBot/Tools.py b/sopel_modules/SpiceBot/Tools.py index 1a9f94a..1412801 100644 --- a/sopel_modules/SpiceBot/Tools.py +++ b/sopel_modules/SpiceBot/Tools.py @@ -35,6 +35,17 @@ github_dict = { "repo_name": "SpiceBot", } +mode_dict_alias = { + "+o": "OP", "-o": "deOP", + "+v": "VOICE", "-v": "deVOICE", + "+h": "HOP", "-h": "deHOP", + "+a": "ADMIN", "-a": "deADMIN", + "+q": "OWNER", "-q": "deOWNER", + "+b": "BAN", "-b": "unBAN", + "+c": "noCOLOR", "-c": "COLOR", + # TODO add more user/channel modes + } + """Sopel Wrapping Tools""" From 59aa6286c09edefd20f457530804e720757e493a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 16:24:54 -0400 Subject: [PATCH 18/33] repair --- sopel_modules/SpiceBot/Channels.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index e11a049..d937362 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -121,12 +121,12 @@ class BotChannels(): # bot block if trigger.nick == bot.nick: for user in bot.channels[trigger.sender].privileges.keys(): - self.add_to_channel(self, trigger.sender, user) + self.add_to_channel(trigger.sender, user) return # Identify nick_id = self.whois_id(trigger.nick) # Verify nick is in the channel list - self.add_to_channel(self, trigger.sender, trigger.nick, nick_id) + self.add_to_channel(trigger.sender, trigger.nick, nick_id) def quit(self, bot, trigger): # bot block @@ -136,7 +136,7 @@ class BotChannels(): # Identify nick_id = self.whois_id(trigger.nick) # Verify nick is not in the channel list - self.remove_from_channel(self, trigger.sender, trigger.nick, nick_id) + self.remove_from_channel(trigger.sender, trigger.nick, nick_id) def part(self, bot, trigger): # bot block @@ -146,7 +146,7 @@ class BotChannels(): # Identify nick_id = self.whois_id(trigger.nick) # Verify nick is not in the channel list - self.remove_from_channel(self, trigger.sender, trigger.nick, nick_id) + self.remove_from_channel(trigger.sender, trigger.nick, nick_id) def kick(self, bot, trigger): targetnick = Identifier(str(trigger.args[1])) @@ -157,7 +157,7 @@ class BotChannels(): # Identify nick_id = self.whois_id(targetnick) # Verify nick is not in the channel list - self.remove_from_channel(self, trigger.sender, targetnick, nick_id) + self.remove_from_channel(trigger.sender, targetnick, nick_id) def nick(self, bot, trigger): newnick = Identifier(trigger) @@ -170,7 +170,7 @@ class BotChannels(): # Identify nick_id = self.whois_id(newnick) # Verify nick is in the channel list - self.add_to_channel(self, trigger.sender, trigger.nick, nick_id) + self.add_to_channel(trigger.sender, trigger.nick, nick_id) def mode(self, bot, trigger): return From 4619dcc546bd845de2a44118ca0b0be498915bbf Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 16:34:18 -0400 Subject: [PATCH 19/33] boom --- sopel_modules/SpiceBot/Channels.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index d937362..8f6710f 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -105,16 +105,28 @@ class BotChannels(): def add_to_channel(self, channel, nick, nick_id=None): if not nick_id: nick_id = self.whois_id(nick) + if channel.lower() not in self.dict['list'].keys(): + self.dict['list'][channel.lower()] = dict() + if 'users' not in self.dict['list'][channel.lower()]: + self.dict['list'][channel.lower()]['users'] = [] if nick_id not in self.dict['list'][channel.lower()]['users']: self.dict['list'][channel.lower()]['users'].append(nick_id) def remove_from_channel(self, channel, nick, nick_id=None): if not nick_id: nick_id = self.whois_id(nick) + if channel.lower() not in self.dict['list'].keys(): + self.dict['list'][channel.lower()] = dict() + if 'users' not in self.dict['list'][channel.lower()]: + self.dict['list'][channel.lower()]['users'] = [] if nick_id in self.dict['list'][channel.lower()]['users']: self.dict['list'][channel.lower()]['users'].remove(nick_id) def remove_all_from_channel(self, channel): + if channel.lower() not in self.dict['list'].keys(): + self.dict['list'][channel.lower()] = dict() + if 'users' not in self.dict['list'][channel.lower()]: + self.dict['list'][channel.lower()]['users'] = [] self.dict['list'][channel.lower()]['users'] = [] def join(self, bot, trigger): From ed260e662693e17e6362dbb8d60805d3f3619835 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 19:11:02 -0400 Subject: [PATCH 20/33] user and channel scanning --- sopel_modules/SpiceBot/Channels.py | 5 ++++ sopel_modules/SpiceBot/Users.py | 25 +++++++++++++++---- .../SpiceBot_Core_Processing/Channels.py | 7 ++++++ .../SpiceBot_Core_Processing/Users.py | 7 ++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index 8f6710f..e1ae109 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -129,6 +129,11 @@ class BotChannels(): self.dict['list'][channel.lower()]['users'] = [] self.dict['list'][channel.lower()]['users'] = [] + def channel_scan(self, bot): + for channel in bot.channels.keys(): + for user in bot.channels[channel].privileges.keys(): + self.add_to_channel(channel, user) + def join(self, bot, trigger): # bot block if trigger.nick == bot.nick: diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index cf61d09..3f508ba 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -50,8 +50,27 @@ class BotUsers(): if nick_id not in self.current.keys(): self.current[nick_id] = {"channels": [], "nick": nick} + def channel_scan(self, bot): + for channel in bot.channels.keys(): + for user in bot.channels[channel].privileges.keys(): + # Identify + nick_id = self.whois_id(user) + # Verify nick is in the all list + self.add_to_all(user, nick_id) + # Verify nick is in the all list + self.add_to_current(user, nick_id) + # set current nick + self.current[nick_id]["nick"] = user + # add joined channel to nick list + if channel not in self.current[nick_id]["channels"]: + self.current[nick_id]["channels"].append(channel) + # mark user as online + if nick_id not in self.online: + self.online.append(nick_id) + if nick_id in self.offline: + self.offline.remove(nick_id) + def join(self, bot, trigger): - # bot block if trigger.nick == bot.nick: for user in bot.channels[trigger.sender].privileges.keys(): # Identify @@ -89,7 +108,6 @@ class BotUsers(): self.offline.remove(nick_id) def quit(self, bot, trigger): - # bot block if trigger.nick == bot.nick: return # Identify @@ -109,7 +127,6 @@ class BotUsers(): self.offline.append(nick_id) def part(self, bot, trigger): - # bot block if trigger.nick == bot.nick: for nick_id in self.current.keys(): if trigger.sender in self.current[nick_id]["channels"]: @@ -137,7 +154,6 @@ class BotUsers(): def kick(self, bot, trigger): targetnick = Identifier(str(trigger.args[1])) - # bot block if targetnick == bot.nick: for nick_id in self.current.keys(): if trigger.sender in self.current[nick_id]["channels"]: @@ -165,7 +181,6 @@ class BotUsers(): def nick(self, bot, trigger): newnick = Identifier(trigger) - # bot block if trigger.nick == bot.nick or newnick == bot.nick: return # alias the nick diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index dd01c94..b4ca4d4 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -132,3 +132,10 @@ def channels_users_nick(bot, trigger): def channels_users_mode(bot, trigger): SpiceBot.channels.mode(bot, trigger) # TODO + + +@sopel.module.event(SpiceBot.events.BOT_CONNECTED) +@sopel.module.rule('.*') +def bot_channelscan(bot, trigger): + while True: + SpiceBot.channels.channel_scan(bot) diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index 5f8dc47..3080126 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -43,3 +43,10 @@ def users_nick(bot, trigger): def users_mode(bot, trigger): SpiceBot.users.mode(bot, trigger) # TODO + + +@sopel.module.event(SpiceBot.events.BOT_CONNECTED) +@sopel.module.rule('.*') +def bot_channelscan_users(bot, trigger): + while True: + SpiceBot.users.channel_scan(bot) From 84d202a7793123857d5da65461440d22db901a93 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 19:23:48 -0400 Subject: [PATCH 21/33] database tweaks --- sopel_modules/SpiceBot/Database.py | 70 ++++++++++++++++++------------ 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 68283c1..e082150 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -45,7 +45,7 @@ class NickValues(BASE): """ __tablename__ = 'spice_nick_values' nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) - namespace = Column(String(255), primary_key=True) + # namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) value = Column(Text()) @@ -56,7 +56,7 @@ class ChannelValues(BASE): """ __tablename__ = 'spice_channel_values' channel = Column(String(255), primary_key=True) - namespace = Column(String(255), primary_key=True) + # namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) value = Column(Text()) @@ -67,7 +67,7 @@ class PluginValues(BASE): """ __tablename__ = 'spice_plugin_values' plugin = Column(String(255), primary_key=True) - namespace = Column(String(255), primary_key=True) + # namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) value = Column(Text()) @@ -83,9 +83,10 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: + # .filter(NickValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ - .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, update @@ -94,7 +95,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_nickvalue = NickValues(nick_id=nick_id, namespace=namespace, key=key, value=value) + new_nickvalue = NickValues(nick_id=nick_id, key=key, value=value) session.add(new_nickvalue) session.commit() except SQLAlchemyError: @@ -108,10 +109,11 @@ class SpiceDB(object): nick = Identifier(nick) session = self.ssession() try: + # .filter(NickValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(NickValues) \ .filter(Nicknames.nick_id == NickValues.nick_id) \ .filter(Nicknames.slug == nick.lower()) \ - .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() if result is not None: @@ -129,9 +131,10 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: + # .filter(NickValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ - .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, delete @@ -151,9 +154,10 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: + # .filter(NickValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ - .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, update @@ -162,7 +166,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_nickvalue = NickValues(nick_id=nick_id, namespace=namespace, key=key, value=float(value)) + new_nickvalue = NickValues(nick_id=nick_id, key=key, value=float(value)) session.add(new_nickvalue) session.commit() except SQLAlchemyError: @@ -180,9 +184,10 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: + # .filter(NickValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ - .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, update @@ -207,7 +212,7 @@ class SpiceDB(object): for entry in entries: while entry in values: values.remove(entry) - new_nickvalue = NickValues(nick_id=nick_id, namespace=namespace, key=key, value=values) + new_nickvalue = NickValues(nick_id=nick_id, key=key, value=values) session.add(new_nickvalue) session.commit() except SQLAlchemyError: @@ -224,9 +229,10 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: + # .filter(ChannelValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ - .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -235,7 +241,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_channelvalue = ChannelValues(channel=channel, namespace=namespace, key=key, value=value) + new_channelvalue = ChannelValues(channel=channel, key=key, value=value) session.add(new_channelvalue) session.commit() except SQLAlchemyError: @@ -249,9 +255,10 @@ class SpiceDB(object): channel = Identifier(channel).lower() session = self.ssession() try: + # .filter(ChannelValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ - .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() if result is not None: @@ -268,9 +275,10 @@ class SpiceDB(object): channel = Identifier(channel).lower() session = self.ssession() try: + # .filter(ChannelValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ - .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, delete @@ -289,9 +297,10 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: + # .filter(ChannelValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ - .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -300,7 +309,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_channelvalue = ChannelValues(channel=channel, namespace=namespace, key=key, value=float(value)) + new_channelvalue = ChannelValues(channel=channel, key=key, value=float(value)) session.add(new_channelvalue) session.commit() except SQLAlchemyError: @@ -317,9 +326,10 @@ class SpiceDB(object): entries = json.dumps(entries, ensure_ascii=False) session = self.ssession() try: + # .filter(ChannelValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ - .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -344,7 +354,7 @@ class SpiceDB(object): for entry in entries: while entry in values: values.remove(entry) - new_channelvalue = ChannelValues(channel=channel, namespace=namespace, key=key, value=values) + new_channelvalue = ChannelValues(channel=channel, key=key, value=values) session.add(new_channelvalue) session.commit() except SQLAlchemyError: @@ -361,9 +371,10 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: + # .filter(PluginValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ - .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # PluginValues exists, update @@ -372,7 +383,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=value) + new_pluginvalue = PluginValues(plugin=plugin, key=key, value=value) session.add(new_pluginvalue) session.commit() except SQLAlchemyError: @@ -386,9 +397,10 @@ class SpiceDB(object): plugin = Identifier(plugin).lower() session = self.ssession() try: + # .filter(PluginValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ - .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() if result is not None: @@ -405,9 +417,10 @@ class SpiceDB(object): plugin = Identifier(plugin).lower() session = self.ssession() try: + # .filter(PluginValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ - .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # PluginValues exists, delete @@ -426,9 +439,10 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: + # .filter(PluginValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ - .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -437,7 +451,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=float(value)) + new_pluginvalue = PluginValues(plugin=plugin, key=key, value=float(value)) session.add(new_pluginvalue) session.commit() except SQLAlchemyError: @@ -454,9 +468,10 @@ class SpiceDB(object): entries = json.dumps(entries, ensure_ascii=False) session = self.ssession() try: + # .filter(PluginValues.namespace == namespace)\ + key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ - .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -481,7 +496,8 @@ class SpiceDB(object): for entry in entries: while entry in values: values.remove(entry) - new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=values) + new_pluginvalue = PluginValues(plugin=plugin, key=key, value=values) + # new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=values) session.add(new_pluginvalue) session.commit() except SQLAlchemyError: From e338543a4d3e28a0c9d34508432b68674bd07d45 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 19:39:01 -0400 Subject: [PATCH 22/33] reinstate namespace --- sopel_modules/SpiceBot/Database.py | 70 ++++++++++++------------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index e082150..68283c1 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -45,7 +45,7 @@ class NickValues(BASE): """ __tablename__ = 'spice_nick_values' nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) - # namespace = Column(String(255), primary_key=True) + namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) value = Column(Text()) @@ -56,7 +56,7 @@ class ChannelValues(BASE): """ __tablename__ = 'spice_channel_values' channel = Column(String(255), primary_key=True) - # namespace = Column(String(255), primary_key=True) + namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) value = Column(Text()) @@ -67,7 +67,7 @@ class PluginValues(BASE): """ __tablename__ = 'spice_plugin_values' plugin = Column(String(255), primary_key=True) - # namespace = Column(String(255), primary_key=True) + namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) value = Column(Text()) @@ -83,10 +83,9 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: - # .filter(NickValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ + .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, update @@ -95,7 +94,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_nickvalue = NickValues(nick_id=nick_id, key=key, value=value) + new_nickvalue = NickValues(nick_id=nick_id, namespace=namespace, key=key, value=value) session.add(new_nickvalue) session.commit() except SQLAlchemyError: @@ -109,11 +108,10 @@ class SpiceDB(object): nick = Identifier(nick) session = self.ssession() try: - # .filter(NickValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(NickValues) \ .filter(Nicknames.nick_id == NickValues.nick_id) \ .filter(Nicknames.slug == nick.lower()) \ + .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() if result is not None: @@ -131,10 +129,9 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: - # .filter(NickValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ + .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, delete @@ -154,10 +151,9 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: - # .filter(NickValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ + .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, update @@ -166,7 +162,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_nickvalue = NickValues(nick_id=nick_id, key=key, value=float(value)) + new_nickvalue = NickValues(nick_id=nick_id, namespace=namespace, key=key, value=float(value)) session.add(new_nickvalue) session.commit() except SQLAlchemyError: @@ -184,10 +180,9 @@ class SpiceDB(object): nick_id = self.get_nick_id(nick) session = self.ssession() try: - # .filter(NickValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(NickValues) \ .filter(NickValues.nick_id == nick_id) \ + .filter(NickValues.namespace == namespace)\ .filter(NickValues.key == key) \ .one_or_none() # NickValue exists, update @@ -212,7 +207,7 @@ class SpiceDB(object): for entry in entries: while entry in values: values.remove(entry) - new_nickvalue = NickValues(nick_id=nick_id, key=key, value=values) + new_nickvalue = NickValues(nick_id=nick_id, namespace=namespace, key=key, value=values) session.add(new_nickvalue) session.commit() except SQLAlchemyError: @@ -229,10 +224,9 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: - # .filter(ChannelValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ + .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -241,7 +235,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_channelvalue = ChannelValues(channel=channel, key=key, value=value) + new_channelvalue = ChannelValues(channel=channel, namespace=namespace, key=key, value=value) session.add(new_channelvalue) session.commit() except SQLAlchemyError: @@ -255,10 +249,9 @@ class SpiceDB(object): channel = Identifier(channel).lower() session = self.ssession() try: - # .filter(ChannelValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ + .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() if result is not None: @@ -275,10 +268,9 @@ class SpiceDB(object): channel = Identifier(channel).lower() session = self.ssession() try: - # .filter(ChannelValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ + .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, delete @@ -297,10 +289,9 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: - # .filter(ChannelValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ + .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -309,7 +300,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_channelvalue = ChannelValues(channel=channel, key=key, value=float(value)) + new_channelvalue = ChannelValues(channel=channel, namespace=namespace, key=key, value=float(value)) session.add(new_channelvalue) session.commit() except SQLAlchemyError: @@ -326,10 +317,9 @@ class SpiceDB(object): entries = json.dumps(entries, ensure_ascii=False) session = self.ssession() try: - # .filter(ChannelValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(ChannelValues) \ .filter(ChannelValues.channel == channel)\ + .filter(ChannelValues.namespace == namespace)\ .filter(ChannelValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -354,7 +344,7 @@ class SpiceDB(object): for entry in entries: while entry in values: values.remove(entry) - new_channelvalue = ChannelValues(channel=channel, key=key, value=values) + new_channelvalue = ChannelValues(channel=channel, namespace=namespace, key=key, value=values) session.add(new_channelvalue) session.commit() except SQLAlchemyError: @@ -371,10 +361,9 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: - # .filter(PluginValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ + .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # PluginValues exists, update @@ -383,7 +372,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_pluginvalue = PluginValues(plugin=plugin, key=key, value=value) + new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=value) session.add(new_pluginvalue) session.commit() except SQLAlchemyError: @@ -397,10 +386,9 @@ class SpiceDB(object): plugin = Identifier(plugin).lower() session = self.ssession() try: - # .filter(PluginValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ + .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() if result is not None: @@ -417,10 +405,9 @@ class SpiceDB(object): plugin = Identifier(plugin).lower() session = self.ssession() try: - # .filter(PluginValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ + .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # PluginValues exists, delete @@ -439,10 +426,9 @@ class SpiceDB(object): value = json.dumps(value, ensure_ascii=False) session = self.ssession() try: - # .filter(PluginValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ + .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -451,7 +437,7 @@ class SpiceDB(object): session.commit() # DNE - Insert else: - new_pluginvalue = PluginValues(plugin=plugin, key=key, value=float(value)) + new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=float(value)) session.add(new_pluginvalue) session.commit() except SQLAlchemyError: @@ -468,10 +454,9 @@ class SpiceDB(object): entries = json.dumps(entries, ensure_ascii=False) session = self.ssession() try: - # .filter(PluginValues.namespace == namespace)\ - key = namespace + "_" + key result = session.query(PluginValues) \ .filter(PluginValues.plugin == plugin)\ + .filter(PluginValues.namespace == namespace)\ .filter(PluginValues.key == key) \ .one_or_none() # ChannelValue exists, update @@ -496,8 +481,7 @@ class SpiceDB(object): for entry in entries: while entry in values: values.remove(entry) - new_pluginvalue = PluginValues(plugin=plugin, key=key, value=values) - # new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=values) + new_pluginvalue = PluginValues(plugin=plugin, namespace=namespace, key=key, value=values) session.add(new_pluginvalue) session.commit() except SQLAlchemyError: From 344d114146545bf96a8645d6b08035a03f821ea4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 19:40:34 -0400 Subject: [PATCH 23/33] possible crossover with normal bot db --- sopel_modules/SpiceBot/Database.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 68283c1..a4d2a81 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -25,7 +25,7 @@ class NickIDs(BASE): """ NickIDs SQLAlchemy Class """ - __tablename__ = 'nick_ids' + __tablename__ = 'spice_nick_ids' nick_id = Column(Integer, primary_key=True) @@ -34,7 +34,7 @@ class Nicknames(BASE): Nicknames SQLAlchemy Class """ __tablename__ = 'nicknames' - nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) + nick_id = Column(Integer, ForeignKey('spice_nick_ids.nick_id'), primary_key=True) slug = Column(String(255), primary_key=True) canonical = Column(String(255)) @@ -44,7 +44,7 @@ class NickValues(BASE): NickValues SQLAlchemy Class """ __tablename__ = 'spice_nick_values' - nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) + nick_id = Column(Integer, ForeignKey('spice_nick_ids.nick_id'), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) value = Column(Text()) From 0b86171a239a85bf417aa270a54ea58f0733e2d5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 19:42:31 -0400 Subject: [PATCH 24/33] hmmm --- sopel_modules/SpiceBot/Database.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index a4d2a81..2a280c6 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -496,6 +496,8 @@ class BotDatabase(): def __init__(self): + sopel.db.NickIDs = NickIDs + sopel.db.Nicknames = Nicknames sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value SopelDB.set_nick_value = SpiceDB.set_nick_value From 15d3bd964a7db90d13193ff21bd240cadedeacf3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 19:54:08 -0400 Subject: [PATCH 25/33] column names --- sopel_modules/SpiceBot/Database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 2a280c6..4cb8f81 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -33,7 +33,7 @@ class Nicknames(BASE): """ Nicknames SQLAlchemy Class """ - __tablename__ = 'nicknames' + __tablename__ = 'spice_nicknames' nick_id = Column(Integer, ForeignKey('spice_nick_ids.nick_id'), primary_key=True) slug = Column(String(255), primary_key=True) canonical = Column(String(255)) From 040e395a082ec2172a417cc6d7c5c591d12af09e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:13:33 -0400 Subject: [PATCH 26/33] test --- sopel_modules/SpiceBot_Core_Processing/Channels.py | 1 + sopel_modules/SpiceBot_Core_Processing/Users.py | 1 + 2 files changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index b4ca4d4..f6b0698 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -137,5 +137,6 @@ def channels_users_mode(bot, trigger): @sopel.module.event(SpiceBot.events.BOT_CONNECTED) @sopel.module.rule('.*') def bot_channelscan(bot, trigger): + return while True: SpiceBot.channels.channel_scan(bot) diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index 3080126..b85e41e 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -48,5 +48,6 @@ def users_mode(bot, trigger): @sopel.module.event(SpiceBot.events.BOT_CONNECTED) @sopel.module.rule('.*') def bot_channelscan_users(bot, trigger): + return while True: SpiceBot.users.channel_scan(bot) From 723df6c56014698922984e3cd3b5c416d3083c90 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:16:53 -0400 Subject: [PATCH 27/33] hmmm, bot join doesn't do it --- sopel_modules/SpiceBot_Core_Processing/Channels.py | 1 - sopel_modules/SpiceBot_Core_Processing/Users.py | 1 - 2 files changed, 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index f6b0698..b4ca4d4 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -137,6 +137,5 @@ def channels_users_mode(bot, trigger): @sopel.module.event(SpiceBot.events.BOT_CONNECTED) @sopel.module.rule('.*') def bot_channelscan(bot, trigger): - return while True: SpiceBot.channels.channel_scan(bot) diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index b85e41e..3080126 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -48,6 +48,5 @@ def users_mode(bot, trigger): @sopel.module.event(SpiceBot.events.BOT_CONNECTED) @sopel.module.rule('.*') def bot_channelscan_users(bot, trigger): - return while True: SpiceBot.users.channel_scan(bot) From 094042e04e9ff8eee0b817616323bfa7b8aa6dae Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:22:32 -0400 Subject: [PATCH 28/33] test --- setup.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/setup.py b/setup.py index a65f758..188e5a5 100755 --- a/setup.py +++ b/setup.py @@ -23,28 +23,6 @@ with open('requirements.txt') as requirements_file: with open('dev-requirements.txt') as dev_requirements_file: dev_requirements = [req for req in dev_requirements_file.readlines()] -pipcommand = "sudo pip3 install --upgrade" -pipcommand += " --force-reinstall" -pipcommand += " git+https://github.com/sopel-irc/sopel@master" - -print('Running {} '.format(pipcommand), file=sys.stderr) -for line in os.popen(pipcommand).read().split('\n'): - print(line, file=sys.stderr) - -import sopel - -# 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) - - setup( name='sopel_modules.SpiceBot', version='0.1.1', From 23564fc735c7caa51423a8ffe85cc78e07128b8f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:25:03 -0400 Subject: [PATCH 29/33] test with int --- sopel_modules/SpiceBot/Channels.py | 2 +- sopel_modules/SpiceBot/Users.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index e1ae109..fc42879 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -110,7 +110,7 @@ class BotChannels(): if 'users' not in self.dict['list'][channel.lower()]: self.dict['list'][channel.lower()]['users'] = [] if nick_id not in self.dict['list'][channel.lower()]['users']: - self.dict['list'][channel.lower()]['users'].append(nick_id) + self.dict['list'][channel.lower()]['users'].append(int(nick_id)) def remove_from_channel(self, channel, nick, nick_id=None): if not nick_id: diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index 3f508ba..55c28c6 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -66,7 +66,7 @@ class BotUsers(): self.current[nick_id]["channels"].append(channel) # mark user as online if nick_id not in self.online: - self.online.append(nick_id) + self.online.append(int(nick_id)) if nick_id in self.offline: self.offline.remove(nick_id) @@ -86,7 +86,7 @@ class BotUsers(): self.current[nick_id]["channels"].append(trigger.sender) # mark user as online if nick_id not in self.online: - self.online.append(nick_id) + self.online.append(int(nick_id)) if nick_id in self.offline: self.offline.remove(nick_id) return @@ -103,7 +103,7 @@ class BotUsers(): self.current[nick_id]["channels"].append(trigger.sender) # mark user as online if nick_id not in self.online: - self.online.append(nick_id) + self.online.append(int(nick_id)) if nick_id in self.offline: self.offline.remove(nick_id) @@ -124,7 +124,7 @@ class BotUsers(): if nick_id in self.online: self.online.remove(nick_id) if nick_id not in self.offline: - self.offline.append(nick_id) + self.offline.append(int(nick_id)) def part(self, bot, trigger): if trigger.nick == bot.nick: @@ -135,7 +135,7 @@ class BotUsers(): if not len(self.current[nick_id]["channels"]) and nick_id in self.online: self.online.remove(nick_id) if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: - self.offline.append(nick_id) + self.offline.append(int(nick_id)) return # Identify nick_id = self.whois_id(trigger.nick) @@ -150,7 +150,7 @@ class BotUsers(): if not len(self.current[nick_id]["channels"]) and nick_id in self.online: self.online.remove(nick_id) if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: - self.offline.append(nick_id) + self.offline.append(int(nick_id)) def kick(self, bot, trigger): targetnick = Identifier(str(trigger.args[1])) @@ -162,7 +162,7 @@ class BotUsers(): if not len(self.current[nick_id]["channels"]) and nick_id in self.online: self.online.remove(nick_id) if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: - self.offline.append(nick_id) + self.offline.append(int(nick_id)) return # Identify nick_id = self.whois_id(targetnick) @@ -177,7 +177,7 @@ class BotUsers(): if not len(self.current[nick_id]["channels"]) and nick_id in self.online: self.online.remove(nick_id) if not len(self.current[nick_id]["channels"]) and nick_id not in self.offline: - self.offline.append(nick_id) + self.offline.append(int(nick_id)) def nick(self, bot, trigger): newnick = Identifier(trigger) @@ -199,7 +199,7 @@ class BotUsers(): self.current[nick_id]["channels"].append(trigger.sender) # mark user as online if nick_id not in self.online: - self.online.append(nick_id) + self.online.append(int(nick_id)) if nick_id in self.offline: self.offline.remove(nick_id) From dfbc80cac7568ca333fcd6294c12d3fe7826c227 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:31:27 -0400 Subject: [PATCH 30/33] going to delete db as well --- sopel_modules/SpiceBot/Users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index 55c28c6..90cd78c 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -15,7 +15,7 @@ class BotUsers(): self.online = [] self.offline = [] for user_id in self.all.keys(): - self.offline.append(user_id) + self.offline.append(int(user_id)) self.current = {} def whois(self, nick): @@ -27,7 +27,7 @@ class BotUsers(): def whois_id(self, nick): nick = Identifier(nick) nick_id = botdb.db.get_nick_id(nick, create=True) - return nick_id + return int(nick_id) def save_user_db(self): botdb.set_bot_value('users', self.all) From 90b797c59c2638577be208817fa77c33aa989dff Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:42:00 -0400 Subject: [PATCH 31/33] add id to nick function --- sopel_modules/SpiceBot/Channels.py | 16 ++++++++-------- sopel_modules/SpiceBot/Users.py | 30 +++++++++++++++++++----------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index fc42879..74366aa 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -97,14 +97,14 @@ class BotChannels(): else: bot.part(channel) - def whois_id(self, nick): + def whois_ident(self, nick): nick = Identifier(nick) nick_id = botdb.db.get_nick_id(nick, create=True) return nick_id def add_to_channel(self, channel, nick, nick_id=None): if not nick_id: - nick_id = self.whois_id(nick) + nick_id = self.whois_ident(nick) if channel.lower() not in self.dict['list'].keys(): self.dict['list'][channel.lower()] = dict() if 'users' not in self.dict['list'][channel.lower()]: @@ -114,7 +114,7 @@ class BotChannels(): def remove_from_channel(self, channel, nick, nick_id=None): if not nick_id: - nick_id = self.whois_id(nick) + nick_id = self.whois_ident(nick) if channel.lower() not in self.dict['list'].keys(): self.dict['list'][channel.lower()] = dict() if 'users' not in self.dict['list'][channel.lower()]: @@ -141,7 +141,7 @@ class BotChannels(): self.add_to_channel(trigger.sender, user) return # Identify - nick_id = self.whois_id(trigger.nick) + nick_id = self.whois_ident(trigger.nick) # Verify nick is in the channel list self.add_to_channel(trigger.sender, trigger.nick, nick_id) @@ -151,7 +151,7 @@ class BotChannels(): self.remove_all_from_channel(trigger.sender) return # Identify - nick_id = self.whois_id(trigger.nick) + nick_id = self.whois_ident(trigger.nick) # Verify nick is not in the channel list self.remove_from_channel(trigger.sender, trigger.nick, nick_id) @@ -161,7 +161,7 @@ class BotChannels(): self.remove_all_from_channel(trigger.sender) return # Identify - nick_id = self.whois_id(trigger.nick) + nick_id = self.whois_ident(trigger.nick) # Verify nick is not in the channel list self.remove_from_channel(trigger.sender, trigger.nick, nick_id) @@ -172,7 +172,7 @@ class BotChannels(): self.remove_all_from_channel(trigger.sender) return # Identify - nick_id = self.whois_id(targetnick) + nick_id = self.whois_ident(targetnick) # Verify nick is not in the channel list self.remove_from_channel(trigger.sender, targetnick, nick_id) @@ -185,7 +185,7 @@ class BotChannels(): if not botdb.check_nick_id(newnick): botdb.alias_nick(trigger.nick, newnick) # Identify - nick_id = self.whois_id(newnick) + nick_id = self.whois_ident(newnick) # Verify nick is in the channel list self.add_to_channel(trigger.sender, trigger.nick, nick_id) diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index 90cd78c..f034a53 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -19,12 +19,20 @@ class BotUsers(): self.current = {} def whois(self, nick): - nick_id = self.whois_id(nick) + nick_id = self.whois_ident(nick) self.add_to_all(nick, nick_id) self.add_to_current(nick, nick_id) return self.current[nick_id]["nick"] - def whois_id(self, nick): + def whois_id(self, nick_id): + if nick_id in self.current.keys(): + return self.current[nick_id]["nick"] + elif int(nick_id) in self.all.keys() and len(self.all[nick_id]): + return self.all[nick_id][0] + else: + return None + + def whois_ident(self, nick): nick = Identifier(nick) nick_id = botdb.db.get_nick_id(nick, create=True) return int(nick_id) @@ -34,7 +42,7 @@ class BotUsers(): def add_to_all(self, nick, nick_id=None): if not nick_id: - nick_id = self.whois_id(nick) + nick_id = self.whois_ident(nick) # add to all if not there if nick_id not in self.all.keys(): self.all[nick_id] = [] @@ -45,7 +53,7 @@ class BotUsers(): def add_to_current(self, nick, nick_id=None): if not nick_id: - nick_id = self.whois_id(nick) + nick_id = self.whois_ident(nick) # add to current if not there if nick_id not in self.current.keys(): self.current[nick_id] = {"channels": [], "nick": nick} @@ -54,7 +62,7 @@ class BotUsers(): for channel in bot.channels.keys(): for user in bot.channels[channel].privileges.keys(): # Identify - nick_id = self.whois_id(user) + nick_id = self.whois_ident(user) # Verify nick is in the all list self.add_to_all(user, nick_id) # Verify nick is in the all list @@ -74,7 +82,7 @@ class BotUsers(): if trigger.nick == bot.nick: for user in bot.channels[trigger.sender].privileges.keys(): # Identify - nick_id = self.whois_id(user) + nick_id = self.whois_ident(user) # Verify nick is in the all list self.add_to_all(user, nick_id) # Verify nick is in the all list @@ -91,7 +99,7 @@ class BotUsers(): self.offline.remove(nick_id) return # Identify - nick_id = self.whois_id(trigger.nick) + nick_id = self.whois_ident(trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -111,7 +119,7 @@ class BotUsers(): if trigger.nick == bot.nick: return # Identify - nick_id = self.whois_id(trigger.nick) + nick_id = self.whois_ident(trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -138,7 +146,7 @@ class BotUsers(): self.offline.append(int(nick_id)) return # Identify - nick_id = self.whois_id(trigger.nick) + nick_id = self.whois_ident(trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -165,7 +173,7 @@ class BotUsers(): self.offline.append(int(nick_id)) return # Identify - nick_id = self.whois_id(targetnick) + nick_id = self.whois_ident(targetnick) # Verify nick is in the all list self.add_to_all(targetnick, nick_id) # Verify nick is in the all list @@ -187,7 +195,7 @@ class BotUsers(): if not botdb.check_nick_id(newnick): botdb.alias_nick(trigger.nick, newnick) # Identify - nick_id = self.whois_id(newnick) + nick_id = self.whois_ident(newnick) # Verify nick is in the all list self.add_to_all(newnick, nick_id) # Verify nick is in the all list From ff9ea7994cce2a4283ab8ba3114470c37c6ca54e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:45:00 -0400 Subject: [PATCH 32/33] get ID from nick --- sopel_modules/SpiceBot/Users.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index f034a53..a966491 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -32,6 +32,12 @@ class BotUsers(): else: return None + def whois_nick(self, nick): + nick_id = self.whois_ident(nick) + self.add_to_all(nick, nick_id) + self.add_to_current(nick, nick_id) + return nick_id + def whois_ident(self, nick): nick = Identifier(nick) nick_id = botdb.db.get_nick_id(nick, create=True) From 8ed9184d94d8b96a8d582d4effd553c6b3f00303 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 7 Jun 2019 20:49:51 -0400 Subject: [PATCH 33/33] inter --- sopel_modules/SpiceBot/Users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index a966491..18e8a54 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -27,7 +27,7 @@ class BotUsers(): def whois_id(self, nick_id): if nick_id in self.current.keys(): return self.current[nick_id]["nick"] - elif int(nick_id) in self.all.keys() and len(self.all[nick_id]): + elif nick_id in self.all.keys() and len(self.all[nick_id]): return self.all[nick_id][0] else: return None