当前位置:网站首页>[nonebot2] several simple robot modules (Yiyan + rainbow fart + 60s per day)
[nonebot2] several simple robot modules (Yiyan + rainbow fart + 60s per day)
2022-07-27 08:42:00 【Tokeii】
There are two kinds of requests api Method , A common use requests, A kind of used 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(' A word ',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(' Rainbow fart ',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(' Getting , One moment please ...')
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
text = await resp.content.read()
#text To 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']
边栏推荐
- P7 Day1 get to know the flask framework
- [penetration test tool sharing] [dnslog server building guidance]
- 数智革新
- JS advanced knowledge - function
- Element display mode: block level, inline, inline block, nesting specification, display mode conversion
- Include error in vs Code (new header file)
- 693. Travel sequencing
- 4279. 笛卡尔树
- 4275. Dijkstra sequence
- 说透缓存一致性与内存屏障
猜你喜欢

UVM入门实验1

Zhongang Mining: the new energy industry is developing rapidly, and fluorine chemical products have a strong momentum

Fluent rendering mechanism - GPU thread rendering

Explain cache consistency and memory barrier

4279. 笛卡尔树

借生态力量,openGauss突破性能瓶颈

众昂矿业:新能源行业快速发展,氟化工产品势头强劲

NIO示例

带宽 与 货币

User management - restrictions
随机推荐
691. 立方体IV
OSI seven layer model and tcp/ip four layer (TCP and UDP) (notes)
Is online account opening safe? Want to know how securities companies get preferential accounts?
“寻源到结算“与“采购到付款“两者有什么不同或相似之处?
Background order management
Arm system call exception assembly
Flutter 渲染机制——GPU线程渲染
4275. Dijkstra sequence
Day5 - Flame restful request response and Sqlalchemy Foundation
JS rotation chart
NIO示例
4278. Summit
Flask request data acquisition and response
借生态力量,openGauss突破性能瓶颈
MCDF顶层验证方案
Login to homepage function implementation
Linear list (sequential storage, chain storage) (linked list of leading nodes, linked list of non leading nodes)
Initial summary of flask framework creation project
Cache consistency and memory barrier
Flask one to many database creation, basic addition, deletion, modification and query