__version__ = (1, 4, 8, 8)
# 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
# █▄█ █░█ █▀▄▀█ █▀▄▀█ █▄█ █▀▄▀█ █▀█ █▀▄ █▀
# ░█░ █▄█ █░▀░█ █░▀░█ ░█░ █░▀░█ █▄█ █▄▀ ▄█
import random as r
import requests
from telethon.tl.types import Message
from .. import loader, utils
class yg_crypto(loader.Module):
"""Модуль для того чтобы узнать курс крипты/фиата"""
strings = {
"name": "yg_crypto",
"inc_args": "🐳 Incorrect args",
"keyerror": (
"🗿 Maybe the coin is not in the site database or you typed the wrong"
" name."
),
"okey": "👯 Successfully. Current default valute: {}",
}
strings_ru = {
"inc_args": "🙀 Неккоректные аргументы",
"keyerror": (
"🙀 Возможно монеты нету в базе данных сайта, или вы ввели неккоректное"
" название."
),
"okey": "🙀 Успешно. Текущая стандартная валюта: {}",
}
async def client_ready(self, client, db):
self.db = db
self.client = client
if "defaultvalute" not in self.db:
self.db.set("defaultvalute", "val", "btc")
async def монетаcmd(self, message: Message):
"""<название> выбрать крипту по умолчанию"""
args = utils.get_args_raw(message)
self.db.set("defaultvalute", "val", args)
await utils.answer(message, self.strings["okey"].format(args))
async def курсcmd(self, message: Message):
"""<кол-во> <название монеты> смотреть курс"""
args = utils.get_args_raw(message)
tray = self.db.get("defaultvalute", "val", args)
if tray == "":
tray = "btc"
if not args:
args = "1" + " " + str(tray)
args_list = args.split(" ")
try:
if len(args_list) == 1 and isinstance(float(args_list[0]), float):
args_list.append(str(tray))
except Exception:
args_list = ["1", args_list[0]]
coin = args_list[1].upper()
if coin == "ТОН":
coin = "TON"
if coin == "ЮСД":
coin = "USD"
if coin == "РУБ":
coin = "RUB"
if coin == "ГРН":
coin = "UAH"
if coin == "ЗЛ":
coin = "PLN"
api = requests.get(
f"https://min-api.cryptocompare.com/data/price?fsym={coin}&tsyms=USD,RUB,UAH,PLN,KZT,BTC,ETH,TON"
).json()
smiles = r.choice(
[
"🙀",
"🙀",
"🙀",
"🙀"
]
)
try:
count = float(args_list[0])
form = (
"{} {} {} is:\n\n🇺🇸"
" {}$\n🇺🇦"
" {}₴\n🇵🇱"
" {}zł.\n🇷🇺"
" {}₽\n🇰🇿"
" {}₸\n🪙 {}"
" BTC\n🪙"
" {} ETH\n🪙 {} TON"
).format(
smiles,
count,
coin,
round(api.get("USD", 0) * count, 2),
round(api.get("UAH", 0) * count, 2),
round(api.get("PLN", 0) * count, 2),
round(api.get("RUB", 0) * count, 2),
round(api.get("KZT", 0) * count, 2),
round(api.get("BTC", 0) * count, 4),
round(api.get("ETH", 0) * count, 4),
round(api.get("TON", 0) * count, 4),
)
await utils.answer(message, form)
except KeyError:
await utils.answer(message, self.strings["keyerror"])
except ValueError:
await utils.answer(message, self.strings["inc_args"])