示例#1
0
        max_length (int, optional): 列表中存储的最大值,超过此值则会删除最早记录的id. Defaults to 20.
    """
    rc_ls: dict = recalled[gid]
    rc_ls[fake_id] = [message_id, passive, time]
    # 重新存储键值刷新字典排序
    if len(rc_ls) > max_length:
        reverse_keys = reversed(rc_ls)
        _tmp_dict = {}
        for k in reverse_keys:
            _tmp_dict[k] = rc_ls[k]
            _tmp_dict.popitem()
        recalled[gid] = _tmp_dict


recall_trigger = antirecall.on_notice(
    rule=sv_sw(plugin_name, plugin_usage, hierarchy='其它')
    & comman_rule(GroupRecallNoticeEvent))


@recall_trigger.handle()
async def got_recall(bot: Bot, event: GroupRecallNoticeEvent):
    while True:
        if (fake_id := randint(10, 999)) not in recalled[
                event.group_id]:  # 由于真实消息id过长并且有负数造成调用混淆所以使用伪id进行对应
            break
    passive = event.user_id != event.operator_id  # 主动撤回还是被管理撤回
    store_recall(event.group_id, fake_id, event.message_id, passive,
                 event.time)
    litigant_info = await bot.get_group_member_info(group_id=event.group_id,
                                                    user_id=event.user_id)
    litigant_name = litigant_info["card"] or litigant_info["nickname"] or str(
示例#2
0
    if not isinstance(event, GroupIncreaseNoticeEvent):
        return False
    logger.debug(f'Group {event.group_id} increase Got!!')
    logger.debug(isinstance(event, GroupIncreaseNoticeEvent))
    if event.user_id == event.self_id:
        return False
    logger.debug('非自身加群')
    gid = str(event.group_id)
    if gid in welcome_settings:
        if event.sub_type == 'approve' and len(welcome_settings[gid]['approve']) == 0:
            # or event.sub_type == 'invite' and len(welcome_settings[gid]['invite']) == 0:
            return False
    return True


entry_welcome = welcome.on_notice(rule=welcome_sw&welcome_rule)


@entry_welcome.handle()
async def welcome_newcomers(bot: Bot, event: GroupIncreaseNoticeEvent):
    gid = str(event.group_id)
    if gid not in welcome_settings:
        welcome_settings[gid] = DEFAULT_SPEECH
    settings = welcome_settings[gid]
    userinfo = await bot.get_group_member_info(group_id=event.group_id, user_id=event.user_id)
    name = userinfo['card'] or userinfo['nickname'] or str(event.user_id)
    # admininfo = await bot.get_group_member_info(group_id=event.group_id, user_id=event.operator_id)
    # admin = admininfo['card'] or admininfo['nickname'] or str(event.user_id)
    # msg = Message(choice(settings[event.sub_type]).format(name=name, admin=admin))
    msg = Message(choice(settings['approve']).format(name=name))
    await entry_welcome.finish(msg, at_sender=True)