mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-25 18:35:26 +00:00
vip 支持通过官方源获取图片
This commit is contained in:
parent
f62c60db95
commit
985834295c
@ -342,7 +342,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "vip",
|
"name": "vip",
|
||||||
"version": "0.40",
|
"version": "0.41",
|
||||||
"section": "chat",
|
"section": "chat",
|
||||||
"maintainer": "xtaodada",
|
"maintainer": "xtaodada",
|
||||||
"size": "4.0 kb",
|
"size": "4.0 kb",
|
||||||
|
43
vip.py
43
vip.py
@ -3,11 +3,19 @@ import io
|
|||||||
from requests import get
|
from requests import get
|
||||||
from os import remove
|
from os import remove
|
||||||
from telethon.tl.types import MessageMediaPhoto
|
from telethon.tl.types import MessageMediaPhoto
|
||||||
from pagermaid import bot
|
from pagermaid import bot, redis, redis_status
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import obtain_message, alias_command
|
from pagermaid.utils import obtain_message, alias_command
|
||||||
|
|
||||||
|
|
||||||
|
p_headers = {
|
||||||
|
"Referer": 'https://www.pixiv.net',
|
||||||
|
'User-Agent':
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 '
|
||||||
|
'Safari/537.36',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=True, outgoing=True, command=alias_command("duckduckgo"),
|
@listener(is_plugin=True, outgoing=True, command=alias_command("duckduckgo"),
|
||||||
description="Duckduckgo 搜索",
|
description="Duckduckgo 搜索",
|
||||||
parameters="<query>")
|
parameters="<query>")
|
||||||
@ -63,10 +71,37 @@ async def weather(context):
|
|||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=True, outgoing=True, command=alias_command("pixiv"),
|
@listener(is_plugin=True, outgoing=True, command=alias_command("pixiv"),
|
||||||
description="查询插画信息 (或者回复一条消息)",
|
description="查询插画信息 (或者回复一条消息)。使用 set [num] 更改镜像源,序号 2 为官方源。",
|
||||||
parameters="[<图片链接>] <图片序号>")
|
parameters="[<图片链接>] <图片序号>")
|
||||||
async def pixiv(context):
|
async def pixiv(context):
|
||||||
await context.edit("获取中 . . .")
|
await context.edit("获取中 . . .")
|
||||||
|
if len(context.parameter) == 2:
|
||||||
|
if context.parameter[0] == 'set':
|
||||||
|
if not redis_status:
|
||||||
|
await context.edit('redis 数据库离线 无法更改镜像源。')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
num = int(context.parameter[1])
|
||||||
|
except ValueError:
|
||||||
|
await context.edit('镜像源序号错误。')
|
||||||
|
return
|
||||||
|
if 0 < num < 3:
|
||||||
|
redis.set("pixiv_num", num)
|
||||||
|
await context.edit('镜像源已更改。')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
await context.edit('镜像源序号错误。')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
if not redis_status:
|
||||||
|
num = 1
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
num = int(redis.get("pixiv_num").decode())
|
||||||
|
except AttributeError:
|
||||||
|
num = 1
|
||||||
try:
|
try:
|
||||||
message = await obtain_message(context)
|
message = await obtain_message(context)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -77,6 +112,8 @@ async def pixiv(context):
|
|||||||
chat_response = await conversation.get_response()
|
chat_response = await conversation.get_response()
|
||||||
await bot.send_read_acknowledge(conversation.chat_id)
|
await bot.send_read_acknowledge(conversation.chat_id)
|
||||||
pixiv_text = chat_response.text
|
pixiv_text = chat_response.text
|
||||||
|
if num == 2:
|
||||||
|
pixiv_text = pixiv_text.replace('i.pixiv.cat', 'i.pximg.net')
|
||||||
pixiv_list = pixiv_text.split('|||||')
|
pixiv_list = pixiv_text.split('|||||')
|
||||||
if len(pixiv_list) == 2:
|
if len(pixiv_list) == 2:
|
||||||
pixiv_albums = pixiv_list[1].split('|||')
|
pixiv_albums = pixiv_list[1].split('|||')
|
||||||
@ -85,7 +122,7 @@ async def pixiv(context):
|
|||||||
if len(pixiv_albums) > 8:
|
if len(pixiv_albums) > 8:
|
||||||
await context.edit('获取的图片数大于 8 ,将只发送前8张图片,下载图片中 . . .')
|
await context.edit('获取的图片数大于 8 ,将只发送前8张图片,下载图片中 . . .')
|
||||||
for i in range(0, min(len(pixiv_albums), 8)):
|
for i in range(0, min(len(pixiv_albums), 8)):
|
||||||
r = get(pixiv_albums[i])
|
r = get(pixiv_albums[i], headers=p_headers)
|
||||||
with open("pixiv." + str(i) + ".jpg", "wb") as code:
|
with open("pixiv." + str(i) + ".jpg", "wb") as code:
|
||||||
code.write(r.content)
|
code.write(r.content)
|
||||||
pixiv_album.extend(["pixiv." + str(i) + ".jpg"])
|
pixiv_album.extend(["pixiv." + str(i) + ".jpg"])
|
||||||
|
Loading…
Reference in New Issue
Block a user