🥳 ping 包含缓存(加速读取)、支持 pixiv 插画查询(暂只支持显示第一张图)
This commit is contained in:
parent
a3aa7d8b05
commit
fdbfffb0c3
@ -1,11 +1,12 @@
|
||||
""" Pagermaid plugin base. """
|
||||
import json, requests
|
||||
import json, requests, re
|
||||
from googletrans import Translator
|
||||
from urllib.parse import urlparse
|
||||
from pagermaid import bot, log
|
||||
from pagermaid.listener import listener, config
|
||||
from pagermaid.utils import clear_emojis, obtain_message
|
||||
from telethon.tl.types import ChannelParticipantsAdmins
|
||||
from os import remove
|
||||
|
||||
|
||||
@listener(outgoing=True, command="guess",
|
||||
@ -219,4 +220,104 @@ async def ipping(context):
|
||||
return True
|
||||
await context.edit('没有找到要查询的 ip/域名 ...')
|
||||
except:
|
||||
await context.edit('没有找到要查询的 ip/域名 ...')
|
||||
await context.edit('没有找到要查询的 ip/域名 ...')
|
||||
|
||||
|
||||
@listener(outgoing=True, command="pixiv",
|
||||
description="查询插画信息(现仅支持第一张图)")
|
||||
async def pixiv(context):
|
||||
reply = await context.get_reply_message()
|
||||
await context.edit('正在查询中...')
|
||||
try:
|
||||
if reply:
|
||||
for num in range(0, len(reply.entities)):
|
||||
url = reply.message[reply.entities[num].offset:reply.entities[num].offset + reply.entities[num].length]
|
||||
url = urlparse(url)
|
||||
try:
|
||||
url = str(re.findall(r"\d+\.?\d*", url.path)[0])
|
||||
pixiv_json = json.loads(requests.get(
|
||||
"https://api.imjad.cn/pixiv/v2/?type=illust&id=" + url).content.decode(
|
||||
"utf-8"))
|
||||
except:
|
||||
await context.edit('呜呜呜出错了...可能是链接不上 API 服务器')
|
||||
try:
|
||||
pixiv_tag = pixiv_json['error']['user_message']
|
||||
await context.edit('没有找到要查询的 pixiv 作品...')
|
||||
return True
|
||||
except:
|
||||
pixiv_tag = []
|
||||
if str(len(pixiv_json['illust']['meta_pages'])) == '0':
|
||||
pixiv_num = str(
|
||||
len(pixiv_json['illust']['meta_pages']) + 1)
|
||||
else:
|
||||
pixiv_num = str(
|
||||
len(pixiv_json['illust']['meta_pages']))
|
||||
pixiv_list = '[' + pixiv_json['illust']['title'] + '](https://www.pixiv.net/artworks/' + str(
|
||||
pixiv_json['illust']['id']) + ')' + ' (1/' + pixiv_num + ')'
|
||||
for nums in range(0, len(pixiv_json['illust']['tags'])):
|
||||
pixiv_tag.extend(['#' + pixiv_json['illust']['tags'][nums]['name']])
|
||||
try:
|
||||
await context.edit('正在下载图片中 ...')
|
||||
try:
|
||||
r = requests.get('https://daidr.me/imageProxy/?url=' +
|
||||
pixiv_json['illust']['meta_single_page']['original_image_url'])
|
||||
except:
|
||||
r = requests.get('https://daidr.me/imageProxy/?url=' +
|
||||
pixiv_json['illust']['meta_pages'][0]['image_urls']['original'])
|
||||
with open("pixiv.jpg", "wb") as code:
|
||||
code.write(r.content)
|
||||
await context.edit('正在上传图片中 ...')
|
||||
await context.client.send_file(context.chat_id, 'pixiv.jpg',
|
||||
caption=pixiv_list + '\nTags: ' + ' , '.join(pixiv_tag),
|
||||
reply_to=reply.id)
|
||||
await context.delete()
|
||||
remove('pixiv.jpg')
|
||||
except:
|
||||
pass
|
||||
return True
|
||||
else:
|
||||
url = urlparse(context.arguments)
|
||||
try:
|
||||
url = str(re.findall(r"\d+\.?\d*", url.path)[0])
|
||||
pixiv_json = json.loads(requests.get(
|
||||
"https://api.imjad.cn/pixiv/v2/?type=illust&id=" + url).content.decode(
|
||||
"utf-8"))
|
||||
except:
|
||||
await context.edit('呜呜呜出错了...可能是链接不上 API 服务器')
|
||||
try:
|
||||
pixiv_tag = pixiv_json['error']['user_message']
|
||||
await context.edit('没有找到要查询的 pixiv 作品...')
|
||||
return True
|
||||
except:
|
||||
pixiv_tag = []
|
||||
if str(len(pixiv_json['illust']['meta_pages'])) == '0':
|
||||
pixiv_num = str(
|
||||
len(pixiv_json['illust']['meta_pages']) + 1)
|
||||
else:
|
||||
pixiv_num = str(
|
||||
len(pixiv_json['illust']['meta_pages']))
|
||||
pixiv_list = '[' + pixiv_json['illust']['title'] + '](https://www.pixiv.net/artworks/' + str(
|
||||
pixiv_json['illust']['id']) + ')' + ' (1/' + pixiv_num + ')'
|
||||
for nums in range(0, len(pixiv_json['illust']['tags'])):
|
||||
pixiv_tag.extend(['#' + pixiv_json['illust']['tags'][nums]['name']])
|
||||
try:
|
||||
await context.edit('正在下载图片中 ...')
|
||||
try:
|
||||
r = requests.get('https://daidr.me/imageProxy/?url=' +
|
||||
pixiv_json['illust']['meta_single_page']['original_image_url'])
|
||||
except:
|
||||
r = requests.get('https://daidr.me/imageProxy/?url=' +
|
||||
pixiv_json['illust']['meta_pages'][0]['image_urls']['original'])
|
||||
with open("pixiv.jpg", "wb") as code:
|
||||
code.write(r.content)
|
||||
await context.edit('正在上传图片中 ...')
|
||||
await context.client.send_file(context.chat_id, 'pixiv.jpg',
|
||||
caption=pixiv_list + '\nTags: ' + ' , '.join(pixiv_tag))
|
||||
await context.delete()
|
||||
remove('pixiv.jpg')
|
||||
except:
|
||||
pass
|
||||
return True
|
||||
await context.edit('没有找到要查询的 pixiv 作品 ...')
|
||||
except:
|
||||
await context.edit('没有找到要查询的 pixiv 作品 ...')
|
Loading…
Reference in New Issue
Block a user