2021-04-28 11:01:25 +00:00
|
|
|
import os
|
|
|
|
|
2021-08-07 07:56:48 +00:00
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.builtins import Bot
|
|
|
|
from core.builtins import Image as Img
|
2023-03-04 08:51:56 +00:00
|
|
|
from core.component import module
|
2022-06-12 07:07:53 +00:00
|
|
|
from core.utils.cache import random_cache_path
|
2021-04-28 11:01:25 +00:00
|
|
|
|
2021-09-29 15:35:50 +00:00
|
|
|
assets_path = os.path.abspath('./assets/arcaea')
|
|
|
|
|
2023-03-04 08:51:56 +00:00
|
|
|
p = module('ptt',
|
2023-04-30 03:30:59 +00:00
|
|
|
developers=['OasisAkari'])
|
2021-10-24 10:55:45 +00:00
|
|
|
|
|
|
|
|
2023-03-15 11:29:25 +00:00
|
|
|
@p.handle('<potential> {{ptt.help}}')
|
2023-02-05 14:33:33 +00:00
|
|
|
async def pttimg(msg: Bot.MessageSession):
|
2021-07-27 17:42:47 +00:00
|
|
|
ptt = msg.parsed_msg['<potential>']
|
2021-04-28 11:01:25 +00:00
|
|
|
# ptt
|
2021-07-27 17:42:47 +00:00
|
|
|
if ptt == '--':
|
2021-04-28 11:01:25 +00:00
|
|
|
ptt = -1
|
|
|
|
else:
|
2022-03-26 16:40:40 +00:00
|
|
|
try:
|
|
|
|
ptt = float(ptt)
|
|
|
|
except ValueError:
|
2023-05-19 04:46:29 +00:00
|
|
|
await msg.finish(msg.locale.t('ptt.message.error.invalid'))
|
2022-07-07 09:55:38 +00:00
|
|
|
if ptt >= 13.00:
|
|
|
|
pttimg = 7
|
|
|
|
elif ptt >= 12.50:
|
2021-04-28 11:01:25 +00:00
|
|
|
pttimg = 6
|
|
|
|
elif ptt >= 12.00:
|
|
|
|
pttimg = 5
|
|
|
|
elif ptt >= 11.00:
|
|
|
|
pttimg = 4
|
|
|
|
elif ptt >= 10.00:
|
|
|
|
pttimg = 3
|
|
|
|
elif ptt >= 7.00:
|
|
|
|
pttimg = 2
|
|
|
|
elif ptt >= 3.50:
|
|
|
|
pttimg = 1
|
|
|
|
elif ptt >= 0:
|
|
|
|
pttimg = 0
|
2022-08-23 07:36:07 +00:00
|
|
|
|
2021-04-28 11:01:25 +00:00
|
|
|
else:
|
|
|
|
pttimg = 'off'
|
2021-09-29 15:35:50 +00:00
|
|
|
pttimgr = Image.open(f'{assets_path}/ptt/rating_{str(pttimg)}.png')
|
2021-04-28 11:01:25 +00:00
|
|
|
ptttext = Image.new("RGBA", (119, 119))
|
2021-09-29 15:35:50 +00:00
|
|
|
font1 = ImageFont.truetype(os.path.abspath(f'{assets_path}/Fonts/Exo-SemiBold.ttf'), 49)
|
|
|
|
font2 = ImageFont.truetype(os.path.abspath(f'{assets_path}/Fonts/Exo-SemiBold.ttf'), 33)
|
2021-09-30 04:52:45 +00:00
|
|
|
if ptt >= 0 and ptt <= 99.99:
|
2021-04-28 11:01:25 +00:00
|
|
|
rawptt = str(ptt).split('.')
|
|
|
|
if len(rawptt) < 2:
|
|
|
|
ptt1 = rawptt[0]
|
|
|
|
ptt2 = '00'
|
|
|
|
else:
|
|
|
|
ptt1 = rawptt[0]
|
2021-09-30 04:52:45 +00:00
|
|
|
ptt2 = rawptt[1][:2]
|
2021-04-28 11:01:25 +00:00
|
|
|
if len(ptt2) < 2:
|
|
|
|
ptt2 += '0'
|
|
|
|
ptttext_width, ptttext_height = ptttext.size
|
|
|
|
font1_width, font1_height = font1.getsize(ptt1 + '.')
|
|
|
|
font2_width, font2_height = font2.getsize(ptt2)
|
|
|
|
pttimg = Image.new("RGBA", (font1_width + font2_width + 6, font1_height + 6))
|
|
|
|
drawptt = ImageDraw.Draw(pttimg)
|
2022-07-27 08:52:09 +00:00
|
|
|
stroke_color = '#52495d'
|
|
|
|
if int(ptt1) >= 13:
|
|
|
|
stroke_color = '#81122F'
|
|
|
|
drawptt.text((0, 0), ptt1 + '.', 'white', font=font1, stroke_width=3, stroke_fill=stroke_color)
|
2022-07-31 08:33:20 +00:00
|
|
|
drawptt.text((font1_width, int(int(font1_height) - int(font2_height))), ptt2, 'white', font=font2,
|
|
|
|
stroke_width=3, stroke_fill=stroke_color)
|
2021-09-30 05:08:58 +00:00
|
|
|
elif ptt == -1:
|
|
|
|
ptt = '--'
|
|
|
|
ptttext_width, ptttext_height = ptttext.size
|
|
|
|
font1_width, font1_height = font1.getsize(ptt)
|
|
|
|
pttimg = Image.new("RGBA", (font1_width + 6, font1_height + 6))
|
|
|
|
drawptt = ImageDraw.Draw(pttimg)
|
2022-03-26 16:40:40 +00:00
|
|
|
drawptt.text((0, 0), ptt, 'white', font=font1, stroke_width=3, stroke_fill='#52495d')
|
2021-04-28 11:01:25 +00:00
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
return await msg.finish(msg.locale.t('ptt.message.error.invalid'))
|
2021-04-28 11:01:25 +00:00
|
|
|
pttimg_width, pttimg_height = pttimg.size
|
2021-08-07 07:56:48 +00:00
|
|
|
ptttext.alpha_composite(pttimg,
|
|
|
|
(int((ptttext_width - pttimg_width) / 2), int((ptttext_height - pttimg_height) / 2) - 11))
|
2022-07-09 06:29:19 +00:00
|
|
|
ptttext = ptttext.resize(pttimgr.size)
|
2021-04-28 11:01:25 +00:00
|
|
|
pttimgr.alpha_composite(ptttext, (0, 0))
|
2022-06-12 07:07:53 +00:00
|
|
|
savepath = random_cache_path() + '.png'
|
2021-07-27 17:42:47 +00:00
|
|
|
pttimgr.save(savepath)
|
2022-05-21 16:04:29 +00:00
|
|
|
await msg.finish([Img(path=savepath)])
|