Exemplo n.º 1
0
async def remove_boss_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent,
                              state: typing.T_State):
    #   Request valid confirmation for deletion
    while True:
        if str(event.get_message()).strip(
        ) not in InteractionMessage.CONFIRMATION_MESSAGE:
            await remove_boss.reject(InteractionMessage.INVALID_ARG)
        else:
            break

    user_confirm = str(event.get_message()).strip()
    if user_confirm.startswith(InteractionMessage.CONFIRMATION_MESSAGE[1]):
        #   Do not delete
        await remove_boss.finish(message=InteractionMessage.RECORD_CHANGE_ABORT
                                 )
    else:
        remove_result = await boss_database.remove(state['boss_id'])
        if remove_result['status'] != DBStatusCode.DELETE_SUCCESS:
            if bot.config.debug:
                await bot.send_private_msg(user_id=plugin_config.AUTHOR,
                                           message=str(remove_result['error']))
            await remove_boss.finish('\n'.join([
                InteractionMessage.RECORD_CHANGE_FAIL,
                InteractionMessage.ERROR_MESSAGE
            ]))
        else:
            await remove_boss.finish(
                message=InteractionMessage.RECORD_CHANGE_SUCCESS)
Exemplo n.º 2
0
async def update_boss_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent,
                              state: typing.T_State):
    #   Request valid confirmation for update
    while True:
        if str(event.get_message()).strip(
        ) not in InteractionMessage.CONFIRMATION_MESSAGE:
            await update_boss.reject(InteractionMessage.INVALID_ARG)
        else:
            break

    user_confirm = str(event.get_message()).strip()
    if user_confirm.startswith(InteractionMessage.CONFIRMATION_MESSAGE[1]):
        #   Do not update
        await update_boss.finish(message=InteractionMessage.RECORD_CHANGE_ABORT
                                 )
    else:
        new_info = {
            'id': int(str(state['new_info'][0]).strip()),
            'alias': str(state['new_info'][1]).strip(),
            'health': int(str(state['new_info'][2]).strip())
        }
        update_result = await boss_database.update(new_info)

        if update_result['status'] != DBStatusCode.UPDATE_SUCCESS:
            if bot.config.debug:
                await bot.send_private_msg(user_id=plugin_config.AUTHOR,
                                           message=str(update_result['error']))
            await update_boss.finish('\n'.join([
                InteractionMessage.RECORD_CHANGE_FAIL,
                InteractionMessage.ERROR_MESSAGE
            ]))
        else:
            await update_boss.finish(
                message=InteractionMessage.RECORD_CHANGE_SUCCESS)
Exemplo n.º 3
0
async def _(bot: Bot, event: GroupMessageEvent):
    tem = str(event.get_message())
    qid = re.findall(r"\d+", tem)[0]
    print(qid)
    if event.get_user_id() in nonebot.get_driver().config.superusers:
        try:
            mid = readJson()[qid][1]
        except Exception as e:
            print(e)
            await withdraw.finish('只能撤回他最后一次涩图')
            return
        await bot.delete_msg(message_id=mid)
    else:
        await withdraw.finish('你没有权利撤回哦')
Exemplo n.º 4
0
async def remove_record_handler(bot: cqhttp.Bot,
                                event: cqhttp.GroupMessageEvent,
                                state: typing.T_State):
    raw_args = str(event.get_message()).strip()
    arg_list = list(map(str.strip, raw_args.split(plugin_config.separator)))

    if len(arg_list) != 3:
        #   Not enough arguments have been provided
        await add_record.finish(InteractionMessage.INVALID_ARG_NUMBER)

    remove_identifiers = {
        'member_id': arg_list[0],
        'boss_id': arg_list[1],
        'damage': arg_list[2]
    }

    remove_result = await record_database.remove(remove_identifiers)
    if remove_result['status'] == DBStatusCode.DELETE_SUCCESS:
        await remove_record.finish(InteractionMessage.RECORD_CHANGE_SUCCESS)
    else:
        if bot.config.debug:
            await bot.send_private_msg(user_id=plugin_config.AUTHOR,
                                       message=str(remove_result['error']))

        await remove_record.finish('\n'.join([
            InteractionMessage.RECORD_CHANGE_FAIL,
            InteractionMessage.ERROR_MESSAGE
        ]))
