mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-22 07:08:18 +00:00
eat 支持指定配置生成吃头像图片 (#196)
This commit is contained in:
parent
2da0ef0959
commit
624dd013c0
57
eat.py
57
eat.py
@ -11,16 +11,25 @@ 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
|
||||||
from pagermaid.utils import alias_command
|
from pagermaid.utils import alias_command
|
||||||
|
from pagermaid import redis, config
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
git_source = config['git_source']
|
||||||
|
except:
|
||||||
|
git_source = "https://raw.githubusercontent.com/Xtao-Labs/PagerMaid_Plugins/master/"
|
||||||
positions = {
|
positions = {
|
||||||
"1": [297, 288],
|
"1": [297, 288],
|
||||||
"2": [85, 368],
|
"2": [85, 368],
|
||||||
"3": [127, 105],
|
"3": [127, 105],
|
||||||
"4": [76, 325],
|
"4": [76, 325],
|
||||||
"5": [256, 160],
|
"5": [256, 160],
|
||||||
|
"6": [298, 22],
|
||||||
}
|
}
|
||||||
max_number = 5
|
notifyStrArr = {
|
||||||
|
"6": "踢人",
|
||||||
|
}
|
||||||
|
max_number = len(positions)
|
||||||
|
|
||||||
|
|
||||||
def eat_it(base, mask, photo, number):
|
def eat_it(base, mask, photo, number):
|
||||||
@ -41,14 +50,13 @@ def eat_it(base, mask, photo, number):
|
|||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=True, outgoing=True, command=alias_command("eat"),
|
@listener(is_plugin=True, outgoing=True, command=alias_command("eat"),
|
||||||
description="生成一张 吃头像 图片,(可选:当第二个参数存在时,旋转用户头像 180°)",
|
description="生成一张 吃头像 图片,(可选:当第二个参数是数字时,读取预存的配置;当第二个参数是r开头时,头像旋转180°,并且判断r后面是数字则读取对应的配置生成)",
|
||||||
parameters="<username/uid> [随意内容]")
|
parameters="<username/uid> [随意内容]")
|
||||||
async def eat(context):
|
async def eat(context):
|
||||||
if len(context.parameter) > 2:
|
if len(context.parameter) > 2:
|
||||||
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
||||||
return
|
return
|
||||||
diu_round = False
|
diu_round = False
|
||||||
await context.edit("正在生成 吃头像 图片中 . . .")
|
|
||||||
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()
|
||||||
try:
|
try:
|
||||||
@ -57,8 +65,6 @@ async def eat(context):
|
|||||||
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
||||||
return
|
return
|
||||||
target_user = await context.client(GetFullUserRequest(user_id))
|
target_user = await context.client(GetFullUserRequest(user_id))
|
||||||
if len(context.parameter) == 1:
|
|
||||||
diu_round = True
|
|
||||||
else:
|
else:
|
||||||
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 = context.parameter[0]
|
||||||
@ -97,19 +103,52 @@ async def eat(context):
|
|||||||
for num in range(1, max_number + 1):
|
for num in range(1, max_number + 1):
|
||||||
print(num)
|
print(num)
|
||||||
if not exists('plugins/eat/eat' + str(num) + '.png'):
|
if not exists('plugins/eat/eat' + str(num) + '.png'):
|
||||||
re = get('https://raw.githubusercontent.com/FlowerSilent/Photo/master/photo/eat' + str(num) + '.png')
|
re = get(f'{git_source}eat/eat' + str(num) + '.png')
|
||||||
with open('plugins/eat/eat' + str(num) + '.png', 'wb') as bg:
|
with open('plugins/eat/eat' + str(num) + '.png', 'wb') as bg:
|
||||||
bg.write(re.content)
|
bg.write(re.content)
|
||||||
if not exists('plugins/eat/mask' + str(num) + '.png'):
|
if not exists('plugins/eat/mask' + str(num) + '.png'):
|
||||||
re = get('https://raw.githubusercontent.com/FlowerSilent/Photo/master/photo/mask' + str(num) + '.png')
|
re = get(f'{git_source}eat/mask' + str(num) + '.png')
|
||||||
with open('plugins/eat/mask' + str(num) + '.png', 'wb') as ms:
|
with open('plugins/eat/mask' + str(num) + '.png', 'wb') as ms:
|
||||||
ms.write(re.content)
|
ms.write(re.content)
|
||||||
number = randint(1, max_number)
|
number = randint(1, max_number)
|
||||||
|
try:
|
||||||
|
p1 = 0
|
||||||
|
p2 = 0
|
||||||
|
if len(context.parameter) == 1:
|
||||||
|
p1 = context.parameter[0]
|
||||||
|
if p1[0] == "r":
|
||||||
|
diu_round = True
|
||||||
|
if len(p1) > 1:
|
||||||
|
p2 = int("".join(p1[1:]))
|
||||||
|
number = p2
|
||||||
|
elif p1[0] == "d":
|
||||||
|
if len(p1) > 1:
|
||||||
|
p2 = int("".join(p1[1:]))
|
||||||
|
if p2:
|
||||||
|
redis.set("eat.default-config", p2)
|
||||||
|
await context.edit(f"已经设置默认配置为:{p2}")
|
||||||
|
else:
|
||||||
|
redis.delete("eat.default-config")
|
||||||
|
await context.edit(f"已经清空默认配置")
|
||||||
|
return
|
||||||
|
defaultConfig = redis.get("eat.default-config")
|
||||||
|
if p2 > 0:
|
||||||
|
number = p2
|
||||||
|
elif not diu_round and int(p1) > 0:
|
||||||
|
number = int(p1)
|
||||||
|
elif defaultConfig:
|
||||||
|
number = int(defaultConfig)
|
||||||
|
except:
|
||||||
|
number = randint(1, max_number)
|
||||||
|
try:
|
||||||
|
notifyStr = notifyStrArr[str(number)]
|
||||||
|
except:
|
||||||
|
notifyStr = "吃头像"
|
||||||
|
await context.edit(f"正在生成 {notifyStr} 图片中 . . .")
|
||||||
markImg = Image.open("plugins/eat/" + str(target_user.user.id) + ".jpg")
|
markImg = Image.open("plugins/eat/" + str(target_user.user.id) + ".jpg")
|
||||||
eatImg = Image.open("plugins/eat/eat" + str(number) + ".png")
|
eatImg = Image.open("plugins/eat/eat" + str(number) + ".png")
|
||||||
maskImg = Image.open("plugins/eat/mask" + str(number) + ".png")
|
maskImg = Image.open("plugins/eat/mask" + str(number) + ".png")
|
||||||
if len(context.parameter) == 2:
|
|
||||||
diu_round = True
|
|
||||||
if diu_round:
|
if diu_round:
|
||||||
markImg = markImg.rotate(180) # 对图片进行旋转
|
markImg = markImg.rotate(180) # 对图片进行旋转
|
||||||
result = eat_it(eatImg, maskImg, markImg, number)
|
result = eat_it(eatImg, maskImg, markImg, number)
|
||||||
|
BIN
eat/eat6.png
Normal file
BIN
eat/eat6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
BIN
eat/mask6.png
Normal file
BIN
eat/mask6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
Loading…
Reference in New Issue
Block a user