mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +08:00
* 🎨 修改 nonebot_bison 目录位置 * auto fix by pre-commit hooks * 🚚 fix frontend build target * 🚚 use soft link * Revert "🚚 use soft link" This reverts commit de21f79d5ae1bd5515b04f42a4138cb25ddf3e62. * 🚚 modify dockerfile --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: felinae98 <731499577@qq.com>
27 lines
710 B
Python
27 lines
710 B
Python
import random
|
|
import string
|
|
from typing import Optional
|
|
|
|
from expiringdict import ExpiringDict
|
|
|
|
|
|
class TokenManager:
|
|
def __init__(self):
|
|
self.token_manager = ExpiringDict(max_len=100, max_age_seconds=60 * 10)
|
|
|
|
def get_user(self, token: str) -> Optional[tuple]:
|
|
res = self.token_manager.get(token)
|
|
assert res is None or isinstance(res, tuple)
|
|
return res
|
|
|
|
def save_user(self, token: str, qq: tuple) -> None:
|
|
self.token_manager[token] = qq
|
|
|
|
def get_user_token(self, qq: tuple) -> str:
|
|
token = "".join(random.choices(string.ascii_letters + string.digits, k=16))
|
|
self.save_user(token, qq)
|
|
return token
|
|
|
|
|
|
token_manager = TokenManager()
|