Exemplo n.º 5
0
async def update_boss_first_receive(bot: cqhttp.Bot,
                                    event: cqhttp.GroupMessageEvent,
                                    state: typing.T_State):
    raw_args = str(event.get_message()).strip()
    if raw_args:
        arg_list = raw_args.split(plugin_config.separator)
        state['new_info'] = arg_list
Exemplo n.º 6
0
async def search_boss_first_receive(bot: cqhttp.Bot,
                                    event: cqhttp.GroupMessageEvent,
                                    state: typing.T_State):
    raw_message = event.get_message()
    arg_list, prior_id = None, None

    if len(raw_message) != 0:
        for segment in raw_message:
            if segment['type'] == 'at':
                #   checking for @message and extract qq_id from it as member_id
                prior_id = segment['data']['qq']
            else:
                arg_list = list(
                    map(
                        lambda x: str(x).strip(),
                        str(segment['data']['text']).strip().split(
                            plugin_config.separator)))

                if len(arg_list) < 1 or len(arg_list) > 2:
                    await add_team.finish(InteractionMessage.INVALID_ARG)
                elif len(arg_list) == 2:
                    state['team_id'] = arg_list[1]

        state['member_id'] = arg_list[0]

    state['member_id'] = prior_id if (prior_id is not None) else (state.get(
        'member_id', event.user_id))
Exemplo n.º 7
0
async def handle_short(bot: Bot, event: GroupMessageEvent, state: T_State):
    group = state["_matched_dict"]
    number = int(group["number"])
    full_name = get_group_bind_repo(str(event.group_id))
    if not full_name:
        await issue_short.finish("此群尚未与仓库绑定!")
        return
    match = re.match(REPO_REGEX, full_name)
    if not match:
        await issue_short.finish("绑定的仓库名不合法!请重新尝试绑定~")
    owner = match.group("owner")
    repo = match.group("repo")

    token = None
    if get_user_token:
        token = get_user_token(event.get_user_id())
    try:
        issue_ = await get_issue(owner, repo, number, token)
    except HTTPStatusError:
        await issue.finish(f"Issue #{number} not found for repo {owner}/{repo}"
                           )
        return
    img = await issue_to_image(issue_)
    if img:
        await send_github_message(
            issue_short, owner, repo, number,
            MessageSegment.image(f"base64://{base64.b64encode(img).decode()}"))
Exemplo n.º 8
0
async def _(bot: Bot, event: GroupMessageEvent):
    global cd
    if str(event.group_id) not in cd:
        cd[str(event.group_id)] = int(time.time())
    ## 初始化cd

    if cd[str(event.group_id)] <= int(time.time()):
        keyword = event.get_message().__str__().strip()
        response = requests.get(
            "https://api.lolicon.app/setu/?apikey={0}&r18={1}&keyword={2}&num={3}&proxy=i.pixiv.cat&size1200=false"
            .format("698604975f3623bd7ed1d0", "2", keyword, 3))
        data = json.loads(response.text)
        if data["code"] == 0:
            cd[str(event.group_id)] = int(time.time()) + 60
            quota = data["quota"]
            if keyword == "":
                await setu.send("正在获取涩图,今日剩余可调用 {0} 次".format(quota))
            else:
                await setu.send("正在获取 [{0}] 涩图,今日剩余可调用 {1} 次".format(
                    keyword, quota))
            for i in data["data"]:
                content = "\n标题: {0} (PID: {1})".format(i["title"], i["pid"])
                content += "\n作者: {0} (UID: {1})".format(i["author"], i["uid"])
                try:
                    await setu.send(MessageSegment.image(i["url"]) + content)
                except Exception as e:
                    print(e)
        elif data["code"] == 404:
            await setu.send("没有符合条件的涩图")
        else:
            await setu.send("获取失败")
    else:
        await setu.finish(
            Message(f"CD还剩 {cd[str(event.group_id)] - int(time.time())} 秒,请节制")
        )
Exemplo n.º 9
0
async def _deal_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
    content = state["content"]
    group_id = event.group_id
    user_id = event.get_user_id()
    node = Funny().fake_msg(content)
    await bot.send_group_forward_msg(group_id=group_id, messages=node)

    _fake_flmt.start_cd(user_id)
    _fake_daliy_max.increase(user_id)
