From 017cc48d95e44eda6f99ebb1748653f8ce445ec6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 17 Sep 2019 16:23:22 -0400 Subject: [PATCH] check if nicks are regged --- sopel_modules/SpiceBot/Events.py | 1 + sopel_modules/SpiceBot/Users.py | 43 +++++++++++++++++++ sopel_modules/SpiceBot/configure.py | 2 +- .../SpiceBot_Core_Processing/Users.py | 6 +++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Events.py b/sopel_modules/SpiceBot/Events.py index a795e92..8024bef 100644 --- a/sopel_modules/SpiceBot/Events.py +++ b/sopel_modules/SpiceBot/Events.py @@ -39,6 +39,7 @@ class BotEvents(object): self.RPL_ISUPPORT = '005' # This is a defined IRC event self.RPL_WHOREPLY = '352' # This is a defined IRC event self.RPL_NAMREPLY = '353' # This is a defined IRC event + self.RPL_WHOISREGNICK = '307' # this is an unrealircd event self.BOT_UPTIME = time.time() self.BOT_WELCOME = '1001' self.BOT_READY = '1002' diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index e944b4f..b55487b 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -28,6 +28,7 @@ class BotUsers(): "offline": [], "away": [], "current": {}, + "registered": [], } """during setup, all users from database are offline until marked online""" for user_id in list(self.dict["all"].keys()): @@ -163,6 +164,8 @@ class BotUsers(): return # Identify nick_id = self.whois_ident(trigger.nick) + # check if nick is registered + self.whois_send(bot, trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -179,6 +182,8 @@ class BotUsers(): return # Identify nick_id = self.whois_ident(trigger.nick) + # check if nick is registered + self.whois_send(bot, trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -195,6 +200,8 @@ class BotUsers(): return # Identify nick_id = self.whois_ident(trigger.nick) + # check if nick is registered + self.whois_send(bot, trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -213,6 +220,8 @@ class BotUsers(): return # Identify nick_id = self.whois_ident(trigger.nick) + # check if nick is registered + self.whois_send(bot, trigger.nick) # Verify nick is in the all list self.add_to_all(trigger.nick, nick_id) # Verify nick is in the all list @@ -232,6 +241,8 @@ class BotUsers(): return # Identify nick_id = self.whois_ident(targetnick) + # check if nick is registered + self.whois_send(bot, targetnick) # Verify nick is in the all list self.add_to_all(targetnick, nick_id) # Verify nick is in the all list @@ -247,6 +258,8 @@ class BotUsers(): newnick = Identifier(trigger) if oldnick == bot.nick or newnick == bot.nick: return + # check if nick is registered + self.whois_send(bot, newnick) # Verify nick is in the all list self.add_to_all(oldnick, old_nick_id) # Verify nick is in the all list @@ -297,6 +310,8 @@ class BotUsers(): self.add_channel(channel, nick_id) # mark user as online self.mark_user_online(nick_id) + # check if nick is registered + self.whois_send(bot, nick) def rpl_who(self, bot, trigger): if len(trigger.args) < 2 or trigger.args[1] not in self.who_reqs: @@ -319,6 +334,28 @@ class BotUsers(): self.add_channel(channel, nick_id) # mark user as online self.mark_user_online(nick_id) + # check if nick is registered + self.whois_send(bot, nick) + + def rpl_whois(self, bot, trigger): + if not bot.config.SpiceBot_regnick.regnick: + return + nick = trigger.args[1] + if str(nick).lower() in [x.lower() for x in self.dict["registered"]]: + return + self.whois_handle(nick) + + def whois_handle(self, nick): + self.lock.acquire() + if str(nick).lower() in [x.lower() for x in self.dict["registered"]]: + self.dict["registered"].append(str(nick)) + self.lock.release() + + def whois_send(self, bot, nick): + if not bot.config.SpiceBot_regnick.regnick: + return + if str(nick).lower() not in [x.lower() for x in self.dict["registered"]]: + bot.write(['WHOIS', str(nick)]) def account(self, bot, trigger): # Identify @@ -423,6 +460,12 @@ class BotUsers(): if str(trigger.sender).lower() not in self.dict["current"][nick_id]["channels"]: return {"targetgood": False, "error": "It looks like " + self.nick_actual(target) + " is online right now, but in a different channel.", "reason": "diffchannel"} + # not a registered nick + if "unregged" not in targetbypass: + if bot.config.SpiceBot_regnick.regnick: + if str(nick).lower() not in [x.lower() for x in self.dict["registered"]]: + return {"targetgood": False, "error": "It looks like " + self.nick_actual(target) + " is not a registered nick.", "reason": "unregged"} + return targetgood def random_valid_target(self, bot, trigger, outputtype): diff --git a/sopel_modules/SpiceBot/configure.py b/sopel_modules/SpiceBot/configure.py index 40db92e..1358c01 100644 --- a/sopel_modules/SpiceBot/configure.py +++ b/sopel_modules/SpiceBot/configure.py @@ -65,4 +65,4 @@ def configure(config): config.SpiceBot_Sherlock.configure_setting('extra', 'SpiceBot_Sherlock API Extra directory') config.define_section("SpiceBot_regnick", SpiceBot_RegNicks_MainSection, validate=False) - config.SpiceBot_Channels.configure_setting('regnick', 'SpiceBot_Channels Announce New Channels') + config.SpiceBot_Channels.configure_setting('regnick', 'SpiceBot_regnick Only allow regged nicks') diff --git a/sopel_modules/SpiceBot_Core_Processing/Users.py b/sopel_modules/SpiceBot_Core_Processing/Users.py index 07a7009..eee2e70 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Users.py +++ b/sopel_modules/SpiceBot_Core_Processing/Users.py @@ -80,3 +80,9 @@ def account_notify_users(bot, trigger): @sopel.module.rule('.*') def track_notify_users(bot, trigger): SpiceBot.users.track_notify(bot, trigger) + + +@sopel.module.event(SpiceBot.events.RPL_WHOISREGNICK) +@sopel.module.rule('.*') +def bot_whois_user(bot, trigger): + SpiceBot.users.rpl_whois(bot, trigger)