forked from MarseyWorld/MarseyWorld
fds
parent
9b566b8f05
commit
243ee712ea
|
@ -0,0 +1,82 @@
|
|||
import math
|
||||
from PIL import Image
|
||||
import io
|
||||
|
||||
pat_frames = [
|
||||
Image.open("files/assets/images/pat/0.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/1.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/2.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/3.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/4.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/5.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/6.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/7.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/8.gif").convert("RGBA"),
|
||||
Image.open("files/assets/images/pat/9.gif").convert("RGBA")
|
||||
]
|
||||
|
||||
def getPat(avatar_file, format="webp"):
|
||||
avatar_x = 5
|
||||
avatar_y = 5
|
||||
avatar_width = 150
|
||||
avatar_height = 150
|
||||
image_width = 160
|
||||
image_height = 160
|
||||
hand_x = 0
|
||||
hand_y = 0
|
||||
delay = 30
|
||||
|
||||
y_scale = [
|
||||
1,
|
||||
0.95,
|
||||
0.9,
|
||||
0.85,
|
||||
0.8,
|
||||
0.8,
|
||||
0.85,
|
||||
0.9,
|
||||
0.95,
|
||||
1
|
||||
]
|
||||
|
||||
x_scale = [
|
||||
0.80,
|
||||
0.85,
|
||||
0.90,
|
||||
0.95,
|
||||
1,
|
||||
1,
|
||||
0.95,
|
||||
0.90,
|
||||
0.85,
|
||||
0.80
|
||||
]
|
||||
|
||||
frames = []
|
||||
avatar_img = Image.open(avatar_file)
|
||||
for i in range(0, 10):
|
||||
avatar_actual_x = math.ceil((1 - x_scale[i]) * avatar_width / 2 + avatar_x)
|
||||
avatar_actual_y = math.ceil((1 - y_scale[i]) * avatar_height + avatar_y)
|
||||
avatar_actual_width = math.ceil(avatar_width * x_scale[i])
|
||||
avatar_actual_height = math.ceil(avatar_height * y_scale[i])
|
||||
|
||||
scaled_avatar_img = avatar_img.resize((avatar_actual_width, avatar_actual_height))
|
||||
frame = Image.new(mode="RGBA", size=(image_width, image_height))
|
||||
frame.paste(scaled_avatar_img, (avatar_actual_x, avatar_actual_y))
|
||||
frame.paste(pat_frames[i], (hand_x, hand_y), pat_frames[i])
|
||||
frames.append(frame)
|
||||
|
||||
output = io.BytesIO()
|
||||
frames[0].save(output, format,
|
||||
save_all = True,
|
||||
append_images = frames[1:],
|
||||
duration = delay,
|
||||
loop = 0
|
||||
)
|
||||
return output
|
||||
|
||||
|
||||
def pat(emoji):
|
||||
stream = getPat(open(f'files/assets/images/emojis/{emoji}.webp', "rb"), "webp")
|
||||
stream.seek(0)
|
||||
open(f'files/assets/images/emojis/{emoji}pat.webp', "wb").write(stream.read())
|
|
@ -3,6 +3,7 @@ from bs4 import BeautifulSoup
|
|||
from bleach.linkifier import LinkifyFilter
|
||||
from functools import partial
|
||||
from .get import *
|
||||
from .patter import pat
|
||||
from os import path, environ
|
||||
import re
|
||||
from mistletoe import markdown
|
||||
|
@ -243,6 +244,10 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
if path.isfile(f'files/assets/images/emojis/{remoji}.webp'):
|
||||
new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" class="{classes}" src="/e/{remoji}.webp">', new, flags=re.I|re.A)
|
||||
if comment: marseys_used.add(emoji)
|
||||
elif remoji.endswith('pat') and path.isfile(f"files/assets/images/emojis/{remoji.replace('pat','')}.webp"):
|
||||
pat(remoji.replace('pat',''))
|
||||
new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" class="{classes}" src="/e/{remoji}.webp">', new, flags=re.I|re.A)
|
||||
|
||||
|
||||
sanitized = sanitized.replace(old, new)
|
||||
|
||||
|
@ -263,10 +268,6 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
old = emoji
|
||||
if emoji == 'marseyrandom': emoji = choice(marseys_const2)
|
||||
else: emoji = old
|
||||
|
||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
sanitized = re.sub(f'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{old}:" title=":!{old}:" class="{classes}" src="/e/{emoji}.webp">', sanitized, flags=re.I|re.A)
|
||||
if comment: marseys_used.add(emoji)
|
||||
else:
|
||||
classes = 'emoji'
|
||||
if not edit and random() < 0.0025 and ('marsey' in emoji or emoji in marseys_const2): classes += ' golden'
|
||||
|
@ -275,9 +276,13 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
if emoji == 'marseyrandom': emoji = choice(marseys_const2)
|
||||
else: emoji = old
|
||||
|
||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
sanitized = re.sub(f'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', sanitized, flags=re.I|re.A)
|
||||
if comment: marseys_used.add(emoji)
|
||||
|
||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
sanitized = re.sub(f'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', sanitized, flags=re.I|re.A)
|
||||
if comment: marseys_used.add(emoji)
|
||||
elif emoji.endswith('pat') and path.isfile(f"files/assets/images/emojis/{emoji.replace('pat','')}.webp"):
|
||||
pat(emoji.replace('pat',''))
|
||||
sanitized = re.sub(f'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{old}:" title=":!{old}:" class="{classes}" src="/e/{emoji}.webp">', sanitized, flags=re.I|re.A)
|
||||
|
||||
|
||||
for rd in ["://reddit.com", "://new.reddit.com", "://www.reddit.com", "://redd.it", "://libredd.it"]:
|
||||
|
@ -353,10 +358,7 @@ def filter_emojis_only(title, edit=False, graceful=False):
|
|||
old = emoji
|
||||
if emoji == 'marseyrandom': emoji = choice(marseys_const2)
|
||||
else: emoji = old
|
||||
|
||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
title = re.sub(f'(?<!"):!{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{old}:" title=":!{old}:" src="/e/{emoji}.webp" class="{classes}">', title, flags=re.I|re.A)
|
||||
|
||||
old = '!' + emoji
|
||||
else:
|
||||
classes = 'emoji'
|
||||
if not edit and random() < 0.0025 and ('marsey' in emoji or emoji in marseys_const2): classes += ' golden'
|
||||
|
@ -365,8 +367,13 @@ def filter_emojis_only(title, edit=False, graceful=False):
|
|||
if emoji == 'marseyrandom': emoji = choice(marseys_const2)
|
||||
else: emoji = old
|
||||
|
||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
title = re.sub(f'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', title, flags=re.I|re.A)
|
||||
|
||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
title = re.sub(f'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', title, flags=re.I|re.A)
|
||||
elif emoji.endswith('pat') and path.isfile(f"files/assets/images/emojis/{emoji.replace('pat','')}.webp"):
|
||||
pat(emoji.replace('pat',''))
|
||||
title = re.sub(f'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', title, flags=re.I|re.A)
|
||||
|
||||
|
||||
title = strikethrough_regex.sub(r'<del>\1</del>', title)
|
||||
|
||||
|
|
Loading…
Reference in New Issue