Ejemplo n.º 1
0
    """
    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(
        event.user_id)
Ejemplo n.º 2
0
            notifier: Bot = choice(ol_bots)
            try:
                for su in SUPERUSERS:
                    await notifier.send_private_msg(
                        user_id=su,
                        message=f' {bot.self_id}disconnected at {dc_time}')
                break
            except BaseException as err:
                logger.error(
                    f'Bot {notifier.self_id} failed to send offline notification: {err}'
                )
                ol_bots.remove(notifier)
        else:
            logger.error(f'All bots failed to send notification!')

    else:
        logger.critical('There is no bot can send notification!')


# 被踢提醒
kicked = on_notice(
    rule=comman_rule(GroupDecreaseNoticeEvent, sub_type="kick_me"))


@kicked.handle()
async def kicked_remind(bot: Bot, event: GroupDecreaseNoticeEvent):
    msg = f'被 {event.operator_id} 踢出群 {event.group_id}'
    logger.info(msg)
    for su in SUPERUSERS:
        await bot.send_private_msg(user_id=su, message=msg)
Ejemplo n.º 3
0
from nonebot import MatcherGroup
from nonebot_adapter_gocq.event import GroupRequestEvent
from nonebot.permission import SUPERUSER
from nonebot.rule import ArgumentParser
from nonebot_adapter_gocq.exception import ActionFailed

from src.common import Bot, MessageEvent, T_State, SUPERUSERS, logger
from src.common.rules import comman_rule

entry_and_exit = MatcherGroup()

entry_manager = entry_and_exit.on_request(
    rule=comman_rule(GroupRequestEvent, sub_type='invite'))


@entry_manager.handle()
async def entry_group(bot: Bot, event: GroupRequestEvent):
    if event.user_id in SUPERUSERS:
        try:
            await event.approve()
        except ActionFailed as err:
            logger.warning(err)
    else:
        await bot.set_group_add_request(flag=event.flag,
                                        sub_type=event.sub_type,
                                        approve=False,
                                        reason='请联系维护组申请群授权')
        for sp in SUPERUSERS:
            await bot.send_private_msg(
                user_id=sp,
                message=
Ejemplo n.º 4
0
from nonebot.plugin import on_request
from nonebot_adapter_gocq.event import FriendRequestEvent

from src.common import Bot, FRIENDREQUESTCODESALT, SUPERUSERS, logger
from src.common.rules import comman_rule
from src.common.levelsystem import UserLevel
from src.utils import get_hash_code

_plugin_name = '处理好友请求'

friend_request = on_request(rule=comman_rule(FriendRequestEvent))


@friend_request.handle()
async def virify_request(bot: Bot, event: FriendRequestEvent):
    pure_comment = event.comment.split('\n回答:')[1]
    if pure_comment == get_hash_code(
            FRIENDREQUESTCODESALT,
            event.get_user_id()) and UserLevel(event.user_id).level > 3:
        # await event.approve()  为啥这个不好使???
        await bot.set_friend_add_request(flag=event.flag, approve=True)
        logger.success(f'Approved friend request with user: {event.user_id}')
        for sps in SUPERUSERS:
            await bot.send_private_msg(
                user_id=sps, message=f'用户 {event.user_id} 通过了好友验证,已添加好友')
    else:
        logger.info(
            f'Wrong request-code, refuse to add friend with: {event.user_id}')
        await bot.set_friend_add_request(flag=event.flag, approve=False)
Ejemplo n.º 5
0
with configfile.open(encoding='utf-8') as j:
    prob_settings = json.load(j)


def record_settings(gid: str, prob: float):
    prob_settings[gid] = prob
    with configfile.open('w', encoding='utf-8') as j:
        json.dump(prob_settings, j, indent=4)


chatbot = MatcherGroup(type='message')

set_prob = chatbot.on_command('聊天触发率',
                              rule=sv_sw(plugin_name, plugin_usage)
                              & comman_rule(GroupMessageEvent),
                              priority=2)


@set_prob.handle()
async def recieve_arg(bot: Bot, event: GroupMessageEvent, state: T_State):
    arg = event.message.extract_plain_text().strip()
    if arg:
        state['prob'] = arg


@set_prob.got("prob", prompt='请输入聊天触发率,范围0-50,输入[退出]取消设置触发率')
async def prob_handle(bot: Bot, event: GroupMessageEvent, state: T_State):
    prob = state[
        "prob"] if "prob" in state else event.message.extract_plain_text(
        ).strip()
Ejemplo n.º 6
0
            #     '{admin}邀请{name}给大家展示女装姐妹丼啦,欸欸~米娜桑不要脱裤子啊(#°Д°)'
            #     ],
            'locked': False
            }  # 暂时没发现有条件能上报operator_id,所以invite就先不管了


def save_wl_settings():
    """保存群欢迎语句设置"""
    with welcome_settings_file.open('w', encoding='utf-8') as j:
        json.dump(welcome_settings, j, ensure_ascii=False, escape_forward_slashes=False, indent=4)


welcome = MatcherGroup()
welcome_sw = sv_sw(welcome_name, welcome_usage, hierarchy='群助手')

speech_editor = welcome.on_command('设置入群欢迎', rule=welcome_sw&comman_rule(GroupMessageEvent), priority=2)


@speech_editor.handle()
async def show_speech(bot: Bot, event: GroupMessageEvent, state: T_State):
    gid = str(event.group_id)
    if gid not in welcome_settings:
        wl_setting = DEFAULT_SPEECH
    else:
        wl_setting = welcome_settings[gid]
    ap_speeches = '\n'.join([f'{i+1}.{speech}' for i, speech in enumerate(wl_setting['approve'])])
    # in_speeches = '\n'.join([f'{i+1+len(wl_setting["approve"])}.{speech}' for i, speech in enumerate(wl_setting['invite'])])
    status = '已锁定' if wl_setting['locked'] else '未锁定'
    msg = '当前新人入群欢迎语句为:\n' + ap_speeches + '\n────────────\n可修改状态:' + status
    if wl_setting['locked'] and event.sender.role == 'member':
        await speech_editor.finish(Message(msg))