Exemplo n.º 10
0
async def _(bot: Bot, event: GroupMessageEvent):
    keyword = event.get_message().__str__().strip()
    global cp
    if keyword in keywords:
        keywords.remove(keyword)
        Save_Config()
        await disable_monitor.send("成功将关键词 [{0}] 移除监控列表".format(keyword))
    else:
        await disable_monitor.send("关键词 [{0}] 不在监控列表,无效操作".format(keyword))
Exemplo n.º 11
0
async def _(bot: Bot, event: GroupMessageEvent):
    keyword = event.get_message().__str__().strip()
    print(keyword)
    global cp
    if keyword in keywords:
        await enable_monitor.send("关键词 [{0}] 已在监控列表, 请勿重复操作".format(keyword))
    else:
        keywords.append(keyword)
        Save_Config()
        await enable_monitor.send("成功将关键词 [{0}] 添加到监控列表".format(keyword))
Exemplo n.º 12
0
async def _ready_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
    user_id = event.get_user_id()
    if not _fake_daliy_max.check(user_id):
        await fake_msg.finish(_fake_max_notice)
    if not _fake_flmt.check(user_id):
        await fake_msg.finish(_fake_flmt_notice)

    msg = str(event.message).strip()
    if msg:
        state["content"] = msg
Exemplo n.º 13
0
async def _(bot: Bot, event: GroupMessageEvent):
    tem = str(event.get_message())
    qid = re.findall(r"\d+", tem)[0]

    try:
        mid = readJson()[qid][1]
    except Exception as e:
        print(e)
        await withdraw.finish(message=Message('只能撤回他最后一次涩图'))
        return
    await bot.delete_msg(message_id=mid)
Exemplo n.º 14
0
async def delete_msg_handle(bot: Bot, event: GroupMessageEvent):
    '''
    撤回违规消息,在data_source中修改违禁词列表
    '''
    msg_id = event.message_id
    msg = event.get_plaintext()
    for i in forbidden_word:
        if i in msg:
            await bot.call_api("delete_msg", **{'message_id': msg_id})
            await bot.send(event, f"在消息{msg_id}发现违禁词,已排除")
            break
Exemplo n.º 15
0
async def _(bot: Bot, event: GroupMessageEvent):
    msg: Message = event.get_message()
    for item in msg:
        if item.type == 'text':
            group_id = str(event.group_id)
            with open(f'/var/www/chat_data/{group_id}_chat.log', 'a+') as file:
                if not await redis_client.exists(group_id):
                    await redis_client.set(group_id, True)
                    file.write("\n")
                file.write(f"{item.data.get('text')}\n")
                await redis_client.expire(group_id, 60)
Exemplo n.º 16
0
async def _(bot: Bot, event: GroupMessageEvent):
    msg: MessageSegment = event.get_message().pop()
    if msg.type == "image":
        async with httpx.AsyncClient() as client:
            image = await client.get(msg.data['url'])
            im = Image.open(io.BytesIO(image.content))
            pre: List[Dict[str, float]] = predict(im)
            if not pre:
                return
            elif pre[0]["score"] > 0.9:
                await recognition.finish(f" 一定是 {pre[0]['name']} 拉")
                return
            elif pre[0]["score"] > 0.7:
                await recognition.finish(f"我猜是 {pre[0]['name']} ")
Exemplo n.º 17
0
async def _(bot: Bot, event: GroupMessageEvent):
    group_id = event.group_id
    user_id = event.user_id
    time = event.time
    nickname = event.sender.nickname
    message = event.get_plaintext().strip()
    result = handle_logger(
        group_id=group_id,
        user_id=user_id,
        time=time,
        nickname=nickname,
        message=message,
    )
    if result:
        await bot.send(event, result)
Exemplo n.º 18
0
async def _(bot: Bot, event: GroupMessageEvent):
    group_id = event.group_id
    user_id = event.user_id
    time = event.time
    nickname = event.sender.nickname
    message = event.get_plaintext().strip()
    await bot.send(
        event,
        handle_command(
            group_id=group_id,
            user_id=user_id,
            time=time,
            nickname=nickname,
            message=message,
        ),
    )
