def decorator(func: Callable): matcher = on_keyword(set(keyword), **kwargs) @wraps(func) @self._pre_check(only_to_me=only_to_me) async def wrapper(bot: Bot, event: Event, state: T_State): await func(bot, event) logger.info( f'消息{event.get_session_id()}已被on_keyword处理器{func.__name__}处理。' ) await matcher.finish() return matcher.handle()(wrapper)
from nonebot.typing import T_State from nonebot.adapters.cqhttp import Message, Bot, Event # 这两个没用的别删 from nonebot.adapters.cqhttp.message import MessageSegment import requests from nonebot.permission import * from nonebot.rule import to_me # matcher = on_keyword({"主人"}) matcher = on_command('主人', rule=to_me(), priority=5) @matcher.handle() async def _(bot: Bot, event: Event, state: T_State): await matcher.send('我主人是川川大帅哥') test = on_keyword({"test"}) @test.handle() async def h_r(bot: Bot, event: Event, state: T_State): id = str(event.get_user_id()) # yuyin=f"[CQ:record,file=http://baidu.com/1.mp3]" # biaoqing=f"[CQ:face,id=123]"#表情包使用 # hongbao=f"[CQ:gift,qq={id},id=8]"#礼物使用 await test.send(MessageSegment.at(id) + '你好帅哥') test = on_keyword({"礼物", '我要礼物', '我也要礼物'}) # test=on_command('礼物',rule=to_me(),priority=5)
import requests from nonebot import on_command, on_startswith, on_keyword from nonebot.rule import to_me from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message import random #wyy = on_startswith("网抑", priority=3) wyy = on_keyword("网抑", priority=3) # 识别参数 并且给state 赋值 @wyy.handle() async def handle_first_receive(bot: Bot, event: Event, state: dict): tiangoudiary = await get_soil_sentence() await wyy.finish(tiangoudiary) async def get_soil_sentence(): url = 'https://v1.hitokoto.cn/' par = {"c": "j"} res = requests.get(url, params=par) result = res.json() content_s = result['hitokoto'] return content_s
await arcbot.finish() get_users = on_command('get_user_list', command('get_user_list')) @get_users.handle() async def _get_users(bot: Bot, event: Event, state: T_State): await bot.send(message=str(showuser()), event=event) await get_users.finish() setu = on_command('setu', command('setu')) setu_t = on_keyword(['哭', '枯', '难受', 'wsl']) proxy_url = 'api.ineko.cc/pixiv' async def fetch(target, client): return await client.get(target) @setu.handle() @setu_t.handle() async def _setu(bot: Bot, event: Event, state: T_State): try: async with httpx.AsyncClient() as client: r = await asyncio.gather(fetch('https://api.lolicon.app/setu/?apikey=986214496009b5f04da0c8&size1200=true&proxy=' + proxy_url, client)) except: await bot.send(message='超时了qwq', event=event)
from nonebot.adapters.cqhttp import Message from nonebot import on_keyword from nonebot.typing import T_State from nonebot.adapters import Bot, Event import requests, re yulu = on_keyword({'美女'}, priority=10) @yulu.handle() async def j(bot: Bot, event: Event, state: T_State): msg = await mei() await yulu.send(Message(msg)) async def mei(): url = 'https://api.66mz8.com/api/rand.img.php?type=美女&format=json' resp = requests.get(url) data = resp.json() ur = data.get('pic_url') tu = f"[CQ:image,file={ur}]" return tu
from nonebot import on_keyword from nonebot.rule import to_me, keyword from nonebot.adapters.cqhttp import Bot, Event from nonebot.typing import T_State from lib.nblib.helpers import render_expression as expr import lib.nblib.smartlib as e #示例代码段 hy_czj = on_keyword("荒野查询", rule=to_me(), priority=5, block=True) @hy_czj.handle() async def handle_first_receive(bot: Bot, event: Event, state: T_State): args = str(event.message).strip() # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海 if args: state["msg"] = args # 如果用户发送了参数则直接赋值 @hy_czj.got("msg", prompt="请告诉我你要查询的用户TAG号,仅限荒野国服(⊙o⊙)哦") async def handle_msg(bot: Bot, event: Event, state: T_State): msg = state["msg"] import re try: re_msg = re.search('[A-Za-z0-9]+', msg).group() except AttributeError: await hy_czj.reject('您的TAG似乎不对,再试试吧', at_sender=True) else: #if msg not in ["上海", "北京"]: # await hy_czj.reject("你想查询的城市暂不支持,请重新输入!") async def hy_cx(tag: str): import subprocess req = subprocess.getoutput(
__des__ = "缩写查询、梗百科" __cmd__ = """ 1. 百科 {keyword},来源为nbnhhsh、小鸡词典、百度百科 2. {keyword} 是啥/是什么,来源为nbnhhsh、小鸡词典 3. 缩写 {keyword},来源为nbnhhsh """.strip() __short_cmd__ = "xxx是啥、百科xxx、缩写xxx" __example__ = """ 缩写 xswl xswl 是啥 百科 洛天依 """.strip() __usage__ = f"{__des__}\nUsage:\n{__cmd__}\nExample:\n{__example__}" commands = {"是啥", "是什么", "是谁"} what = on_keyword(commands, priority=14) baike = on_command("baike", aliases={"what", "百科"}, block=True, priority=13) nbnhhsh = on_command("nbnhhsh", aliases={"缩写"}, block=True, priority=13) @what.handle() async def _(msg: str = EventPlainText(), to_me: bool = EventToMe()): def split_command(msg): for command in commands: if command in msg: prefix, suffix = re.split(command, msg) return prefix, suffix return "", "" msg = msg.strip().strip(".>,?!。,()()[]【】") prefix_words = ["这", "这个", "那", "那个", "你", "我", "他", "它"]
from nonebot import on_command, on_keyword # from nonebot.adapters import Bot,Event # from nonebot.rule import to_me from nonebot.typing import T_State from nonebot.adapters.cqhttp import Bot, Message, GroupMessageEvent test = on_keyword({'我帅不帅', '谁最帅'}) @test.handle() 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)
return ans explain = on_command("我要亲亲", aliases={'我要抱抱'}, priority=2) @explain.handle() async def explainsend(bot: Bot, event: Event, state: dict): if int(event.get_user_id()) != event.self_id: k = (random.randint(0, 10000) + random.randint(0, 10000)) % len(kiss) s = kiss[k] print('kiss总数目', len(kiss), '我要抱抱指令输出:', s) await bot.send(event=event, message=s, at_sender=True) st = on_keyword({'setu', '涩图', '色图', '每日一图'}, priority=2) @st.handle() async def st_(bot: Bot, event: Event, state: dict): if int(event.get_user_id()) != event.self_id: await bot.send(event=event, message=MessageSegment.image(get_setu())) R18 = on_keyword({'R18', 'r18'}, priority=2) @R18.handle() async def R18_(bot: Bot, event: Event, state: dict): if int(event.get_user_id()) != event.self_id: await bot.send(
exlpain = on_command("情感语录",aliases={'舔狗日记'} ,priority=2) @exlpain.handle() async def slove(bot: Bot, event: Event, state: dict): if int(event.get_user_id())!= event.self_id: str1='' if(random.randint(0,1)): str1=get_new2() else: str1=get_news() await bot.send( event=event, message=str1, at_sender=True ) qinghua = on_keyword("情话",priority=2) @qinghua.handle() async def qinghua_(bot:Bot,event:Event): if event.get_user_id != event.self_id: await bot.send( event=event, message=get_qinhua() ) lvcha= on_keyword("绿茶",priority=2) @lvcha.handle() async def lvcha_(bot:Bot,event:Event): if event.get_user_id != event.self_id: await bot.send( event=event, message=get_lvcha()
cmd4 = on_command('今晚到我房间来', priority=2) @cmd4.handle() async def cmd4_(bot: Bot, event: Event): if int(event.get_user_id()) != event.self_id: path_ = os.getcwd() path_ = path_ + '\yuyinbao\我已经躺床上了.mp3' mypath = 'file:///' + path_ print(mypath) sst = MessageSegment.record(file=str(mypath)) await bot.send(event=event, message=Message(sst)) #能做你女朋友吗 cmd5 = on_keyword(['单身'], priority=2) @cmd5.handle() async def cmd5_(bot: Bot, event: Event): if int(event.get_user_id()) != event.self_id: path_ = os.getcwd() path_ = path_ + '\yuyinbao\我能做你女朋友吗?.mp3' mypath = 'file:///' + path_ print(mypath) sst = MessageSegment.record(file=str(mypath)) await bot.send(event=event, message=Message(sst)) #哎呀好的啦 小哥哥不要生气了嘛 cmd6 = on_keyword(['生气', '气死我', '是遇得到', '服了', '醉了', '不高兴', '不开心', '好烦'],
from nonebot import on_keyword from nonebot.rule import to_me from nonebot.adapters.cqhttp import Bot, Event from nonebot.typing import T_State #import xxt.plugins.clashroyale.get_deta as gets from lib.nblib.helpers import render_expression as expr import lib.nblib.smartlib as e #示例代码段 cr_cbx = on_keyword("查宝箱", rule=to_me(), priority=4, block=True) @cr_cbx.handle() async def handle_first_receive(bot: Bot, event: Event, state: T_State): args = str(event.get_message()).replace(' ', '') args = str(event.get_message()).replace( '\n', '') # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海 if args != '查宝箱': await cr_cbx.send(args, at_sender=True) import re try: bdzh = re.search('@[1-9]+', args).group() except AttributeError: try: re_msg = re.search('[A-Za-z0-9]+', args).group() except AttributeError: await cr_cbx.reject('您的TAG似乎不对,再试试吧', at_sender=True) except: await cr_cbx.finish('出现了一些未知的错误,请稍后再试试吧', at_sender=True) else: if re_msg != '': state["msg"] = re_msg # 如果用户发送了参数则直接赋值
from nonebot import on_keyword from nonebot.adapters import Bot, Event from nonebot.rule import to_me from nonebot.typing import T_State from .dialog_data import * from .utils import * dialog_xiabian = on_keyword(set('瞎编'), rule=to_me(), priority=6) @dialog_xiabian.handle() async def dialog_xiabian_handle(bot: Bot, event: Event, state: T_State): await dialog_xiabian.finish(random_reply(dialog_xiabian_data))
elif '来张acg' in msg: state['img_type'] = 'acg' elif '来张写真' in msg: state['img_type'] = 'photo' else: bg_call = type_rex.search(msg) if bg_call: state['img_type'] = 'bg' state['pc'] = bg_call.group('method') state['lx'] = bg_call.group('lx') else: return False return True rand_img = on_keyword({'来张', '一张'}, rule=sv_sw('杂图', '啊这..不好解释', '其它') & call_img, priority=2) msc_img_lmt = FuncLimiter(func_name='杂图', cd_rel=150, cost=3, max_free=1, only_group=False) @rand_img.handle() @msc_img_lmt.inventory() @msc_img_lmt.limit_verify(cding='下一发图片{left_time}秒后装填好~', overdraft='你只剩{left_fund}块钱了,要不考虑援交一下赚点钱?') async def send_others(bot: Bot, event: MessageEvent, state: T_State): # msg = MessageSegment.reply(id_=event.message_id) if event.message_type == 'group' else MessageSegment.text('') if state['img_type'] == 'meizi': call = get_nmb(False) elif state['img_type'] == 'photo': call = get_pw(False) elif state['img_type'] == 'bg': if state['lx'] in ('acg', '小姐姐', '风景', '随机'): lx = state['lx'].replace('acg', 'dongman').replace('小姐姐', 'meizi').replace('风景', 'fengjing').replace('随机', 'suiji')
#Nonebot2基础模块 from nonebot import on_keyword from nonebot.rule import to_me from nonebot.adapters.cqhttp import Bot, Event from nonebot.typing import T_State yhbd = on_keyword("绑定账号", rule=to_me(), priority=5, block=True) @yhbd.handle() async def handle_first_receive(bot: Bot, event: Event, state: T_State): args = str(event.message).strip() # 原始信息 if args: # 过滤可用信息 import re try: tag = re.search('[A-Za-z0-9]+', args).group() except AttributeError: await cr_cbx.reject('您的TAG似乎不对,再试试吧', at_sender=True) else: import pymysql import xxt.setting as xs conn = pymysql.connect(**xs.yyk) cursor = conn.cursor() lists = cursor.execute( f'SELECT * FROM `xiasweet` WHERE `tag` = "{tag}" and `qid`={event.user_id}' ) if lists == 0: state["tag"] = tag.upper() state["qid"] = event.user_id else: lists = cursor.fetchall() if lists[0][3] == 'bs':
# coding=utf-8 """ 作者:川川 时间:2021/8/2 """ from nonebot import on_keyword from nonebot.typing import T_State from nonebot.adapters.cqhttp import Message, Bot, Event # 这两个没用的别删 from nonebot.permission import * from aiocqhttp.exceptions import Error as CQHttpError import requests ao=on_keyword({'奥运'}) @ao.handle() async def j(bot: Bot, event: Event, state: T_State): # bot = nonebot.get_bot() msg = await ji() try: await ao.send(message=Message(msg)) except CQHttpError: pass async def ji(): url = 'https://api.cntv.cn/olympic/getOlyMedals' params = { 'serviceId': 'pcocean', 'itemcode': 'GEN-------------------------------', } json = requests.get(url, params=params).json()