当前位置:网站首页>【nonebot2】几个简单的机器人模块(一言+彩虹屁+每日60s)
【nonebot2】几个简单的机器人模块(一言+彩虹屁+每日60s)
2022-07-27 08:39:00 【Tokeii】
里面有两种请求api 方法,一种普通的使用requests,一种使用的aiohttp
import base64
from nonebot import Bot, on_command
from nonebot.rule import to_me
from nonebot.matcher import Matcher
from nonebot.params import Arg, CommandArg, ArgPlainText
from nonebot.adapters.onebot.v11 import Message
import json
import requests
import aiohttp
import asyncio
import base64
hitokoto1 = on_command('一言',priority=5)
@hitokoto1.handle()
async def hitokoto_(bot: Bot, args: Message = CommandArg()):
url = 'https://v1.hitokoto.cn/'
r = requests.get(url)
data = json.loads(r.text)
hitokoto_ = data.get('hitokoto')
from_ = data.get('from')
from_who = data.get('from_who')
message_=hitokoto_+'\nFrom:'+str(from_)+'('+str(from_who)+')'
await hitokoto1.send(message_)
caihongpi = on_command('彩虹屁',priority=5)
@caihongpi.handle()
async def caihongpi_(bot: Bot, args: Message = CommandArg()):
shadiao = await get_shadiao()
await caihongpi.send(shadiao)
day60 = on_command('60s',priority=5)
@day60.handle()
async def day60_(bot: Bot, args: Message = CommandArg()):
url = 'https://api.qqsuu.cn/api/60s'
await day60.send('正在获取,请稍等...')
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
text = await resp.content.read()
#text转为base64
picbase = base64.b64encode(text).decode()
await day60.finish(Message(f"[CQ:image,file=base64://{
picbase}]"))
async def get_shadiao():
url = 'https://api.shadiao.app/chp'
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
text = await resp.text()
#json
data = json.loads(text)
return data['data']['text']
边栏推荐
- How to upload qiniu cloud
- Background order management
- Minio 安装与使用
- Software test interview questions (key points)
- while Loop
- Day3 -- flag state holding, exception handling and request hook
- Make a game by yourself with pyGame 01
- 缓存一致性与内存屏障
- JWT authentication and login function implementation, exit login
- After downloading URL loader and specifying the size of the image with limit, the image will not be displayed
猜你喜欢

VS Code中#include报错(新建的头文件)
![[MRCTF2020]PYWebsite 1](/img/d4/2d9cd06abd7188add668cde77d3075.png)
[MRCTF2020]PYWebsite 1

Login to homepage function implementation

Realization of background channel group management function
![[NPUCTF2020]ReadlezPHP 1](/img/d9/590446b45f917be3f077a9ea739c20.png)
[NPUCTF2020]ReadlezPHP 1

“寻源到结算“与“采购到付款“两者有什么不同或相似之处?

Forced login, seven cattle cloud upload pictures

低成本、低门槛、易部署,4800+万户中小企业数字化转型新选择

How to view instances of software objects in QSIM?

Flink1.15源码阅读flink-clients客户端执行流程(阅读较枯燥)
随机推荐
Alibaba cloud international receipt message introduction and configuration process
Solution to the program design of the sequence structure of one book (Chapter 1)
Minio 安装与使用
Eval and assert execute one sentence Trojan horse
[penetration test tool sharing] [dnslog server building guidance]
Use of flask
VS Code中#include报错(新建的头文件)
Pass parameters and returned responses of flask
海量数据肖枫:共建共治openGauss根社区,共享欣欣向荣新生态
低成本、低门槛、易部署,4800+万户中小企业数字化转型新选择
The following license SolidWorks Standard cannot be obtained, and the use license file cannot be found. (-1,359,2)。
Day4 --- flask blueprint and rest ful
Initial summary of flask framework creation project
How to permanently set source
3311. Longest arithmetic
Map structure
Cookie addition, deletion, modification and exception
Cache consistency and memory barrier
Minio installation and use
List删除集合元素