mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-22 12:55:38 +00:00
eat 优化判断
This commit is contained in:
parent
d12d4d8be9
commit
9ebdc9a229
39
eat.py
39
eat.py
@ -6,7 +6,7 @@ from os import remove
|
|||||||
from requests import get
|
from requests import get
|
||||||
from random import randint
|
from random import randint
|
||||||
from telethon.tl.functions.users import GetFullUserRequest
|
from telethon.tl.functions.users import GetFullUserRequest
|
||||||
from telethon.tl.types import MessageEntityMentionName
|
from telethon.tl.types import MessageEntityMentionName, MessageEntityPhone
|
||||||
from telethon.errors.rpcerrorlist import ChatSendStickersForbiddenError
|
from telethon.errors.rpcerrorlist import ChatSendStickersForbiddenError
|
||||||
from struct import error as StructError
|
from struct import error as StructError
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
@ -15,7 +15,6 @@ from pagermaid import redis, config
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
git_source = config['git_source']
|
git_source = config['git_source']
|
||||||
except:
|
except:
|
||||||
@ -36,7 +35,7 @@ configFilePath = 'plugins/eat/config.json'
|
|||||||
configFileRemoteUrlKey = "eat.configFileRemoteUrl"
|
configFileRemoteUrlKey = "eat.configFileRemoteUrl"
|
||||||
|
|
||||||
|
|
||||||
async def eat_it(context, base, mask, photo, number, layer = 0):
|
async def eat_it(context, from_user, base, mask, photo, number, layer=0):
|
||||||
mask_size = mask.size
|
mask_size = mask.size
|
||||||
photo_size = photo.size
|
photo_size = photo.size
|
||||||
if mask_size[0] < photo_size[0] and mask_size[1] < photo_size[1]:
|
if mask_size[0] < photo_size[0] and mask_size[1] < photo_size[1]:
|
||||||
@ -62,7 +61,7 @@ async def eat_it(context, base, mask, photo, number, layer = 0):
|
|||||||
except:
|
except:
|
||||||
await context.edit(f"图片模版加载出错,请检查并更新配置:mask{str(numberPosition[2])}.png")
|
await context.edit(f"图片模版加载出错,请检查并更新配置:mask{str(numberPosition[2])}.png")
|
||||||
return base
|
return base
|
||||||
base = await eat_it(context, base, maskImg, markImg, numberPosition[2], layer+1)
|
base = await eat_it(context, from_user, base, maskImg, markImg, numberPosition[2], layer + 1)
|
||||||
|
|
||||||
temp = base.size[0] if base.size[0] > base.size[1] else base.size[1]
|
temp = base.size[0] if base.size[0] > base.size[1] else base.size[1]
|
||||||
if temp != 512:
|
if temp != 512:
|
||||||
@ -72,14 +71,14 @@ async def eat_it(context, base, mask, photo, number, layer = 0):
|
|||||||
return base
|
return base
|
||||||
|
|
||||||
|
|
||||||
async def updateConfig(configFilePath, context):
|
async def updateConfig(context):
|
||||||
configFileRemoteUrl = redis.get(configFileRemoteUrlKey)
|
configFileRemoteUrl = redis.get(configFileRemoteUrlKey)
|
||||||
if configFileRemoteUrl:
|
if configFileRemoteUrl:
|
||||||
if downloadFileFromUrl(configFileRemoteUrl, configFilePath) != 0:
|
if downloadFileFromUrl(configFileRemoteUrl, configFilePath) != 0:
|
||||||
redis.set(configFileRemoteUrlKey, configFileRemoteUrl)
|
redis.set(configFileRemoteUrlKey, configFileRemoteUrl)
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
return await loadConfigFile(configFilePath, context, True)
|
return await loadConfigFile(context, True)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@ -93,7 +92,7 @@ def downloadFileFromUrl(url, filepath):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
async def loadConfigFile(configFilePath, context, forceDownload = False):
|
async def loadConfigFile(context, forceDownload=False):
|
||||||
global positions, notifyStrArr
|
global positions, notifyStrArr
|
||||||
try:
|
try:
|
||||||
with open(configFilePath, 'r', encoding='utf8') as cf:
|
with open(configFilePath, 'r', encoding='utf8') as cf:
|
||||||
@ -154,7 +153,6 @@ async def eat(context):
|
|||||||
return
|
return
|
||||||
diu_round = False
|
diu_round = False
|
||||||
user_object = await context.client.get_me()
|
user_object = await context.client.get_me()
|
||||||
global from_user
|
|
||||||
from_user = await context.client(GetFullUserRequest(user_object.id))
|
from_user = await context.client(GetFullUserRequest(user_object.id))
|
||||||
if context.reply_to_msg_id:
|
if context.reply_to_msg_id:
|
||||||
reply_message = await context.get_reply_message()
|
reply_message = await context.get_reply_message()
|
||||||
@ -165,15 +163,23 @@ async def eat(context):
|
|||||||
return
|
return
|
||||||
target_user = await context.client(GetFullUserRequest(user_id))
|
target_user = await context.client(GetFullUserRequest(user_id))
|
||||||
else:
|
else:
|
||||||
|
user_raw = ""
|
||||||
if len(context.parameter) == 1 or len(context.parameter) == 2:
|
if len(context.parameter) == 1 or len(context.parameter) == 2:
|
||||||
user = context.parameter[0]
|
user_raw = user = context.parameter[0]
|
||||||
if user.isnumeric():
|
if user.isnumeric():
|
||||||
user = int(user)
|
user = int(user)
|
||||||
else:
|
else:
|
||||||
user = user_object.id
|
user = user_object.id
|
||||||
if context.message.entities is not None:
|
if context.message.entities is not None:
|
||||||
if isinstance(context.message.entities[0], MessageEntityMentionName):
|
if isinstance(context.message.entities[0], MessageEntityMentionName):
|
||||||
return await context.client(GetFullUserRequest(context.message.entities[0].user_id))
|
target_user = await context.client(GetFullUserRequest(context.message.entities[0].user_id))
|
||||||
|
elif isinstance(context.message.entities[0], MessageEntityPhone):
|
||||||
|
target_user = int(context.parameter[0])
|
||||||
|
else:
|
||||||
|
return await context.edit("出错了呜呜呜 ~ 参数错误。")
|
||||||
|
elif user_raw[:1] in [".", "/", "-", "!"]:
|
||||||
|
target_user = from_user
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
user_object = await context.client.get_entity(user)
|
user_object = await context.client.get_entity(user)
|
||||||
target_user = await context.client(GetFullUserRequest(user_object.id))
|
target_user = await context.client(GetFullUserRequest(user_object.id))
|
||||||
@ -184,7 +190,8 @@ async def eat(context):
|
|||||||
if str(exception).startswith("No user has"):
|
if str(exception).startswith("No user has"):
|
||||||
await context.edit("出错了呜呜呜 ~ 指定的道纹不存在。")
|
await context.edit("出错了呜呜呜 ~ 指定的道纹不存在。")
|
||||||
return
|
return
|
||||||
if str(exception).startswith("Could not find the input entity for") or isinstance(exception, StructError):
|
if str(exception).startswith("Could not find the input entity for") or isinstance(exception,
|
||||||
|
StructError):
|
||||||
await context.edit("出错了呜呜呜 ~ 无法通过此 UserID 找到对应的用户。")
|
await context.edit("出错了呜呜呜 ~ 无法通过此 UserID 找到对应的用户。")
|
||||||
return
|
return
|
||||||
if isinstance(exception, OverflowError):
|
if isinstance(exception, OverflowError):
|
||||||
@ -253,14 +260,14 @@ async def eat(context):
|
|||||||
else:
|
else:
|
||||||
# 下载成功,加载配置文件
|
# 下载成功,加载配置文件
|
||||||
redis.set(configFileRemoteUrlKey, p2)
|
redis.set(configFileRemoteUrlKey, p2)
|
||||||
if await loadConfigFile(configFilePath, context, True) != 0:
|
if await loadConfigFile(context, True) != 0:
|
||||||
await context.edit(f"加载配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
await context.edit(f"加载配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
await context.edit(f"下载并加载配置文件成功")
|
await context.edit(f"下载并加载配置文件成功")
|
||||||
else:
|
else:
|
||||||
# 没传url直接更新
|
# 没传url直接更新
|
||||||
if await updateConfig(configFilePath, context) != 0:
|
if await updateConfig(context) != 0:
|
||||||
await context.edit(f"更新配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
await context.edit(f"更新配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -269,7 +276,7 @@ async def eat(context):
|
|||||||
elif p1[0] == "!" or p1[0] == "!":
|
elif p1[0] == "!" or p1[0] == "!":
|
||||||
# 加载配置
|
# 加载配置
|
||||||
if exists(configFilePath):
|
if exists(configFilePath):
|
||||||
if await loadConfigFile(configFilePath, context) != 0:
|
if await loadConfigFile(context) != 0:
|
||||||
await context.edit(f"加载配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
await context.edit(f"加载配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
||||||
return
|
return
|
||||||
txt = ""
|
txt = ""
|
||||||
@ -311,7 +318,7 @@ async def eat(context):
|
|||||||
|
|
||||||
# 加载配置
|
# 加载配置
|
||||||
if exists(configFilePath):
|
if exists(configFilePath):
|
||||||
if await loadConfigFile(configFilePath, context) != 0:
|
if await loadConfigFile(context) != 0:
|
||||||
await context.edit(f"加载配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
await context.edit(f"加载配置文件异常,请确认从远程下载的配置文件格式是否正确")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -334,7 +341,7 @@ async def eat(context):
|
|||||||
number = str(number)
|
number = str(number)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
result = await eat_it(context, eatImg, maskImg, markImg, number)
|
result = await eat_it(context, from_user, eatImg, maskImg, markImg, number)
|
||||||
result.save('plugins/eat/eat.webp')
|
result.save('plugins/eat/eat.webp')
|
||||||
target_file = await context.client.upload_file("plugins/eat/eat.webp")
|
target_file = await context.client.upload_file("plugins/eat/eat.webp")
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user