-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPromoClaimer.py
More file actions
139 lines (118 loc) · 6.36 KB
/
PromoClaimer.py
File metadata and controls
139 lines (118 loc) · 6.36 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# ---------------------------------------------------лл------------------------------
# ░█▀▄░▄▀▀▄░█▀▄░█▀▀▄░█▀▀▄░█▀▀▀░▄▀▀▄░░░█▀▄▀█
# ░█░░░█░░█░█░█░█▄▄▀░█▄▄█░█░▀▄░█░░█░░░█░▀░█
# ░▀▀▀░░▀▀░░▀▀░░▀░▀▀░▀░░▀░▀▀▀▀░░▀▀░░░░▀░░▒▀
# Name: PromoClaimer
# Description: Automatically claim https://t.me/StableWaifuBot promo from any chat
# Author: @codrago_m
# Ported with Wine Hikka for FoxUserbot
# ---------------------------------------------------------------------------------
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# ---------------------------------------------------------------------------------
# Author: @codrago
# Commands: checktokens
# scope: hikka_only
# meta developer: @codrago_m
# ---------------------------------------------------------------------------------
import asyncio
import os
import logging
from pyrogram import Client, filters
from pyrogram.enums import ParseMode
import re
from command import fox_command, fox_sudo, who_message, get_text
logger = logging.getLogger(__name__)
filename = os.path.basename(__file__)
Module_Name = 'PromoClaimer'
LANGUAGES = {
"en": {
"module_name": "PromoClaimer",
"claimed_promo": "[PromoClaimer] 👌 I successfully claimed promo {promo} for {amount} tokens!",
"error_watcher": "[PromoClaimer] ⛔️ An error occurred while watching for messages:\n{e}",
"invalid_promo": "[PromoClaimer] 😢 Promo code {promo} is invalid or has expired!",
"already_claimed": "[PromoClaimer] 😢 Promo code {promo} has already been claimed!",
"checking_tokens": "[PromoClaimer] Checking tokens balance...",
"watcher_started": "[PromoClaimer] Watcher started for StableWaifuBot promos",
"command_description": "| Check tokens balance"
},
"ru": {
"module_name": "PromoClaimer",
"claimed_promo": "[PromoClaimer] 👌 Я успешно активировал промокод {promo} на {amount} токен(-ов)!",
"error_watcher": "[PromoClaimer] ⛔️ Во время отслеживания сообщений произошла ошибка:\n{e}",
"invalid_promo": "[PromoClaimer] 😢 Промокод {promo} недействителен, либо уже истек!",
"already_claimed": "[PromoClaimer] 😢 Промокод {promo} уже активирован!",
"checking_tokens": "[PromoClaimer] Проверка баланса токенов...",
"watcher_started": "[PromoClaimer] Старт отслеживания промокодов StableWaifuBot",
"command_description": "| Посмотреть баланс токенов"
}
}
@Client.on_message(fox_command("checktokens", Module_Name, filename) & fox_sudo())
async def checktokens(client, message):
message = await who_message(client, message)
await message.edit(
get_text("PromoClaimer", "checking_tokens", LANGUAGES=LANGUAGES),
parse_mode=ParseMode.MARKDOWN
)
try:
bot_username = "StableWaifuBot"
sent_message = await client.send_message(bot_username, "/tokens")
response = None
for _ in range(15):
await asyncio.sleep(1)
async for msg in client.get_chat_history(bot_username, limit=1):
if msg.from_user and not msg.from_user.is_self and msg.id != sent_message.id:
response = msg
break
if response:
break
if response and response.text:
# Проверяем, есть ли информация о токенах в ответе
if "не нашел" in response.text.lower() or "not found" in response.text.lower():
tokens = f"❌ {response.text}"
else:
# Показываем весь ответ от бота
tokens = response.text
else:
tokens = "❌ No response from bot"
await message.edit(tokens, parse_mode=ParseMode.MARKDOWN)
except Exception as e:
await message.edit(f"❌ Error: {e}", parse_mode=ParseMode.MARKDOWN)
@Client.on_message(filters.text & ~filters.me)
async def watcher(client, message):
try:
print(message.text)
if not message.text:
return
pattern = r'https://t\.me/StableWaifuBot\?start=promo_(\w+)'
matches = re.findall(pattern, message.text)
if not matches:
return
bot_username = "StableWaifuBot"
for match in matches:
promo = 'promo_' + match
sent_message = await client.send_message(bot_username, f'/start {promo}')
response = None
for _ in range(15):
await asyncio.sleep(1)
async for msg in client.get_chat_history(bot_username, limit=1):
if msg.from_user and not msg.from_user.is_self and msg.id != sent_message.id:
response = msg
break
if response:
break
if not response:
logger.error(f"No response for promo {promo}")
continue
if 'недействителен' in response.text or 'истёк' in response.text or 'неверный' in response.text:
logger.info(get_text("PromoClaimer", "invalid_promo", LANGUAGES=LANGUAGES, promo=promo))
elif 'уже активирован' in response.text:
logger.info(get_text("PromoClaimer", "already_claimed", LANGUAGES=LANGUAGES, promo=promo))
else:
try:
amount = response.text.split('(+')[1]
logger.info(get_text("PromoClaimer", "claimed_promo", LANGUAGES=LANGUAGES, promo=promo, amount=amount))
except (IndexError, ValueError):
logger.info(get_text("PromoClaimer", "claimed_promo", LANGUAGES=LANGUAGES, promo=promo, amount="?"))
except Exception as e:
logger.error(get_text("PromoClaimer", "error_watcher", LANGUAGES=LANGUAGES, e=str(e)))