This repository has been archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
waves_telegram.py
371 lines (273 loc) · 15.5 KB
/
waves_telegram.py
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
import waves_bot
import waves_database
import waves_payments
import re
from waves_config import BOT_TOKEN
from telegram import Update, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, CallbackQueryHandler
from telegram.ext import filters
from telegram.constants import ParseMode
from time import time
from random import randint
from threading import Thread
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
username = update.effective_chat.username
if username != "your_telegram_username":
print("[INFO] New user:", username)
text = "<b>GM! This is a private bot.</b>\n\n<b>Current features:</b>\n- Monitor USDC/USDT/BUSD balances of gateway\n- Check for withdrawal availability of these stablecoins\n- Notify when arbitrage opportunity occurs and withdrawal is available\n\n<b>Commands:</b>\n- Help — Displays this message\n- Configure notifications — Set notifications mode\n- Info — Show latest info"
keyboard = [
["Info", "Configure notifications"],
["Account", "Help"]
]
markup = ReplyKeyboardMarkup(keyboard, True)
await context.bot.send_message(update.effective_chat.id, text, ParseMode.HTML, reply_markup=markup)
async def account(update: Update, context: ContextTypes.DEFAULT_TYPE):
user = await waves_database.get_user(update.effective_chat.username)
keyboard = [
[InlineKeyboardButton("Buy subscription — $10 (1 month)", callback_data="Buy")]
]
markup = InlineKeyboardMarkup(keyboard)
text = f"<b>Account:</b>\n{update.effective_user.full_name} (@{update.effective_chat.username})\n\n<b>Subscriptions:</b>\n"
if not user:
text = text + "No active subscription"
await context.bot.send_message(update.effective_chat.id, text, ParseMode.HTML, reply_markup=markup)
return
expiration = user[1]
current_time = int(time())
if expiration > current_time:
days_count = round((expiration-current_time)/60/60/24)
text = text + f"{days_count} day left" if days_count == 1 else text + f"{days_count} days left"
if days_count <= 2:
await context.bot.send_message(update.effective_chat.id, text, ParseMode.HTML, reply_markup=markup)
return
await context.bot.send_message(update.effective_chat.id, text, ParseMode.HTML)
return
if expiration == 0:
text = text + "Lifetime subscription"
await context.bot.send_message(update.effective_chat.id, text, ParseMode.HTML)
return
text = text + "No active subscription"
await context.bot.send_message(update.effective_chat.id, text, ParseMode.HTML, reply_markup=markup)
async def check_subscription(update: Update, context: ContextTypes.DEFAULT_TYPE):
user = await waves_database.get_user(update.effective_chat.username)
if not user:
keyboard = [
[InlineKeyboardButton("Get free trial (1 day)", callback_data="Trial")]
]
markup = InlineKeyboardMarkup(keyboard)
await context.bot.send_message(update.effective_chat.id, "You're not allowed to use this command", reply_markup=markup)
return False
expiration = user[1]
if expiration > int(time()):
return True
if expiration == 0:
return True
await context.bot.send_message(update.effective_chat.id, "Your subscription/trial has expired")
return False
async def give_trial(update: Update, context: ContextTypes.DEFAULT_TYPE):
if await waves_database.get_user(update.effective_chat.username):
await update.callback_query.answer("You have already used trial or have active subscription")
return
await waves_database.add_user(update.effective_chat.username)
await waves_database.set_user_expiration(update.effective_chat.username, int(time())+86400)
await update.callback_query.answer("Your trial period has started!")
async def process_subscription(update: Update, context: ContextTypes.DEFAULT_TYPE):
tx_hash = update.effective_message.text
random_num = context.user_data.get("random_num")
if not random_num:
return
amount = float("10."+str(random_num))
if not waves_payments.check_tx(tx_hash, amount):
await context.bot.send_message(update.effective_chat.id, "Failed to process this transaction:\nTransaction doesn't exist or tx hash is invalid")
return
current_time = int(time())
user = await waves_database.get_user(update.effective_chat.username)
if user:
expiration = user[1]
if expiration == 0 or expiration < current_time:
context.user_data.clear()
await waves_database.set_user_expiration(update.effective_chat.username, current_time+60*60*24*30)
await context.bot.send_message(update.effective_chat.id, "Your 30 day subscription period has started!")
return
offset = expiration - current_time
context.user_data.clear()
await waves_database.set_user_expiration(update.effective_chat.username, current_time+offset+60*60*24*30)
await context.bot.send_message(update.effective_chat.id, "Added 30 days to your current subscription!")
return
context.user_data.clear()
await waves_database.add_user(update.effective_chat.username)
await waves_database.set_user_expiration(update.effective_chat.username, current_time+60*60*24*30)
await context.bot.send_message(update.effective_chat.id, "Your 30 day subscription period has started!")
return
async def buy_subscription(update: Update, context: ContextTypes.DEFAULT_TYPE):
random_num = context.user_data.get("random_num")
if not random_num:
random_num = randint(100000, 999999)
context.user_data.update({"random_num": random_num})
text = f"Send <b>exactly</b> 10.{random_num} USDT/BUSD/USDC to {waves_payments.RECEIVER_ADDRESS}\n\nAccepted chains:\nEthereum, BSC, Polygon\n\nEnter the tx hash:"
await update.callback_query.answer("")
await context.bot.send_message(update.effective_chat.id, text, ParseMode.HTML)
async def configure(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not await check_subscription(update, context):
return
keyboard = [
[InlineKeyboardButton("Standard", callback_data="Standard"), InlineKeyboardButton("Silent", callback_data="Silent")],
[InlineKeyboardButton("Disable", callback_data="Disable")]
]
markup = InlineKeyboardMarkup(keyboard)
await context.bot.send_message(update.effective_chat.id, "Choose notification mode:", reply_markup=markup)
async def bot_runner(context: ContextTypes.DEFAULT_TYPE):
if not waves_bot.msg:
return
mode = context.job.data[0]
expiration = context.job.data[1]
if int(time()) > expiration and expiration != 0:
jobs = context.job_queue.jobs()
for job in jobs:
if job.chat_id == context.job.chat_id:
job.schedule_removal()
if mode == 1:
await context.bot.send_message(context.job.chat_id, f"```\n{waves_bot.msg}```", ParseMode.MARKDOWN_V2)
if mode == 2 and "arb" in waves_bot.msg:
await context.bot.send_message(context.job.chat_id, f"```\n{waves_bot.msg}```", ParseMode.MARKDOWN_V2)
async def bot_standard(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not await check_subscription(update, context):
return
jobs = context.job_queue.jobs()
for job in jobs:
if job.chat_id == update.effective_chat.id:
job.schedule_removal()
await update.callback_query.answer("Started sending notifications every 30 seconds")
await waves_database.set_mode(update.effective_chat.username, update.effective_chat.id, 1)
expiration = (await waves_database.get_user(update.effective_chat.username))[1]
context.job_queue.run_repeating(bot_runner, 30, chat_id=update.effective_chat.id, data=(1, expiration))
async def bot_silent(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not await check_subscription(update, context):
return
jobs = context.job_queue.jobs()
for job in jobs:
if job.chat_id == update.effective_chat.id:
job.schedule_removal()
await update.callback_query.answer("Started sending notifications for arbitrage opportunities")
await waves_database.set_mode(update.effective_chat.username, update.effective_chat.id, 2)
expiration = (await waves_database.get_user(update.effective_chat.username))[1]
context.job_queue.run_repeating(bot_runner, 30, chat_id=update.effective_chat.id, data=(2, expiration))
async def bot_stop(update: Update, context: ContextTypes.DEFAULT_TYPE):
jobs = context.job_queue.jobs()
if not jobs:
await update.callback_query.answer("Notifications are already disabled")
return
for job in jobs:
if job.chat_id == update.effective_chat.id:
job.schedule_removal()
await waves_database.set_mode(update.effective_chat.username, update.effective_chat.id, 0)
await update.callback_query.answer("Notifications disabled")
else:
await update.callback_query.answer("Notifications are already disabled")
async def info(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not await check_subscription(update, context):
return
if not waves_bot.msg:
return
await context.bot.send_message(update.effective_chat.id, f"```\n{waves_bot.msg}```", ParseMode.MARKDOWN_V2)
class AdminCommands:
async def try_withdraw(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.effective_chat.username != "rexcloud":
await context.bot.send_message(update.effective_chat.id, "You're not allowed to use this command")
return
if waves_bot.try_withdraw_running:
await context.bot.send_message(update.effective_chat.id, "Already running. Use /stop_try_withdraw first")
return
if len(context.args) != 2:
await context.bot.send_message(update.effective_chat.id, "Invalid command params:\n/try_withdraw TOKEN AMOUNT\nExample:\n/try_withdraw USDT 5000")
return
token = context.args[0].upper()
if token not in ("USDT", "USDC", "BUSD"):
await context.bot.send_message(update.effective_chat.id, "Invalid token (USDT, USDC, BUSD)")
return
amount = context.args[1]
try:
if "." in amount:
amount = float(amount)
elif "," in amount:
await context.bot.send_message(update.effective_chat.id, "Invalid amount format (1000 or 1000.77)")
return
else:
amount = int(amount)
except ValueError:
await context.bot.send_message(update.effective_chat.id, "Invalid amount format (1000 or 1000.77)")
return
waves_bot.try_withdraw_running = True
Thread(target=waves_bot.try_withdraw_loop, args=(token, amount), daemon=True).start()
await context.bot.send_message(update.effective_chat.id, f"Started trying to withdraw {amount} {token}")
async def stop_try_withdraw(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.effective_chat.username != "rexcloud":
await context.bot.send_message(update.effective_chat.id, "You're not allowed to use this command")
return
if waves_bot.try_withdraw_running:
waves_bot.try_withdraw_running = False
await context.bot.send_message(update.effective_chat.id, "Stopped trying to withdraw")
else:
await context.bot.send_message(update.effective_chat.id, "Use /try_withdraw TOKEN AMOUNT first")
async def add_user(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.effective_chat.username != "rexcloud":
await context.bot.send_message(update.effective_chat.id, "You're not allowed to use this command")
return
if len(context.args) != 1:
await context.bot.send_message(update.effective_chat.id, "Invalid command params:\n/add_user @username")
return
username = context.args[0].replace("@", "")
await waves_database.add_user(username)
await context.bot.send_message(update.effective_chat.id, f"Added {username}")
async def remove_user(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.effective_chat.username != "rexcloud":
await context.bot.send_message(update.effective_chat.id, "You're not allowed to use this command")
return
if len(context.args) != 1:
await context.bot.send_message(update.effective_chat.id, "Invalid command params:\n/remove_user @username")
return
username = context.args[0].replace("@", "")
jobs = context.job_queue.jobs()
if jobs:
for job in jobs:
if job.chat_id == update.effective_chat.id:
job.schedule_removal()
await waves_database.remove_user(username)
await context.bot.send_message(update.effective_chat.id, f"Removed {username}")
async def get_users(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.effective_chat.username != "rexcloud":
await context.bot.send_message(update.effective_chat.id, "You're not allowed to use this command")
return
text = "Username, mode, period:\n\n"
users = await waves_database.get_all_users()
for user in users:
text = text + user[0] + ", " + str(user[1]) + ", " + str(user[2]) + "\n"
await context.bot.send_message(update.effective_chat.id, text)
if __name__ == "__main__":
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Thread(target=waves_bot.run_parser, daemon=True).start()
bot = ApplicationBuilder().token(BOT_TOKEN).build()
bot.add_handler(CommandHandler(("start", "help"), start))
bot.add_handler(MessageHandler(filters.Regex(re.compile("^(start|help)$", re.IGNORECASE)), start))
bot.add_handler(MessageHandler(filters.Regex(re.compile("^Info$", re.IGNORECASE)), info))
bot.add_handler(MessageHandler(filters.Regex(re.compile("^Configure notifications$", re.IGNORECASE)), configure))
bot.add_handler(MessageHandler(filters.Regex(re.compile("^Account$", re.IGNORECASE)), account))
bot.add_handler(MessageHandler(filters.Regex(re.compile("^0x", re.IGNORECASE)), process_subscription))
bot.add_handler(CallbackQueryHandler(buy_subscription, "Buy"))
bot.add_handler(CallbackQueryHandler(give_trial, "Trial"))
bot.add_handler(CallbackQueryHandler(bot_standard, "Standard"))
bot.add_handler(CallbackQueryHandler(bot_silent, "Silent"))
bot.add_handler(CallbackQueryHandler(bot_stop, "Disable"))
bot.add_handler(CommandHandler("try_withdraw", AdminCommands.try_withdraw))
bot.add_handler(CommandHandler("stop_try_withdraw", AdminCommands.stop_try_withdraw))
bot.add_handler(CommandHandler("add_user", AdminCommands.add_user))
bot.add_handler(CommandHandler("remove_user", AdminCommands.remove_user))
bot.add_handler(CommandHandler("get_users", AdminCommands.get_users))
while True:
try:
active_jobs = waves_database._get_active_modes()
for job in active_jobs:
bot.job_queue.run_repeating(bot_runner, 30, chat_id=job[0], data=(job[1], job[2]))
bot.run_polling(drop_pending_updates=True)
except:
continue