eat 支持指定配置生成吃头像图片 (#196)

This commit is contained in:
lowking 2021-11-08 23:36:45 +08:00 committed by GitHub
parent 2da0ef0959
commit 624dd013c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 10 deletions

57
eat.py
View File

@ -11,16 +11,25 @@ from telethon.errors.rpcerrorlist import ChatSendStickersForbiddenError
from struct import error as StructError
from pagermaid.listener import listener
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 = {
"1": [297, 288],
"2": [85, 368],
"3": [127, 105],
"4": [76, 325],
"5": [256, 160],
"6": [298, 22],
}
max_number = 5
notifyStrArr = {
"6": "踢人",
}
max_number = len(positions)
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"),
description="生成一张 吃头像 图片,(可选:当第二个参数存在时,旋转用户头像 180°",
description="生成一张 吃头像 图片,(可选:当第二个参数是数字时读取预存的配置当第二个参数是r开头时头像旋转180°并且判断r后面是数字则读取对应的配置生成",
parameters="<username/uid> [随意内容]")
async def eat(context):
if len(context.parameter) > 2:
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
diu_round = False
await context.edit("正在生成 吃头像 图片中 . . .")
if context.reply_to_msg_id:
reply_message = await context.get_reply_message()
try:
@ -57,8 +65,6 @@ async def eat(context):
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
target_user = await context.client(GetFullUserRequest(user_id))
if len(context.parameter) == 1:
diu_round = True
else:
if len(context.parameter) == 1 or len(context.parameter) == 2:
user = context.parameter[0]
@ -97,19 +103,52 @@ async def eat(context):
for num in range(1, max_number + 1):
print(num)
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:
bg.write(re.content)
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:
ms.write(re.content)
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")
eatImg = Image.open("plugins/eat/eat" + str(number) + ".png")
maskImg = Image.open("plugins/eat/mask" + str(number) + ".png")
if len(context.parameter) == 2:
diu_round = True
if diu_round:
markImg = markImg.rotate(180) # 对图片进行旋转
result = eat_it(eatImg, maskImg, markImg, number)

BIN
eat/eat6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
eat/mask6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -202,7 +202,7 @@
},
{
"name": "eat",
"version": "1.031",
"version": "1.032",
"section": "profile",
"maintainer": "SF_PICK",
"size": "6.4 kb",