"""The privilege of user discribed in an `int` number.

`0` is for Default or NotSet. The other numbers may change in future versions.
"""
BLACK = -999
DEFAULT = 0
NORMAL = 1
PRIVATE = 10
ADMIN = 21
OWNER = 22
WHITE = 51
SUPERUSER = 999
SU =SUPERUSER
from datetime import datetime

import rin
from rin.typing import CQEvent

#===================== block list =======================#
_black_group = {}  # Dict[group_id, expr_time]
_black_user = {}  # Dict[user_id, expr_time]


def set_block_group(group_id, time):
    _black_group[group_id] = datetime.now() + time


def set_block_user(user_id, time):
    if user_id not in rin.config.SUPERUSERS:
        _black_user[user_id] = datetime.now() + time


def check_block_group(group_id):
    if group_id in _black_group and datetime.now() > _black_group[group_id]:
        del _black_group[group_id]  # 拉黑时间过期
        return False
    return bool(group_id in _black_group)


def check_block_user(user_id):
    if user_id in _black_user and datetime.now() > _black_user[user_id]:
        del _black_user[user_id]  # 拉黑时间过期
        return False
    return bool(user_id in _black_user)


#========================================================#


def get_user_priv(ev: CQEvent):
    uid = ev.user_id
    if uid in rin.config.SUPERUSERS:
        return SUPERUSER
    if check_block_user(uid):
        return BLACK
    # TODO: White list
    if ev['message_type'] == 'group':
        if not ev.anonymous:
            role = ev.sender.get('role')
            if role == 'member':
                return NORMAL
            elif role == 'admin':
                return ADMIN
            elif role == 'administrator':
                return ADMIN    # for cqhttpmirai
            elif role == 'owner':
                return OWNER
        return NORMAL
    if ev['message_type'] == 'private':
        return PRIVATE
    return NORMAL


def check_priv(ev: CQEvent, require: int) -> bool:
    if ev['message_type'] == 'group':
        return bool(get_user_priv(ev) >= require)
    else:
        return False  # 不允许私聊

"""The privilege of user discribed in an `int` number.

`0` is for Default or NotSet. The other numbers may change in future versions.
"""
BLACK = -999
DEFAULT = 0
NORMAL = 1
PRIVATE = 10
ADMIN = 21
OWNER = 22
WHITE = 51
SUPERUSER = 999
SU =SUPERUSER
from datetime import datetime

import rin
from rin.typing import CQEvent

#===================== block list =======================#
_black_group = {}  # Dict[group_id, expr_time]
_black_user = {}  # Dict[user_id, expr_time]


def set_block_group(group_id, time):
    _black_group[group_id] = datetime.now() + time


def set_block_user(user_id, time):
    if user_id not in rin.config.SUPERUSERS:
        _black_user[user_id] = datetime.now() + time


def check_block_group(group_id):
    if group_id in _black_group and datetime.now() > _black_group[group_id]:
        del _black_group[group_id]  # 拉黑时间过期
        return False
    return bool(group_id in _black_group)


def check_block_user(user_id):
    if user_id in _black_user and datetime.now() > _black_user[user_id]:
        del _black_user[user_id]  # 拉黑时间过期
        return False
    return bool(user_id in _black_user)


#========================================================#


def get_user_priv(ev: CQEvent):
    uid = ev.user_id
    if uid in rin.config.SUPERUSERS:
        return SUPERUSER
    if check_block_user(uid):
        return BLACK
    # TODO: White list
    if ev['message_type'] == 'group':
        if not ev.anonymous:
            role = ev.sender.get('role')
            if role == 'member':
                return NORMAL
            elif role == 'admin':
                return ADMIN
            elif role == 'administrator':
                return ADMIN    # for cqhttpmirai
            elif role == 'owner':
                return OWNER
        return NORMAL
    if ev['message_type'] == 'private':
        return PRIVATE
    return NORMAL


def check_priv(ev: CQEvent, require: int) -> bool:
    if ev['message_type'] == 'group':
        return bool(get_user_priv(ev) >= require)
    else:
        return False  # 不允许私聊

The privilege of user discribed in an `int` number.  `0` is for Default or NotSet. The other numbers may change in future versions. #===================== block list =======================# # Dict[group_id, expr_time] # Dict[user_id, expr_time] # 拉黑时间过期 # 拉黑时间过期 #========================================================# # TODO: White list # for cqhttpmirai # 不允许私聊