sedi-relay/viera/authreqs.py

73 lines
1.4 KiB
Python
Raw Normal View History

2018-08-11 01:36:24 +00:00
import uuid
import logging
from collections import namedtuple
from .database import DATABASE
PendingAuth = namedtuple('PendingAuth', ['irc_nickname', 'irc_account', 'actor'])
AUTHS = DATABASE.get('auths', {})
DATABASE["auths"] = AUTHS
PENDING_AUTHS = {}
IRC_BOT = None
def check_reqs(chunks, actor):
global DATABASE
results = [x in PENDING_AUTHS for x in chunks]
logging.debug('AUTHREQ: chunks: %r, results: %r', chunks, results)
if True in results:
pending_slot = results.index(True)
pending_uuid = chunks[pending_slot]
req = PENDING_AUTHS.pop(pending_uuid)._replace(actor=actor["id"])
logging.debug("IRC BOT: %r, AUTHREQ: %r", IRC_BOT, req)
if IRC_BOT:
IRC_BOT.handle_auth_req(req)
DATABASE["auths"][req.irc_account] = req.actor
return True in results
2018-08-11 01:36:24 +00:00
def new_auth_req(irc_nickname, irc_account):
authid = str(uuid.uuid4())
PENDING_AUTHS[authid] = PendingAuth(irc_nickname, irc_account, None)
return authid
# XXX - utter hackjob
2018-08-11 01:36:24 +00:00
def set_irc_bot(bot):
global IRC_BOT
IRC_BOT = bot
logging.debug("SET IRC BOT TO: %r", bot)
def get_irc_bot():
global IRC_BOT
return IRC_BOT
2018-08-11 01:36:24 +00:00
def check_auth(account):
return account in DATABASE["auths"]
def fetch_auth(account):
if check_auth(account):
return DATABASE["auths"][account]
return None
2018-08-11 15:27:04 +00:00
def drop_auth(account):
DATABASE["auths"].pop(account, None)