def on_request(self, only_group: bool = True, **kwargs) -> "matcher_wrapper": rule = self.check_service(0, only_group) priority = kwargs.get('priority', 1) mw = matcher_wrapper(self, 'Request', priority, only_group=only_group) self.matchers.append(str(mw)) mw.load_matcher(on_request(rule, **kwargs)) _loaded_matchers[mw.matcher] = mw return mw
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)
command_test = on_keyword({"帮助"}) @command_test.handle() async def _echo(bot: Bot, event: MessageEvent): if event.get_plaintext()!='帮助': return text =help_str await bot.send(event,text,at_sender=True) def NewFriendRequestEventRule(bot: Bot, event: Event, state: T_State): return isinstance(event, NewFriendRequestEvent) new_friend = on_request(NewFriendRequestEventRule) @new_friend.handle() async def _(bot: Bot, event: NewFriendRequestEvent, state: T_State): await event.approve(bot) time.sleep(1) text='见到你我很高兴\n输入帮助即可尽情玩弄机器人哦QaQ' await bot.send_friend_message(event.from_id,text) def BotJoinGroupEventRule(bot: Bot, event: Event, state: T_State): return isinstance(event, BotJoinGroupEvent) join_group = on_notice(BotJoinGroupEventRule) @join_group.handle() async def _(bot: Bot, event: BotJoinGroupEvent, state: T_State):
from nonebot.adapters.cqhttp.event import (FriendRequestEvent, GroupBanNoticeEvent, GroupDecreaseNoticeEvent, GroupIncreaseNoticeEvent, LuckyKingNotifyEvent) from nonebot.plugin import on_notice, on_request, require WelcomePath = os.path.join(os.getcwd(), 'DataBase', 'Json', 'studylib.json') with open(WelcomePath, 'r', encoding="utf-8") as fr: handle_new_member = json.load( fr)['public']['preinstall_words']['handle_new_member'] scheduler = require('nonebot_plugin_apscheduler').scheduler # 定义计划任务 member_var = on_notice(priority=5, rule=check_white_list_group()) ban_members = on_notice(priority=5, rule=check_white_list_group()) lucky_king = on_notice(priority=5, rule=check_white_list_group()) friend_add = on_request(priority=5) gaokao_time = datetime.datetime(datetime.datetime.now().year, 6, 7) @member_var.handle() # 群成员变化检测 迎新 退群通告 async def _change_menbers(bot: Bot, event): if isinstance(event, GroupIncreaseNoticeEvent): # 增加 WelcomeTence = random.choice(handle_new_member) msg = Message(f'[CQ:at,qq={str(event.user_id)}]\n' f'{WelcomeTence}\n' '我只是个无情的机器人,请通过#help查看帮助\n' '顺带一提,年轻人要学会控制自己的欲望~~~') await member_var.finish(msg) elif isinstance(event, GroupDecreaseNoticeEvent): # 减少 if event.operator_id == event.user_id: out_time = datetime.datetime.now()
# -*- coding = utf-8 -*- from nonebot import plugin from nonebot.adapters import Bot, Event request_event = plugin.on_request(priority=20) @request_event.handle() async def deal_request_event(bot: Bot, event: Event): event_name = event.get_event_name() if event_name == 'request.friend': imfor = event.get_event_description().split("'") flag = imfor[-2].replace("'", "") await bot.set_friend_add_request(flag=flag, approve=False) elif event_name == 'request.group.invite': imfor = event.get_event_description().split("'") flag = imfor[-2].replace("'", "") sub_type = imfor[15].replace("'", "") await bot.set_group_add_request(flag=flag, sub_type=sub_type, approve=True) elif event_name == 'request.group.add': imfor = event.get_event_description().split("'") flag = imfor[-2].replace("'", "") sub_type = imfor[15].replace("'", "") await bot.set_group_add_request(flag=flag, sub_type=sub_type, approve=True) await request_event.finish()
from nonebot.plugin import on_request from nonebot.adapters.cqhttp import GroupRequestEvent from salmon import Bot, configs group_request = on_request() @group_request.handle() async def handle_group_invite(bot: Bot, event: GroupRequestEvent): if event.sub_type == 'invite': if event.user_id not in configs.SUPERUSERS: await group_request.reject(reason='邀请入群请联系维护组') else: await group_request.approve() elif event.sub_type == 'add': cfg = configs.groupmaster.join_approve gid = event.group_id if gid not in cfg: return for k in cfg[gid].get('keywords', []): if k in event.comment: await group_request.approve() return if cfg[gid].get('reject_when_not_match', False): await group_request.reject() return
from nonebot.plugin import on_request from nonebot.adapters import Event, Bot from nonebot.rule import to_me from nonebot.typing import T_State from nonebot.adapters.cqhttp import Bot, Message import nonebot, asyncio, pymysql cljq = on_request(priority=1, block=True) @cljq.handle() async def cljq(bot: Bot, event: Event, state: T_State): post_type = event.post_type # 获取请求-------------上报类型 flag = event.flag if post_type == 'request': request_type = event.request_type # 请求类型 if request_type == 'group': # 处理加群请求 sub_type = event.sub_type # 子类型(主动或者邀请) if sub_type == 'add': # 主动主动申请 userid = event.user_id # 申请入群的QQ号 groupid = event.group_id # 群号 comment = event.comment # 验证信息 state = sqlyz(userid) if state: print('已同意') await bot.set_group_add_request(approve=True, flag=flag, sub_type=sub_type) else: print('已拒绝')
f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]') elif event.user_id == int(event.self_id): await groupEvent.finish("在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w") if event.raw_event['notice_type'] == 'group_decrease': if event.user_id != int(event.self_id): await groupEvent.finish(f'[{event.user_id}] 离开了我们...') elif event.user_id == int(event.self_id): for sup in master: await bot.send_private_msg( user_id=sup, message=f'呜呜呜,主人,咱被群[{event.group_id}]扔出来了...') # 处理 加好友 / 拉群 事件 selfEvent = on_request(rule=check_banlist()) FRIEND_ADD = 0 GROUP_INVITE = 0 @selfEvent.handle() async def _(bot: Bot, event: Event, state: dict) -> None: print(event.raw_event) flag = event.raw_event['flag'] req_type = event.raw_event['request_type'] if req_type == 'friend': for sup in master: msg0 = '主人,收到一条好友请求:\n' msg0 += f"请求人:{event.raw_event['user_id']}\n" msg0 += f"申请信息:{event.raw_event['comment']}\n"
from nonebot.adapters.mirai.event import Event, NewFriendRequestEvent, BotInvitedJoinGroupRequestEvent from .config import Config from .data_source import data_source from .help_text import HelpText global_config = nonebot.get_driver().config plugin_config = Config(**global_config.dict()) async def check_request(bot: Bot, event: Event, state: T_State) -> bool: return isinstance(event, (NewFriendRequestEvent, BotInvitedJoinGroupRequestEvent)) request = on_request(rule=check_request, priority=100) admin = on_command("admin", priority=10, permission=SUPERUSER) @admin.handle() async def handle_admin_receive(bot: Bot, event: Event, state: T_State): args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海 if args: state["command"] = args # 如果用户发送了参数则直接赋值 else: state["command"] = "help" @admin.got("command") async def handle_admin(bot: Bot, event: Event, state: T_State): command = state["command"].split(" ")
import pytz import asyncio from datetime import datetime from nonebot.plugin import on_notice, on_request from nonebot.adapters.cqhttp import GroupRequestEvent, GroupIncreaseNoticeEvent import salmon from salmon import Bot, configs from salmon.modules.authMS import util from salmon.modules.authMS.constant import config, group_dict, trial_list tz = pytz.timezone('Asia/Shanghai') group_more_request = on_request() group_50_notice = on_notice() @group_more_request.handle() async def handle_group_invite(bot: Bot, event: GroupRequestEvent): ''' 自动处理入群邀请 适用于50人以上的邀请的情况, 50人以下请参见下一条函数 ''' if not config.ENABLE_AUTH: # 配置ENABLE_AUTH为0, 则授权系统不起作用, 不会自动通过加群邀请 return if event.sub_type == 'invite': gid = event.group_id new_group_auth = await util.new_group_check(gid) if event.user_id not in configs.SUPERUSERS: if new_group_auth == 'expired' or new_group_auth == 'no trial': await bot.set_group_add_request(flag=event.flag,
from nonebot.adapters.cqhttp.bot import Bot from nonebot.adapters.cqhttp.event import FriendAddNoticeEvent from nonebot.plugin import on_request from nonebot.adapters.cqhttp import FriendRequestEvent import salmon from salmon import Bot from salmon.modules.authMS import util from salmon.modules.authMS.constant import config friend_request = on_request() @friend_request.handle() async def friend_approve(bot: Bot, event: FriendRequestEvent): if config.FRIEND_APPROVE: util.log(f'已自动接受来自{event.user_id}的好友请求', 'friend_add') salmon.logger.info(f'已自动接受来自{event.user_id}的好友请求') await bot.set_friend_add_request(flag=event.flag, approve=True) else: util.log(f'收到来自{event.user_id}的好友请求', 'friend_add') salmon.logger.info(f'收到来自{event.user_id}的好友请求')