-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevoke_checks.py
More file actions
85 lines (70 loc) · 2.37 KB
/
revoke_checks.py
File metadata and controls
85 lines (70 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import asyncio
from os import getenv
from aiogram import Bot
from dotenv import load_dotenv
from db_tools import (
check_all_subscriptions,
check_subscription_end,
delete_user_subscription,
get_all_users,
)
from xui import delete_xui_client
load_dotenv(".env")
ADMIN = getenv("ADMIN")
TOKEN = getenv("BOT_TOKEN")
async def main() -> None:
"""Check subscriptions and send messages to users."""
bot = Bot(token=TOKEN)
(
common_data_vray,
user_ids_tomorrow_ends_vray,
) = check_all_subscriptions()
if isinstance(common_data_vray, str):
common_data_vray = [common_data_vray]
if isinstance(user_ids_tomorrow_ends_vray, str):
user_ids_tomorrow_ends_vray = [user_ids_tomorrow_ends_vray]
await bot.send_message(
chat_id=ADMIN,
text=(
f"Пользователям:\n"
f"VRAY {common_data_vray}\n"
"будут отменены подписки и удалены из базы.\n"
f"Скоро конец: {user_ids_tomorrow_ends_vray}"
),
)
for obfuscated_user in common_data_vray:
if delete_xui_client(f"{obfuscated_user}@vray"):
delete_user_subscription(obfuscated_user, is_vray=1)
user_ids_tomorrow_ends_vray = (
[user_ids_tomorrow_ends_vray]
if isinstance(user_ids_tomorrow_ends_vray, int)
else user_ids_tomorrow_ends_vray
)
for user_id in user_ids_tomorrow_ends_vray:
vray_end = str(check_subscription_end(user_id, is_vray=1))[:-8]
await bot.send_message(
chat_id=int(user_id),
text=(
f"Напоминаем, что подписка VRAY скоро закончится: {vray_end}. Вы можете продлить ее"
),
)
async def send_message_to_all_users() -> None:
"""Send message to all users."""
bot = Bot(token=TOKEN)
all_users = get_all_users()
for user_id in all_users:
await bot.send_message(
chat_id=int(user_id),
text="Объявление: ",
)
async def refund() -> None:
"""Refunds payment."""
bot = Bot(token=TOKEN)
await bot.refund_star_payment(
user_id=0,
telegram_payment_charge_id="",
)
if __name__ == "__main__":
asyncio.run(main())
# asyncio.run(refund())
# asyncio.run(send_message_to_all_users())