nonebot 机器人插件 - 妹子
1 import time 2 3 from nonebot import on_command 4 from nonebot.rule import to_me 5 from nonebot.typing import T_State 6 from nonebot.adapters import Bot, Event 7 8 from nonebot.adapters.cqhttp.message import Message 9 10 import random 11 import httpx 12 import json 13 import time 14 15 huangtu = on_command('huangtu', aliases={'妹子', '涩图'}, priority=5) 16 17 18 @huangtu.handle() 19 async def huangtu_gogo(bot: Bot, event: Event, state: T_State): 20 args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/妹子 1,则args1 21 22 if not args: 23 await send_meizi(1) 24 else: 25 if int(args) > 10: 26 await huangtu.send(Message('超过数量限制')) 27 else: 28 await send_meizi(int(args)) 29 30 31 async def send_meizi(quantity: int): 32 data_api = 'https://robot.datapi.cn/robots/meizi/' 33 request_data = httpx.get(data_api) 34 response = json.loads(request_data.text) 35 response_result = response['result'] 36 response_list = response_result['list'] 37 38 if quantity > 1: 39 for index in range(0, quantity): 40 await huangtu.send(Message('[CQ:image,file=' + random.choice(response_list) + ',id=40000]')) 41 else: 42 await huangtu.send(Message('[CQ:image,file=' + random.choice(response_list) + ',id=40000]'))
本文来自博客园,作者:我就丶是逗比,转载请注明原文链接:https://www.cnblogs.com/lonewolfyx/articles/15352731.html