__version__ = (1, 1, 1, 1)
# This file is a part of Hikka Userbot
# Code is NOT licensed under CC-BY-NC-ND 4.0 unless otherwise specified.
# 🌐 https://github.com/hikariatama/Hikka
# You CAN edit this file without direct permission from the author.
# You can redistribute this file with any modifications.
# meta developer: @yg_modules
# scope: hikka_only
# scope: hikka_min 1.6.3
# ported classes from telethon that are not in Hikka-TL
# █▄█ █░█ █▀▄▀█ █▀▄▀█ █▄█ █▀▄▀█ █▀█ █▀▄ █▀
# ░█░ █▄█ █░▀░█ █░▀░█ ░█░ █░▀░█ █▄█ █▄▀ ▄█
from .. import loader, utils
@loader.tds
class yg_stars(loader.Module):
"""Get current prices for stars in different currencies!"""
strings = {"name": "yg_stars",
"hint": ("💡 The course is calculated at the price of a 100 star package.\n"
"📉 When you buy more, the price per star will be slightly lower!\n\n"),
"loading": "💱 Fetching information...",
"phrase": "Rate for",
"phrase_usd": "Amount of stars for",
"1": "stars",
"2": "star",
"3": "stars"}
strings_ru = {"name": "yg_stars",
"hint": ("💡 Курс рассчитан по цене пакета в 100 звёзд.\n"
"📉 При покупке большего количества цена за звезду будет немного ниже!\n\n"),
"loading": "💱 Получаю информацию...",
"phrase": "Курс за",
"phrase_usd": "Количество звёзд за",
"1": "звёзд",
"2": "звезду",
"3": "звезды"}
strings_ua = {"name": "yg_stars",
"hint": ("💡 Курс розрахований за ціною пакета 100 зірок.\n"
"📉 При покупці більшої кількості ціна за зірку буде трохи нижчою!\n\n"),
"loading": "💱 Отримую інформацію...",
"phrase": "Курс за",
"phrase_usd": "Кількість зірок за",
"1": "зірок",
"2": "зірку",
"3": "зірки"}
async def client_ready(self, *_):
self.lib = await self.import_lib("https://mods.kok.gay/lib",
suspend_on_error=True)
@loader.command(ru_doc=" - получить курс звезд", ua_doc=" - отримати курс зірок")
async def starscmd(self, msg):
""" - get the rate of stars"""
args = utils.get_args_raw(msg)
try:
amount = int(args) if args else 1
except ValueError:
await utils.answer(msg, "Enter the number of stars!")
return
await utils.answer(msg, self.strings("loading"))
result = await msg.client(self.lib.GetStarsGiftOptionsRequest(user_id="me"))
rates = await self.lib.YRates(result[0].stars, result[0].currency, result[0].amount).get()
text = (f"⭐️ {self.phrase(amount)}\n\n"
f"{self.strings('hint')}")
for source, values in rates.items():
text += self.format(source, values, amount) + "\n"
await utils.answer(msg, text, parse_mode=self.lib.YummyHtml)
@loader.command(ru_doc=" - доллары в звезды", ua_doc=" - долари у зірки")
async def dollarcmd(self, msg):
""" - dollars to stars"""
args = utils.get_args_raw(msg)
try:
usd_amount = float(args) if args else 1.0
except ValueError:
return await utils.answer(msg, "Enter the amount in USD!")
await utils.answer(msg, self.strings("loading"))
result = await msg.client(self.lib.GetStarsGiftOptionsRequest(user_id="me"))
rates = await self.lib.YRates(result[0].stars, result[0].currency, result[0].amount).get()
text = (f"🇺🇲 {self.strings('phrase_usd')} ${usd_amount:.2f}\n\n"
f"{self.strings('hint')}")
for source, values in rates.items():
stars_count = int(usd_amount / values['USD']) if values['USD'] > 0 else 0
text += (f"{source}:\n"
f"└─ ⭐️ {stars_count} {self.get_suffix(stars_count)}
\n")
await utils.answer(msg, text, parse_mode=self.lib.YummyHtml)
def get_suffix(self, amount):
last_two = amount % 100
last = amount % 10
return self.strings("1" if 11 <= last_two <= 14 else
"2" if last == 1 else
"3" if 2 <= last <= 4 else "1")
def phrase(self, amount):
return f"{self.strings('phrase')} {amount} {self.get_suffix(amount)}"
def format(self, name, data, amount):
return (f"{name}:\n"
f"├─ 🇺🇲 USD: {data['USD'] * amount:.2f}\n"
f"├─ 🇪🇺 EUR: {data['EUR'] * amount:.2f}\n"
f"├─ 🇺🇦 UAH: {data['UAH'] * amount:.2f}\n"
f"├─ 🇷🇺 RUB: {data['RUB'] * amount:.2f}\n"
f"├─ 🇵🇱 PLN: {data['PLN'] * amount:.2f}\n"
f"└─ 👛 TON: {data['TON'] * amount:.2f}
\n")