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)