Added and updated repositories 2026-02-08 01:58:46

This commit is contained in:
github-actions[bot]
2026-02-08 01:58:46 +00:00
parent ab5aaf579b
commit 23dade9b9e

View File

@@ -4,9 +4,9 @@
#░░░█░░░█░░░░█░░█░█░█░█ #░░░█░░░█░░░░█░░█░█░█░█
#░░░███░███░░█░░███░███ #░░░███░███░░█░░███░███
# meta developer: @ZetGo # meta developer: @nullmod
__version__ = (1, 0, 0) __version__ = (1, 0, 1)
import io import io
import math import math
@@ -94,9 +94,9 @@ def set_gradient(im: io.BytesIO, gradient: Image.Image) -> io.BytesIO:
buffer.seek(0) buffer.seek(0)
return buffer return buffer
def crop_by_bbox(img: Image.Image): def crop_by_bbox(img: Image.Image, bbox: tuple = None):
img_w, img_h = img.size img_w, img_h = img.size
x, y, w, h = BBOX_TGA_TGD x, y, w, h = bbox or BBOX_TGA_TGD
left = int(round(x * img_w)) left = int(round(x * img_w))
top = int(round(y * img_h)) top = int(round(y * img_h))
@@ -132,7 +132,7 @@ BBOX_TGA_TGD = (
) )
@loader.translatable_docstring @loader.tds
class Gradientor(loader.Module): class Gradientor(loader.Module):
strings = { strings = {
"name": "Gradientor", "name": "Gradientor",
@@ -148,11 +148,17 @@ class Gradientor(loader.Module):
async def client_ready(self): async def client_ready(self):
self.colors = self.get("PROFILE_COLORS", None) self.colors = self.get("PROFILE_COLORS", None)
if not self.colors: if not self.colors or not self.colors.get("light", None):
raw_colors = (await self.client(GetPeerProfileColorsRequest(0))).colors raw_colors = (await self.client(GetPeerProfileColorsRequest(0))).colors
self.colors = { self.colors = {
str(col.color_id): hexes_to_rgbs(col.dark_colors.bg_colors) for col "dark": {
in raw_colors str(col.color_id): hexes_to_rgbs(col.dark_colors.bg_colors) for col
in raw_colors
},
"light": {
str(col.color_id): hexes_to_rgbs(col.colors.bg_colors) for col
in raw_colors
},
} }
self.set("PROFILE_COLORS", self.colors) self.set("PROFILE_COLORS", self.colors)
@@ -160,12 +166,14 @@ class Gradientor(loader.Module):
@loader.command( @loader.command(
ru_doc="[фотография/reply] - создать аватарку с градиентом из цвета профиля\n" ru_doc="[фотография/reply] - создать аватарку с градиентом из цвета профиля\n"
"--update-cache - обновить кеш профиля, если вы только что сменили фон профиля\n" "--update-cache - обновить кеш профиля, если вы только что сменили фон профиля\n"
"--linear - использовать линейный градиент" "--linear - использовать линейный градиент\n"
"--light - использовать светлую тему"
) )
async def makepp(self, message: Message): async def makepp(self, message: Message):
"""[photo/reply] - create a profile picture with a gradient from profile color\n """[photo/reply] - create a profile picture with a gradient from profile color\n
--update-cache - update profile cache if you just changed profile background\n --update-cache - update profile cache if you just changed profile background\n
--linear - use linear gradient""" --linear - use linear gradient\n
--light - use light theme"""
reply: Message = await message.get_reply_message() reply: Message = await message.get_reply_message()
args = utils.get_args(message) args = utils.get_args(message)
@@ -174,13 +182,25 @@ class Gradientor(loader.Module):
args.remove("--update-cache") args.remove("--update-cache")
else: else:
upd_cache = False upd_cache = False
if "--linear" in args: if "--linear" in args:
force_linear = True force_linear = True
args.remove("--linear") args.remove("--linear")
else: else:
force_linear = False force_linear = False
if "--light" in args:
theme = "light"
args.remove("--light")
else:
theme = "dark"
if "--full" in args:
_full = True
args.remove("--full")
else:
_full = False
user = None user = None
background_only = False background_only = False
@@ -202,10 +222,10 @@ class Gradientor(loader.Module):
user = reply.sender user = reply.sender
else: else:
user = self.client.hikka_me user = self.client.hikka_me
if not user.premium: if not user.premium:
color1, color2 = (28, 28, 28), (28, 28, 28) color1, color2 = (28, 28, 28), (28, 28, 28)
elif user.emoji_status and isinstance(user.emoji_status, EmojiStatusCollectible): elif user.emoji_status and isinstance(user.emoji_status, EmojiStatusCollectible):
color1, color2 = ( color1, color2 = (
user.emoji_status.edge_color, user.emoji_status.center_color user.emoji_status.edge_color, user.emoji_status.center_color
@@ -216,20 +236,21 @@ class Gradientor(loader.Module):
elif user.profile_color: elif user.profile_color:
color_variant = user.profile_color.color color_variant = user.profile_color.color
color1, color2 = self.colors.get( color1, color2 = self.colors.get(theme).get(
str(color_variant), str(color_variant),
((28, 28, 28), (28, 28, 28)) ((28, 28, 28), (28, 28, 28))
) )
else: else:
color1, color2 = (28, 28, 28), (28, 28, 28) color1, color2 = (28, 28, 28), (28, 28, 28)
await utils.answer(message, self.strings["gradient_creating"]) await utils.answer(message, self.strings["gradient_creating"])
gradient = get_gradient((1280, 1280), color1, color2, "linear" if force_linear else "radial") gradient = get_gradient((1280, 1280), color1, color2, "linear" if force_linear else "radial")
gradient = crop_by_bbox(gradient) if not _full:
gradient = crop_by_bbox(gradient)
if not background_only: if not background_only and not _full:
p_b = await photo_source.download_media(bytes) p_b = await photo_source.download_media(bytes)
p_b_io = io.BytesIO(p_b) p_b_io = io.BytesIO(p_b)
p_b_io.seek(0) p_b_io.seek(0)
@@ -240,7 +261,7 @@ class Gradientor(loader.Module):
result = io.BytesIO() result = io.BytesIO()
gradient.save(result, format='PNG') gradient.save(result, format='PNG')
result.seek(0) result.seek(0)
result.name = "grad @nullmod.png" result.name = "grad @nullmod.png"
await utils.answer(message, self.strings["gradient_created"], file=result, force_document=True) await utils.answer(message, self.strings["gradient_created"], file=result, force_document=True)