def handler_acceptrep(cli, msg):
    if isauthed(str(msg.from_user.id)):
        if len(msg.command) == 2:
            tag = msg.command[1]
            chat = Redis.hget('reportedfrom:global', tag).decode('utf-8')
            user = get_user_name(
                Redis.hget('reportedby:global', tag).decode('utf-8'))
            bot.send_message(chat_id=chat, text=ntf_accepted.format(user, tag))
            rmsnippet(tag, bot_master)
            rmreport(tag)
    else:
        msg.reply('Insufficiant permission')
예제 #2
0
def rmsnippet(tag: str, user: str) -> None:
    """
	To remove a command into the database.
	Params:
	- `tag` : `str` , unique tag of the command to be removed
	- `user` : `str` , the user who takes the action, for verification use.

	Returns: `None`
	Raises:
	
	- `TagNotFound` if tag is not found.
	- `TagNotOwned` if tag is not owned by the user.
	"""
    if not tagexists(tag):
        raise TagNotFound

    if not isauthed(user, tag):
        raise TagNotOwned

    credit = Redis.hget(CRDT_GBL, tag).decode('utf-8')
    Redis.srem(TAGS_GBL, tag)
    Redis.hdel(CMDS_GBL, tag)
    Redis.hdel(DESC_GBL, tag)
    Redis.srem(CREATEDBY.format(credit), tag)
    Redis.hdel(CRDT_GBL, tag)
예제 #3
0
def getsnippet(tag: str) -> Snippet:
    """
	Get everything of the given tag, if exists.

	Returns: `list`
	- `[0]` : `str`, command snippet itself.
	- `[1]` : `str`, the description.
	- `[2]` : `str`, the credit.

	Raises: `TagNotFound` if the tag is not exist in the database.
	"""
    if not Redis.sismember(TAGS_GBL, tag):
        raise TagNotFound
    desc = Redis.hget(DESC_GBL, tag).decode('utf-8')
    command = Redis.hget(CMDS_GBL, tag).decode('utf-8')
    credit = Redis.hget(CRDT_GBL, tag).decode('utf-8')
    return (command, desc, credit)
예제 #4
0
def tagsingroup(group: str) -> List[Tags]:
    """
	Get all tags belongs to the group.

	Returns:

	- `['', []]` if the group is not exist, there's a chance that the group was emptied.
	- `[str, list[str]]` the first string is the description of the group, the latter is a list of the tags in the given group.

	Raises: None
	"""
    result = ['', []]
    res = Redis.smembers(f'taggroup:global:{group}')
    if res:
        result[0] = Redis.hget('g_description:global', group)
        for e in res:
            result[1].append(e.decode('utf-8'))

    return result
예제 #5
0
def get_user_name(ident: str) -> str:
    return Redis.hget('username', ident).decode('utf-8')