Exemplo n.º 19
0
async def add_team_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent,
                           state: typing.T_State):
    while True:
        action = str(event.get_message()).strip()
        if action == 'confirm':
            if not state['team_list']:
                await add_team.reject(prompt=InteractionMessage.NOT_ENOUGH_TEAM
                                      )
            else:
                break
        elif action == 'abort':
            await add_team.finish(InteractionMessage.RECORD_CHANGE_ABORT)
        else:
            card = action.split(plugin_config.separator)
            if len(card) != 2:
                await add_team.reject(
                    prompt=InteractionMessage.INVALID_ARG_NUMBER)
            else:
                state['team_list'].append(card[0])
                state['us_list'].append(card[1])
                await add_team.reject(
                    prompt=InteractionMessage.REPEATE_ADD_TEAM_CARD)

    team_info = {
        'member_id': state['member_id'],
        'team_id': state['team_id'],
        'team_list': ','.join(state['team_list']),
        'us_list': ','.join(state['us_list'])
    }
    print(team_info)

    add_result = await ds.tc.add(team_info)
    print(add_result)
    if add_result['error'] is None:
        await add_team.finish(InteractionMessage.RECORD_CHANGE_SUCCESS)
    else:
        if bot.config.debug:
            await bot.send_private_msg(user_id=plugin_config.AUTHOR,
                                       message=add_result['func_info'])
            await bot.send_private_msg(user_id=plugin_config.AUTHOR,
                                       message=add_result['error'])
        await add_team.finish('\n'.join([
            InteractionMessage.RECORD_CHANGE_FAIL,
            InteractionMessage.ERROR_MESSAGE
        ]))
Exemplo n.º 20
0
async def add_record_first_receive(bot: cqhttp.Bot,
                                   event: cqhttp.GroupMessageEvent,
                                   state: typing.T_State):
    raw_args = str(event.get_message()).strip()
    arg_list = list(map(str.strip, raw_args.split(plugin_config.separator)))

    if len(arg_list) < 4 or len(arg_list) > 7:
        #   Not enough arguments have been provided
        await add_record.finish(InteractionMessage.INVALID_ARG_NUMBER)
    elif len(arg_list) > 4:
        #   turn, time, member_id might be provided
        for arg in arg_list[4:]:
            arg_check = _single_checker(arg)
            state[arg_check[0]] = arg_check[1]

    state['base_info'] = arg_list[0:4]
    state['turn'] = state.get('turn', plugin_config.default_revue_turn)
    state['time'] = state.get('time', int(time.time()))
    state['member_id'] = state.get('member_id', event.user_id)
Exemplo n.º 21
0
async def add_team_first_receive(bot: cqhttp.Bot,
                                 event: cqhttp.GroupMessageEvent,
                                 state: typing.T_State):
    raw_message = event.get_message()
    arg_list, prior_id = None, None

    if len(raw_message) != 0:
        for segment in raw_message:
            if segment['type'] == 'at':
                #   checking for @message and extract qq_id from it as member_id
                prior_id = segment['data']['qq']
            else:
                arg_list = list(
                    map(
                        lambda x: str(x).strip(),
                        str(segment['data']['text']).strip().split(
                            plugin_config.separator)))

                if len(arg_list) < 1 or len(arg_list) > 2:
                    await add_team.finish(InteractionMessage.INVALID_ARG)
                elif len(arg_list) == 2:
                    state['member_id'] = arg_list[1]
    else:
        await add_team.reject(prompt=InteractionMessage.REQUEST_ARG)

    state['member_id'] = prior_id if (prior_id is not None) else (state.get(
        'member_id', event.user_id))
    state['team_id'] = int(arg_list[0])

    #   check if there is already a team belongs to the given member
    team_existence = await ds.tc.search_team(state['member_id'],
                                             state['team_id'])
    if team_existence['response']['result']:
        await add_team.finish(InteractionMessage.RECORD_ALREADT_EXIST)
    else:
        state['team_list'] = []
        state['us_list'] = []
        await add_team.pause(prompt=InteractionMessage.REPEATE_ADD_TEAM_CARD)
