-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_con.py
381 lines (334 loc) · 15.7 KB
/
settings_con.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
372
373
374
375
376
377
378
379
380
381
from firebase_admin import db
from telegram.ext import ConversationHandler
from functions import *
TWITTER_UPDATE, TWITTER_UPDATE_LIST, TWITTER_UPDATE_CONFIRM = range(3)
async def twitter_ids(update, context):
message = update.message
if message.chat.type in ['group', 'supergroup']:
return ConversationHandler.END
chat_id = message.chat_id
username = message.from_user.username
text = message.text
reply_keyboard = [["Update ID's", "My id's"], ['settings']]
await bot.send_message(chat_id=chat_id, text="Twitter settings",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True),
reply_to_message_id=update.message.message_id)
return TWITTER_UPDATE
async def twitter_update(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text
text = text.lower()
if "update id's" == text:
reply_keyboard = [['cancel']]
await bot.send_message(chat_id=chat_id, text="Now send the all twitter usernames comma(,) separated including "
"previously added id's\n"
"Example: @pugalkmc",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True),
reply_to_message_id=update.message.message_id)
return TWITTER_UPDATE_LIST
elif "my id's" == text:
get_ids = peoples_col.find_one({'chat_id': chat_id})
if get_ids and 'twitter' in get_ids:
form_text = "Twitter id's list:\n"
for i in get_ids['twitter']:
form_text += f"@{i} "
await bot.send_message(chat_id=chat_id, text=form_text)
else:
await bot.send_message(chat_id=chat_id, text="No twitter id's found!")
return await twitter_ids(update, context)
elif "settings" == text:
await settings(update, context)
return ConversationHandler.END
async def twitter_update_list(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text
if "cancel" == text.lower():
return await twitter_ids(update, context)
ids = text.replace("@", "").replace(" ", "").split(",")
ids_text = ''
for i in ids:
ids_text += f"@{i} "
context.user_data['twitter_ids'] = ids
reply_keyboard = [["confirm", "cancel"]]
await bot.send_message(chat_id=chat_id, text=f"Twitter ID:\n"
f"{ids_text}\n\n"
f"Please click confirm or cancel the process",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
return TWITTER_UPDATE_CONFIRM
async def twitter_update_confirm(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text
text = text.lower()
if "confirm" == text:
print(context.user_data['twitter_ids'])
peoples_col.update_one({"chat_id": chat_id}, {"$set": {"twitter": context.user_data['twitter_ids']}},
upsert=True)
await bot.send_message(chat_id=chat_id, text="Your twitter id's are updated")
return await twitter_ids(update, context)
elif "cancel" == text:
return await twitter_ids(update, context)
else:
await bot.send_message(chat_id=chat_id, text="Please correct option 'confirm' or 'cancel'")
return TWITTER_UPDATE_CONFIRM
BINANCE_OPTIONS, SET_BINANCE = range(2)
async def binance_start(update, context):
message = update.message
if message.chat.type == 'group' or message.chat.type == 'supergroup':
return ConversationHandler.END
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
get_data = peoples_col.find_one({"chat_id": chat_id})
if get_data and 'binance' in get_data:
reply_keyboard = [["change binance", "settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your binance ID : {get_data['binance']}",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'set'
else:
reply_keyboard = [["set binance", "settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your binance not set",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'not set'
return BINANCE_OPTIONS
async def binance_option(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
if context.user_data['status'] == 'set':
option_1 = "change binance"
else:
option_1 = "set binance"
if option_1 == text:
reply_keyboard = [["cancel"]]
await bot.send_message(chat_id=chat_id, text=f"Now send the binance ID to set",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
return SET_BINANCE
elif "settings" == text:
await settings(update, context)
return ConversationHandler.END
else:
await bot.send_message(chat_id=chat_id, text="Please select valid option")
return BINANCE_OPTIONS
async def set_binance(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
if "cancel" == text:
await settings(update, context)
return ConversationHandler.END
if text.isnumeric():
peoples_col.update_one({"chat_id": chat_id}, {"$set": {"binance": text}}, upsert=True)
return await binance_start(update, context)
else:
await bot.send_message(chat_id=chat_id, text="Binance ID must be a number")
return SET_BINANCE
ADDRESS_OPTIONS, SET_ADDRESS = range(2)
async def address_start(update, context):
message = update.message
if message.chat.type == 'group' or message.chat.type == 'supergroup':
return ConversationHandler.END
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
get_data = peoples_col.find_one({"chat_id": chat_id})
if get_data and 'address' in get_data:
reply_keyboard = [["change address", "settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your TUSD address : {get_data['address']}",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'set'
else:
reply_keyboard = [["set address", "settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your TUSD(BEP-20) address not set",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'not set'
return ADDRESS_OPTIONS
async def address_option(update, context):
message = update.message
chat_id = message.chat_id
text = message.text.lower()
if context.user_data['status'] == 'set':
option_1 = "change address"
else:
option_1 = "set address"
if option_1 == text:
reply_keyboard = [["cancel"]]
await bot.send_message(chat_id=chat_id, text=f"Now send the TUSD(BEP-20) Binance account or any wallet "
f"address to set\n\n",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
return SET_ADDRESS
elif "settings" == text:
await settings(update, context)
return ConversationHandler.END
else:
await bot.send_message(chat_id=chat_id, text="Please select valid option")
return ADDRESS_OPTIONS
async def set_address(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
if "cancel" == text:
await settings(update, context)
return ConversationHandler.END
try:
url = f"https://api.bscscan.com/api?module=account&action=balance&address={text}&apikey={bscscan_api_key}"
response = requests.get(url)
data = response.json()
if data["status"] == "1" and data["message"] == "OK":
# Check if the address has any BEP-20 tokens
peoples_col.update_one({"chat_id": chat_id}, {"$set": {"address": text}}, upsert=True)
return await address_start(update, context)
else:
await bot.send_message(chat_id=update.effective_chat.id, text="Address not found, Please send proper TUSD("
"BEP-20) address")
except Exception as e:
await bot.send_message(chat_id=update.effective_chat.id,
text="An error occurred while checking the TUSD address.\n"
"Report to developer")
return SET_ADDRESS
DISCORD_OPTIONS, SET_DISCORD = range(2)
async def discord_start(update, context):
message = update.message
if message.chat.type == 'group' or message.chat.type == 'supergroup':
return ConversationHandler.END
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
get_data = peoples_col.find_one({"chat_id": chat_id})
if get_data and 'discord' in get_data:
reply_keyboard = [["change discord", "settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your discord username : {get_data['discord']}",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'set'
else:
reply_keyboard = [["set discord", "settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your discord username not set",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'not set'
return DISCORD_OPTIONS
async def discord_option(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
if context.user_data['status'] == 'set':
option_1 = "change discord"
else:
option_1 = "set discord"
if option_1 == text:
reply_keyboard = [["cancel"]]
await bot.send_message(chat_id=chat_id, text=f"Now send the discord username to set\n"
f"Example: PugalKMC#5040",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
return SET_DISCORD
elif "settings" == text:
await settings(update, context)
return ConversationHandler.END
else:
await bot.send_message(chat_id=chat_id, text="Please select valid option")
return DISCORD_OPTIONS
async def set_discord(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text
if "cancel" == text.lower():
await settings(update, context)
return ConversationHandler.END
if "#" in text:
peoples_col.update_one({"chat_id": chat_id}, {"$set": {"discord": text}}, upsert=True)
return await discord_start(update, context)
else:
await bot.send_message(chat_id=chat_id, text="Invalid discord username")
return SET_DISCORD
UPI_OPTIONS, SET_UPI = range(2)
async def upi_start(update, context):
message = update.message
if message.chat.type == 'group' or message.chat.type == 'supergroup':
return ConversationHandler.END
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
get_data = peoples_col.find_one({"chat_id": chat_id})
if get_data and 'upi' in get_data:
reply_keyboard = [["Change UPI", "Settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your UPI ID: {get_data['upi']}",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'set'
else:
reply_keyboard = [["Set UPI", "Settings"]]
await bot.send_message(chat_id=chat_id, text=f"Your UPI ID not set",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
context.user_data['status'] = 'not set'
return UPI_OPTIONS
async def upi_option(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text.lower()
if context.user_data['status'] == 'set':
option_1 = "change upi"
else:
option_1 = "set upi"
if option_1 == text:
reply_keyboard = [["cancel"]]
await bot.send_message(chat_id=chat_id, text=f"Now send the UPI ID to set\n"
f"Example: 9344776097@paytm",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True,
one_time_keyboard=True)
)
return SET_BINANCE
elif "settings" == text:
await settings(update, context)
return ConversationHandler.END
else:
await bot.send_message(chat_id=chat_id, text="Please select a valid option")
return UPI_OPTIONS
async def set_upi(update, context):
message = update.message
chat_id = message.chat_id
username = message.from_user.username
text = message.text
if "cancel" == text.lower():
await settings(update, context)
return ConversationHandler.END
if "@" in text:
peoples_col.update_one({"chat_id": chat_id}, {"$set": {"upi": text}}, upsert=True)
return await upi_start(update, context)
else:
await bot.send_message(chat_id=chat_id, text="Invalid UPI ID")
return SET_UPI