Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/core/utils.py

47 lines
1.9 KiB
Python
Raw Normal View History

2021-04-28 12:21:33 +00:00
import os
2021-04-27 15:01:17 +00:00
import re
2021-02-06 16:30:13 +00:00
import aiohttp
2021-04-27 15:01:17 +00:00
from core.elements import Target
from core.template import sendMessage
from graia.application.message.chain import MessageChain
from graia.application.message.elements.internal import Image, Plain
2021-02-06 16:30:13 +00:00
2021-04-28 12:21:33 +00:00
async def load_prompt():
authorcache = os.path.abspath('.cache_restart_author')
loadercache = os.path.abspath('.cache_loader')
if os.path.exists(authorcache):
import json
from core.template import sendMessage
openauthorcache = open(authorcache, 'r')
cachejson = json.loads(openauthorcache.read())
openloadercache = open(loadercache, 'r')
await sendMessage(cachejson, openloadercache.read(), Quote=False)
openloadercache.close()
openauthorcache.close()
os.remove(authorcache)
os.remove(loadercache)
2021-02-11 12:41:07 +00:00
async def get_url(url: str, headers=None):
2021-02-06 16:30:13 +00:00
async with aiohttp.ClientSession() as session:
2021-02-11 12:41:07 +00:00
async with session.get(url, timeout=aiohttp.ClientTimeout(total=20), headers=headers) as req:
2021-02-06 16:30:13 +00:00
text = await req.text()
return text
2021-04-27 15:01:17 +00:00
async def getsetu(kwargs):
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(60)) as session:
qqavatarbase = 'https://ptlogin2.qq.com/getface?appid=1006102&imgtype=3&uin=' + str(kwargs[Target].senderId)
async with session.get(qqavatarbase) as qlink:
try:
qqavatarlink = re.match(r'pt.setHeader\({".*?":"(https://thirdqq.qlogo.cn/.*)"}\)',
await qlink.text())
qqavatarlink = qqavatarlink.group(1)
except Exception:
qqavatarlink = False
if qqavatarlink:
await sendMessage(kwargs, MessageChain.create([Plain(f'↓╰♡╮極мī鏈接,速嚸╭♡╯↓\n{qqavatarlink}')]))
await sendMessage(kwargs, MessageChain.create([Image.fromNetworkAddress(qqavatarlink)]), Quote=False)