This commit is contained in:
deathbybandaid 2019-07-01 10:51:40 -04:00
parent 403887e2e9
commit cc0ba58803
3 changed files with 10 additions and 15 deletions

View File

@ -20,18 +20,17 @@ class BotUsers():
def __init__(self): def __init__(self):
self.lock = threading.Lock() self.lock = threading.Lock()
# TODO AWAY
self.dict = { self.dict = {
"all": botdb.get_bot_value('users') or {}, "all": botdb.get_bot_value('users') or {},
"online": [], "online": [],
"offline": [], "offline": [],
"away": [], # TODO "away": [],
"current": {}, "current": {},
} }
"""during setup, all users from database are offline until marked online""" """during setup, all users from database are offline until marked online"""
for user_id in list(self.dict["all"].keys()): for user_id in list(self.dict["all"].keys()):
self.lock.acquire() self.mark_user_offline(user_id)
self.dict["offline"].append(int(user_id))
self.lock.release()
def __getattr__(self, name): def __getattr__(self, name):
''' will only get called for undefined attributes ''' ''' will only get called for undefined attributes '''
@ -42,20 +41,20 @@ class BotUsers():
raise Exception('User dict does not contain a function or key ' + str(name.lower())) raise Exception('User dict does not contain a function or key ' + str(name.lower()))
def ID(self, nickinput): def ID(self, nickinput):
self.lock.acquire()
if is_number(nickinput): if is_number(nickinput):
nick_id = nickinput nick_id = nickinput
if nick_id in list(self.dict["current"].keys()): self.lock.acquire()
nick = self.dict["current"][nick_id]["nick"] if int(nick_id) in list(self.dict["current"].keys()):
elif nick_id in list(self.dict["all"].keys()) and len(self.dict["all"][int(nick_id)]): nick = self.dict["current"][int(nick_id)]["nick"]
self.lock.release()
elif int(nick_id) in list(self.dict["all"].keys()) and len(self.dict["all"][int(nick_id)]):
nick = self.dict["all"][int(nick_id)][0] nick = self.dict["all"][int(nick_id)][0]
self.lock.release()
else: else:
raise Exception('ID ' + str(nickinput) + ' does not appear to be associated with a nick') raise Exception('ID ' + str(nickinput) + ' does not appear to be associated with a nick')
self.lock.release()
return nick return nick
else: else:
nick_id = self.whois_ident(nickinput) nick_id = self.whois_ident(nickinput)
self.lock.release()
return int(nick_id) return int(nick_id)
def whois_ident(self, nick, usercreate=True): def whois_ident(self, nick, usercreate=True):
@ -65,7 +64,7 @@ class BotUsers():
except Exception as e: except Exception as e:
nick_id = e nick_id = e
nick_id = None nick_id = None
if usercreate: if usercreate and nick_id:
self.add_to_all(nick, nick_id) self.add_to_all(nick, nick_id)
return int(nick_id) return int(nick_id)

View File

@ -140,7 +140,6 @@ def bot_channelscan(bot, trigger):
SpiceBot.channels.channel_scan(bot) SpiceBot.channels.channel_scan(bot)
"""
@sopel.module.event(SpiceBot.events.RPL_NAMREPLY) @sopel.module.event(SpiceBot.events.RPL_NAMREPLY)
@sopel.module.rule('(.*)') @sopel.module.rule('(.*)')
def handle_names(bot, trigger): def handle_names(bot, trigger):
@ -153,4 +152,3 @@ def handle_names(bot, trigger):
@sopel.module.unblockable @sopel.module.unblockable
def recv_who(bot, trigger): def recv_who(bot, trigger):
SpiceBot.channels.rpl_who(bot, trigger) SpiceBot.channels.rpl_who(bot, trigger)
"""

View File

@ -51,7 +51,6 @@ def bot_channelscan_users(bot, trigger):
SpiceBot.users.channel_scan(bot) SpiceBot.users.channel_scan(bot)
"""
@sopel.module.rule('.*') @sopel.module.rule('.*')
def bot_users_chat(bot, trigger): def bot_users_chat(bot, trigger):
SpiceBot.users.chat(bot, trigger) SpiceBot.users.chat(bot, trigger)
@ -81,4 +80,3 @@ def account_notify(bot, trigger):
@sopel.module.rule('.*') @sopel.module.rule('.*')
def track_notify(bot, trigger): def track_notify(bot, trigger):
SpiceBot.users.track_notify(bot, trigger) SpiceBot.users.track_notify(bot, trigger)
"""