mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 15:09:54 -05:00
commit
57393a4209
@ -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)
|
||||||
|
|
||||||
|
|||||||
@ -137,8 +137,7 @@ def channels_users_mode(bot, trigger):
|
|||||||
@sopel.module.event(SpiceBot.events.BOT_CONNECTED)
|
@sopel.module.event(SpiceBot.events.BOT_CONNECTED)
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_channelscan(bot, trigger):
|
def bot_channelscan(bot, trigger):
|
||||||
while True:
|
SpiceBot.channels.channel_scan(bot)
|
||||||
SpiceBot.channels.channel_scan(bot)
|
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(SpiceBot.events.RPL_NAMREPLY)
|
@sopel.module.event(SpiceBot.events.RPL_NAMREPLY)
|
||||||
|
|||||||
@ -31,7 +31,10 @@ def bot_events_connected(bot, trigger):
|
|||||||
if len(SpiceBot.events.dict["trigger_queue"]):
|
if len(SpiceBot.events.dict["trigger_queue"]):
|
||||||
pretriggerdict = SpiceBot.events.dict["trigger_queue"][0]
|
pretriggerdict = SpiceBot.events.dict["trigger_queue"][0]
|
||||||
SpiceBot.events.dispatch(bot, pretriggerdict)
|
SpiceBot.events.dispatch(bot, pretriggerdict)
|
||||||
del SpiceBot.events.dict["trigger_queue"][0]
|
try:
|
||||||
|
del SpiceBot.events.dict["trigger_queue"][0]
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(SpiceBot.events.BOT_WELCOME)
|
@sopel.module.event(SpiceBot.events.BOT_WELCOME)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user