Asynchronous api of the SkyManager service
Project description
<h1>SkyManagerAPI <img src="https://sun9-87.userapi.com/s/v1/if2/V2hDbOtYk5zwTO8A-Fe9oQcDkr_SWTwL3T0I96qmrXlKEklSNjXMx7gBT-oRf6Coh51kOK9ZFMdGXSJWBcOywrmW.jpg?quality=95&as=32x19,48x28,72x42,108x63,160x94,240x141,360x211,480x281,540x317,640x375,720x422,771x452&from=bu&cs=771x0" width=45 height=25></h1>
<p align="left" >
<a href="https://pypi.org/project/skymanagerapi/">
<img src="https://img.shields.io/pypi/v/skymanagerapi?style=flat-square" alt="PyPI">
</a>
<a href="https://pypi.org/project/skymanagerapi/">
<img src="https://img.shields.io/pypi/dm/skymanagerapi?style=flat-square" alt="PyPI">
</a>
</p>
Использование
With skymanagerapi you can use SkyManagerAPI together with Telegram
Documentation: https://api.skymanager.top/redoc
Установка
pip install skymanager
Требования
-
Python 3.8+ -
aiohttp
Возможности
-
Asynchronous -
Exception handling
Пример обязательной подписки, показов методом /check
from skymanagerapi import SkyManager
from aiogram import types
skym = SkyManager(skym_token) # skym_token api-ключ сервиса SkyManager
async def message_handler(message: types.Message):
# Применяйте везде, где требуется проверка
if not await skym.check(
user_id=message.from_user.id,
language_code=message.from_user.language_code,
is_premium=message.from_user.is_premium):
return
async def callback_handler(call: types.CallbackQuery):
# Применяйте везде, где требуется проверка
if not await skym.check(
user_id=call.from_user.id,
language_code=call.from_user.language_code,
is_premium=call.from_user.is_premium):
return
Использование пользовательского сообщения
# Опционально, для метода check. Можно настроить также в @SkyManagerBot
message_custom = {
"text": "🤖 Чтобы пользоваться чат-ботом, сначала выполните задания",
"row_width": 2, # кнопок в одной в строке
"buttons": [ # [0] - bot, [1] - channel, [2] - url, [3] - boost
{"title": "▶️ Запустить бота"}, # bot
{"title": "➕ Подписаться"}, # channel
{"title": "🌐 Открыть"}, # external / url
]
}
await skym.check(user_id, language_code=language_code, message=message)
Пример интеграции без токена бота методами /get_tasks, /check_tasks
# Получение задач для пользователя /get_tasks
@dp.message(Command(commands=["start"]))
async def message_handler(message: types.Message):
data = await skym.get_tasks(
user_id=message.from_user.id,
language_code=message.from_user.language_code, # used only for new pinning
is_premium=message.from_user.is_premium,
limit=5) # количество слотов
if data.get("result"):
# ВАЖНО! Необходимо добавить в код бота функцию отправки сообщения op_message(). Пример ниже.
await op_message(bot, message.chat.id, data["result"], data["bundle_id"])
return
...
# Получение статуса выполнения задач
@dp.callback_query(lambda c: c.data and c.data.startswith("sky_fp:"))
async def check_subscription(call: types.CallbackQuery):
bundle_id = call.data.split(":", 1)[1]
done = await skym.check_tasks(call.from_user.id, bundle_id)
if done:
await call.message.delete()
await call.message.answer("Подписка подтверждена ✅")
else:
await call.answer("Вы ещё не подписались.", show_alert=True)
# Пример функции op_message().
async def op_message(bot, chat_id: int, tasks: list[dict], bundle_id: str, template: dict | None = None) -> None:
if not tasks:
return
tpl = template or {}
text = tpl.get("text", "👋 Для продолжения подпишитесь и нажмите «✅ Проверить».")
row_width = int(tpl.get("row_width", 2)) or 2
t_bot = tpl.get("button_bot", "Запустить")
t_channel = tpl.get("button_channel", "Подписаться")
t_url = tpl.get("button_url", "Перейти")
t_boost = tpl.get("button_boost", "Голосовать")
t_confirm = tpl.get("button_fp", "✅ Проверить")
title_map = {"bot": t_bot, "channel": t_channel, "external": t_url, "boost": t_boost}
rows, row = [], []
for idx, t in enumerate(tasks, start=1):
rtype = t.get("rtype", "external")
row.append(
types.InlineKeyboardButton(
text=f"{idx} {title_map.get(rtype, t_url)}",
url=t["url"],
)
)
if len(row) == row_width:
rows.append(row); row = []
if row: rows.append(row)
# 👉 bundle_id упаковываем в callback_data
rows.append([
types.InlineKeyboardButton(
text=t_confirm,
callback_data=f"sky_fp:{bundle_id}"
)
])
kb = types.InlineKeyboardMarkup(inline_keyboard=rows)
await bot.send_message(chat_id, text, reply_markup=kb, parse_mode="HTML")
Developed by Mits (c) 2024-2025
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
skymanager-1.0.0.tar.gz
(7.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skymanager-1.0.0.tar.gz.
File metadata
- Download URL: skymanager-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5133603d54ed17faf9a0df381843b928abef785b87bad78a7781c6130d94ce4
|
|
| MD5 |
4cc2beac746bab1b2b2ba1a855939afc
|
|
| BLAKE2b-256 |
e62e17bd0d9bb700ce6de85e6ad76d06c7f15ac9fdc72fa88a382e12bd2d975b
|
File details
Details for the file skymanager-1.0.0-py3-none-any.whl.
File metadata
- Download URL: skymanager-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d75587e2f93c5a2ddbb58696bc5fc8efc70ba4a1e7ea15843ed8a915e734c0df
|
|
| MD5 |
5b7126b70e51778cea190529c54bf788
|
|
| BLAKE2b-256 |
cf230cfaffde4e9f58908d91a6df496c8146c8b371acd6a17312a44eb6b5d4d7
|