Exemplo n.º 22
0
async def add_record_first_receive(bot: cqhttp.Bot,
                                   event: cqhttp.GroupMessageEvent,
                                   state: typing.T_State):
    raw_message = event.get_message()

    #   received arguments, parsing
    arg_list, prior_id = None, None
    for segment in raw_message:
        if segment['type'] == 'at':
            #   checking for @message and extract qq_id from it as member_id
            prior_id = segment['data']['qq']
        else:
            #   standard input arguments
            arg_list = list(
                map(
                    lambda x: str(x).strip(),
                    str(segment['data']['text']).strip().split(
                        plugin_config.separator)))

            if len(arg_list) < 4 or len(arg_list) > 7:
                await add_record.finish(InteractionMessage.INVALID_ARG)
            elif len(arg_list) > 4:
                #   turn, time, member_id might be provided
                for arg in arg_list:
                    arg_check = _single_checker(arg)
                    state[arg_check[0]] = arg_check[1]

    #   No arguments received
    if len(raw_message) == 0 or arg_list is None:
        await add_record.reject(prompt=InteractionMessage.REQUEST_ARG)

    #   all arguments should have been processed except the 4 basic ones
    #   base_info[0:4] should be corresponds to sequence, boss_id, team, damage
    state['base_info'] = arg_list[0:4]
    state['turn'] = state.get('turn', plugin_config.default_revue_turn)
    state['date_time'] = state.get('date_time', int(time.time()))
    state['member_id'] = prior_id if (prior_id is not None) else (state.get(
        'member_id', event.user_id))
Exemplo n.º 23
0
async def _(bot: Bot, event: GroupMessageEvent):
    global last_message
    message = str(event.get_message())
    # await bot.send(event, str(message))
    # await bot.send(event, str("CQ:image" in message and "url=" in message))
    if message == last_message:
        tem = "打断复读" + random.randint(1, 10) * '!'
        last_message = tem
        await block_repeat.finish(message=tem)
    elif "CQ:image" in message and "url=" in message and b64encode(requests.get(str(message)
                                                                                [str(message).find("url=")
                                                                                 + 4:-1]).content) \
            .decode() == last_message:
        tem = "打断复读" + random.randint(1, 10) * '!'
        last_message = tem
        await block_repeat.finish(message=tem)
    else:
        if "CQ:image" in message and "url=" in message:
            last_message = b64encode(
                requests.get(str(message)[str(message).find("url=") +
                                          4:-1]).content).decode()
        else:
            last_message = message
Exemplo n.º 24
0
async def remove_team_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent,
                              state: typing.T_State):
    raw_args = str(event.get_message()).strip()
    arg_list = list(map(str.strip, raw_args.split(plugin_config.separator)))

    remove_identifier = {'member_id': arg_list[0]}
    try:
        remove_identifier['team_id'] = int(arg_list[1])
    except ValueError:
        await remove_team.finish(InteractionMessage.INVALID_ARG)

    remove_result = await ds.tc.delete(**remove_identifier)
    if remove_result['error'] is None:
        await remove_team.finish(InteractionMessage.RECORD_CHANGE_SUCCESS)
    else:
        if bot.config.debug:
            await bot.send_private_msg(user_id=plugin_config.AUTHOR,
                                       message=remove_result['func_info'])
            await bot.send_private_msg(user_id=plugin_config.AUTHOR,
                                       message=remove_result['error'])
        await remove_team.finish('\n'.join([
            InteractionMessage.RECORD_CHANGE_FAIL,
            InteractionMessage.ERROR_MESSAGE
        ]))
Exemplo n.º 25
0
async def process_arg(bot: Bot, event: GroupMessageEvent, state: T_State):
    arg = event.get_plaintext().strip()
    if arg:
        state["full_name"] = arg
Exemplo n.º 26
0
async def update_boss_parser(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent,
                             state: typing.T_State):
    state[state['_current_key']] = str(event.get_message()).strip().split(
        plugin_config.separator)
Exemplo n.º 27
0
async def remove_boss_first_receive(bot: cqhttp.Bot,
                                    event: cqhttp.GroupMessageEvent,
                                    state: typing.T_State):
    raw_args = str(event.get_message()).strip()
    if raw_args:
        state['boss_id'] = int(raw_args)
Exemplo n.º 28
0
async def remove_boss_parser(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent,
                             state: typing.T_State):
    state[state['_current_key']] = int(str(event.get_message()).strip())
Exemplo n.º 29
0
async def h_r(bot: Bot, event: GroupMessageEvent, state: T_State):
    id_ = event.get_user_id()
    at_ = "[CQ:at,qq={}]".format(id_)
    msg = at_ + '你最帅,帅的一批'
    msg = Message(msg)
    await test.finish(msg)
Exemplo n.º 30
0
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
    state["at"] = MessageSegment.at(event.get_user_id())
    state["test"] = "test"
    # message: /template {at} hello {test}!
    ft = event.message.template(event.message)
    await template.send(ft)