Merge pull request #118 from deathbybandaid/development

Development
This commit is contained in:
Deathbybandaid 2019-09-18 14:30:38 -04:00 committed by GitHub
commit 72d982abbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 18 deletions

View File

@ -285,12 +285,21 @@ def trigger_runstatus_query(bot, trigger, botcom):
botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.")
return False
# Stop here if not registered
# Stop here if not registered or not identified
if bot.config.SpiceBot_regnick.regnick:
# not registered
if str(trigger.nick).lower() not in [x.lower() for x in botusers.dict["registered"]]:
message = "The query command requires you to be registerd with IRC services. Registering may take a few minutes to process with the bot."
message = "The " + str(botcom.dict["comtext"]) + " command requires you to be registered with IRC services. Registering may take a few minutes to process with the bot."
return trigger_cant_run(bot, trigger, botcom, message)
# registered nick, but not identified
else:
nick_id = botusers.whois_ident(trigger.nick)
if nick_id not in botusers.dict["identified"]:
message = "Your nickname appears to be registered with IRC services. However, you have not identified. Identifying may take a few minutes to process with the bot."
return trigger_cant_run(bot, trigger, botcom, message)
# don't run commands that are disabled in channels
if not trigger.is_privmsg:
channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender))
@ -342,12 +351,21 @@ def trigger_runstatus(bot, trigger, botcom):
botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.")
return False
# Stop here if not registered
# Stop here if not registered or not identified
if bot.config.SpiceBot_regnick.regnick:
# not registered
if str(trigger.nick).lower() not in [x.lower() for x in botusers.dict["registered"]]:
message = "The " + str(botcom.dict["comtext"]) + " command requires you to be registerd with IRC services. Registering may take a few minutes to process with the bot."
message = "The " + str(botcom.dict["comtext"]) + " command requires you to be registered with IRC services. Registering may take a few minutes to process with the bot."
return trigger_cant_run(bot, trigger, botcom, message)
# registered nick, but not identified
else:
nick_id = botusers.whois_ident(trigger.nick)
if nick_id not in botusers.dict["identified"]:
message = "Your nickname appears to be registered with IRC services. However, you have not identified. Identifying may take a few minutes to process with the bot."
return trigger_cant_run(bot, trigger, botcom, message)
# if botcom.dict["hyphen_arg"]:
# return False

View File

@ -30,11 +30,15 @@ class BotUsers():
"away": [],
"current": {},
"registered": botdb.get_bot_value('regged_users') or [],
"notregistered": {},
"register_check": {},
"identified": [],
}
"""during setup, all users from database are offline until marked online"""
for user_id in list(self.dict["all"].keys()):
self.mark_user_offline(user_id)
# for user_id in list(self.dict["all"].keys()):
# self.mark_user_offline(user_id)
self.lock.acquire()
self.dict["offline"] = list(self.dict["all"].keys())
self.lock.release()
def __getattr__(self, name):
''' will only get called for undefined attributes '''
@ -150,6 +154,7 @@ class BotUsers():
if int(nick_id) not in self.dict["offline"]:
self.dict["offline"].append(int(nick_id))
self.lock.release()
self.whois_identify_forget(nick_id)
def join(self, bot, trigger):
if trigger.nick == bot.nick:
@ -348,27 +353,47 @@ class BotUsers():
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):
nick_id = self.whois_ident(nick)
self.lock.acquire()
# identified
if int(nick_id) not in self.dict["identified"]:
self.dict["identified"].append(int(nick_id))
# registered
if str(nick).lower() not in [x.lower() for x in self.dict["registered"]]:
self.dict["registered"].append(str(nick))
else:
self.dict["notregistered"][str(nick).lower()] = time.time()
self.lock.release()
def whois_send(self, bot, nick):
if not bot.config.SpiceBot_regnick.regnick:
return
if str(nick).lower() in [x.lower() for x in list(self.dict["notregistered"].keys())]:
timestamp = self.dict["notregistered"][str(nick).lower()]
if time.time() - timestamp < 240:
return
if str(nick).lower() not in [x.lower() for x in self.dict["registered"]]:
check_whois = False
nick_id = self.whois_ident(nick)
# No registered check
if str(nick).lower() not in [x.lower() for x in list(self.dict["register_check"].keys())]:
check_whois = True
elif nick_id in self.dict["identified"]:
timestamp = self.dict["register_check"][str(nick).lower()]
if time.time() - timestamp >= 1800:
check_whois = True
else:
timestamp = self.dict["register_check"][str(nick).lower()]
if time.time() - timestamp >= 240:
check_whois = True
if check_whois:
bot.write(['WHOIS', str(nick)])
self.lock.acquire()
self.dict["register_check"][str(nick).lower()] = time.time()
self.lock.release()
def whois_identify_forget(self, nick_id):
self.lock.acquire()
if int(nick_id) in self.dict["identified"]:
self.dict["identified"].remove(int(nick_id))
self.lock.release()
def account(self, bot, trigger):
# Identify
@ -479,6 +504,7 @@ class BotUsers():
# if bot.config.SpiceBot_regnick.regnick:
# if str(target).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"}
# TODO identified
return targetgood

View File

@ -13,11 +13,17 @@ from sopel_modules.spicemanip import spicemanip
@sopel.module.nickname_commands('regnicks', 'regnick')
def nickname_comand_regnicks(bot, trigger, botcom):
reggedusers = SpiceBot.users.dict["registered"]
bot.osd("These users are registered " + spicemanip(reggedusers, 'andlist') + ".", trigger.nick, 'notice')
bot.osd(["These users are registered:", spicemanip(reggedusers, 'andlist')], trigger.nick, 'notice')
notregged = []
for user in SpiceBot.users.dict["online"]:
usernick = SpiceBot.users.ID(user)
if str(usernick).lower() not in [x.lower() for x in SpiceBot.users.dict["registered"]]:
if usernick != bot.nick:
notregged.append(usernick)
bot.osd("These online users are not registered " + spicemanip(notregged, 'andlist') + ".", trigger.nick, 'notice')
bot.osd(["These online users are not registered:", spicemanip(notregged, 'andlist')], trigger.nick, 'notice')
identusers = []
for user in SpiceBot.users.identified:
usernick = SpiceBot.users.ID(user)
identusers.append(str(usernick))
bot.osd(["These online users are identified:", spicemanip(identusers, 'andlist')], trigger.nick, 'notice')