function = 'kickChatMember' fieldss = {'chat_id': chat_id, 'user_id': user_id} send = requests.post(self.api_url + function, fieldss) #print(send.json()) return send details = sys.argv[1:] conn = mysql.connector.connect(host=details[0], user=details[1], database=details[2], password=details[3], autocommit=True) cur = conn.cursor() token = database.special('API', cur) offset = 0 change_address = [] with_amount = [] special = [ '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!' ] bot = BoilerPlate(token) def starter(): global offset, conn, cur
def bot_message_handler(current_updates, update_id, message_id, sender_id, group_id, dict_checker, cur, callback_data=0, callback=False): global pairs try: if callback == True: print(callback_data, sender_id, time.time()) if callback_data == 'New Alert': full_code = [] if sender_id in alert: del alert[sender_id] for i in pairs: full_code.append([{'text':f'{i}', 'callback_data':f'{i}'}]) full_code.append([{'text':'Back','callback_data':'Back'}]) bot.edit_message_two(group_id, message_id, 'Select a pair', full_code) bot.get_updates(offset = update_id+1) elif callback_data in pairs: cu_price = price(callback_data) cu_price = str(cu_price).replace('.', '\\.') bot.edit_message_two(group_id, message_id, f'Current Price of {callback_data}: {cu_price}\\.\nTo create an alert send the price point in one word', [[{'text':'Back', 'callback_data':'New Alert'}]]) alert[sender_id] = callback_data bot.get_updates(offset = update_id+1) if callback_data == 'Back': if sender_id in alert: del alert[sender_id] if sender_id in feedback: feedback.remove(sender_id) bot.edit_message_two(group_id, message_id, 'Select one of the options below\nSend /start to go back to the main menu', [[{'text':'Active Alerts', 'callback_data':'Active Alert'}], [{'text':'Create New Alert', 'callback_data':'New Alert'}], [{'text':'Source Code', 'url':'https://github.com/Sakib0194/crypto_price_alert/'}, {'text':'Send Feedback', 'callback_data':'Feedback'}], [{'text':'Price Checker', 'callback_data':'Price Checker'}]]) bot.get_updates(offset = update_id+1) if callback_data == 'Active Alert': full_text = '' for i in pairs: full_text += f'*{i}*\n' data = database.all_up(sender_id, i, cur).split(' ') for a in data: a = a.replace('.', '\\.') full_text += f'{a}\n' data = database.all_down(sender_id, i, cur).split(' ') for a in data: a = a.replace('.', '\\.') full_text += f'{a}\n' bot.edit_message_two(group_id, message_id, full_text, [[{'text':'Back','callback_data':'Back'}]]) bot.get_updates(offset = update_id+1) if callback_data == 'Feedback': feedback.append(sender_id) bot.edit_message_two(group_id, message_id, 'You can report any bugs, feedback, request features from here\\.\nType your text now, it will be recorded\nTo contact me directly [click here](https://t.me/sakib0194)', [[{'text':'Back','callback_data':'Back'}]]) bot.get_updates(offset = update_id+1) if callback_data == 'Price Checker': full_text = '' for i in for_price: cu_price = price(i) cu_price = str(cu_price).replace('.', '\\.') full_text += f'*{i}* {cu_price}\n' full_text += '\nAll Binance Pairs price can now be checked via the command below\n*price PairNames*\nexample command\nprice BNBBTC\nprice BTCUSDT BNBUSDT etc' bot.send_message(sender_id, full_text) bot.get_updates(offset = update_id+1) else: text = current_updates['message']['text'] print(text, sender_id, time.time()) if text == '/start': if sender_id in feedback: feedback.remove(sender_id) if sender_id in alert: del alert[sender_id] users = database.all_users(cur) if sender_id not in users: database.add_users(sender_id, cur) database.add_user_alert(sender_id, cur) bot.send_message_four(sender_id, 'Select one of the options below\nSend /start to go back to the main menu', [[{'text':'Active Alerts', 'callback_data':'Active Alert'}], [{'text':'Create New Alert', 'callback_data':'New Alert'}], [{'text':'Source Code', 'url':'https://github.com/Sakib0194/crypto_price_alert/'}, {'text':'Send Feedback', 'callback_data':'Feedback'}], [{'text':'Price Checker', 'callback_data':'Price Checker'}]]) bot.get_updates(offset = update_id+1) if sender_id in alert: try: pri_point = float(text) price_point = str(pri_point).replace('.', '\\.') sele_pair = alert[sender_id] bot.send_message_four(sender_id, f'Creating a new alert at {price_point} on pair {sele_pair}', [[{'text':'Done', 'callback_data':'Back'}]]) cu_price = price(sele_pair) if pri_point > cu_price: cu_alerts = database.all_up(sender_id, sele_pair, cur) if cu_alerts == 'Nothing': cu_alerts = '' cu_alerts += f'{pri_point}' else: cu_alerts += f' {pri_point}' database.add_up(sender_id, sele_pair, cu_alerts, cur) elif pri_point < cu_price: cu_alerts = database.all_down(sender_id, sele_pair, cur) if cu_alerts == 'Nothing': cu_alerts = '' cu_alerts += f'{pri_point}' else: cu_alerts += f' {pri_point}' database.add_down(sender_id, sele_pair, cu_alerts, cur) elif pri_point == cu_price: bot.send_message_four(sender_id, 'Alert Price cannot be same as the current price\\. Try Again', [[{'text':'Done', 'callback_data':'Back'}]]) bot.get_updates(offset = update_id+1) del alert[sender_id] bot.get_updates(offset = update_id+1) except: bot.send_message_four(sender_id, 'Text is not a digit\\. Enter a valid numner', [[{'text':'Done', 'callback_data':'Back'}]]) bot.get_updates(offset = update_id+1) if text.startswith(database.special('mass', cur)): message = text.split(' ')[1:] full_text = '' for i in message: full_text += f'{i} ' for i in special: full_text = full_text.replace(i, f'\\{i}') all_user = database.all_users(cur) for i in all_user: bot.send_message(i, full_text) bot.get_updates(offset = update_id+1) if sender_id in feedback: for i in special: text = text.replace(i, f'\\{i}') bot.send_message(468930122, text) database.add_feedback(sender_id, text, cur) bot.send_message_four(sender_id, 'Your feedback has been successfully recorded', [[{'text':'Done', 'callback_data':'Back'}]]) bot.get_updates(offset = update_id+1) if text.startswith('price') or text.startswith('/price') or text.startswith('Price') or text.startswith('/Price'): try: message = text.split(' ')[1:] full_text = '' for i in message: coin_price = price(i) coin_price = '%.10f'%coin_price coin_price = str(coin_price).replace('.', '\\.') full_text += f'*{i}* {coin_price}\n' bot.send_message(sender_id, full_text) bot.get_updates(offset = update_id+1) except: bot.send_message(sender_id, 'Invalid Pairs') bot.get_updates(offset = update_id+1) except Exception as e: print(e) print('got an error') pass
def bot_message_handler(current_updates, update_id, message_id, sender_id, group_id, dict_checker, cur, callback_data=0, callback=False): try: if callback == True: print(callback_data) if sender_id not in logged_in: bot.send_message(sender_id, 'Enter your password') bot.get_updates(offset=update_id + 1) else: if callback_data == 'Nothing': bot.get_updates(offset=update_id + 1) elif callback_data == 'Total Deposit': all_dep = database.all_depo(cur) if all_dep == 'Nothing': bot.edit_message_two(sender_id, message_id, 'No Deposit done yet', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) else: full_text = '' for i in all_dep: tele_first = database.first_name(i[2], cur)[0] tele_last = database.first_name(i[2], cur)[1] if len(full_text) > 3800: bot.send_message(sender_id, full_text) full_text = '' full_text += f'Telegram ID: {i[2]}\nName: {tele_first} {tele_last}\nAmount: {i[0]}\nTransaction Hash: {i[1]}\n\n' bot.send_message_four(sender_id, full_text, [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) elif callback_data == 'All User': all_use = database.all_first(cur) full_text = '' for i in all_use: if len(full_text) > 3800: bot.send_message(sender_id, full_text) full_text = '' full_text += f'Telegram ID: {i[0]}\nFirst Name: {i[1]} {i[4]}\nBalance: {i[2]}\nReferral ID: {i[3]}\n\n' bot.send_message_four(sender_id, full_text, [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) elif callback_data == 'Back': total_user = database.total_user(cur) try: total_depo = database.total_depo(cur) total_depo = format(total_depo, ',.8f') except: total_depo = 0.000 if sender_id in interest: del interest[sender_id] bot.edit_message_two( sender_id, message_id, 'Select one of the option from below', [[{ 'text': f'Total User: {total_user}', 'callback_data': 'All User' }], [{ 'text': f'Total Deposit: {total_depo} BTC', 'callback_data': 'Total Deposit' }], [{ 'text': 'Pending Withdrawal', 'callback_data': 'Pending Withdrawal' }], [{ 'text': 'Set Interest of Today', 'callback_data': 'Enter Interest' }]]) bot.get_updates(offset=update_id + 1) elif callback_data == 'Pending Withdrawal': pending_id = database.pending(cur) if pending_id == 'Nothing': bot.edit_message_two(sender_id, message_id, 'No withdrawal is pending', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) else: pending_amount = len(pending_id) full_text = f'Pending Withdrawal {pending_amount}\n\nPending Message ID: ' for i in pending_id: if len(full_text) > 3800: bot.send_message(sender_id, full_text) full_text = '' full_text += f'{i[0]},' full_text += '\n\nTo Get Full Details of a Withdrawal, send the following Command\n\n$data (Message ID)\n\nExample$data 5\n$data 38\n\nTo mark a withdrawal as Complete, send the command below\n\n$withdraw (Message ID) (transaction hash)' bot.send_message_four(sender_id, full_text, [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) elif callback_data == 'Enter Interest': bot.edit_message_two(sender_id, message_id, 'Enter interest rate in Digit', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) interest[sender_id] = 0 bot.get_updates(offset=update_id + 1) elif callback_data == 'Inte Posi': all_user = database.all_user(cur) if all_user == 'Nothing': bot.edit_message_two( sender_id, message_id, 'No ID available to send interest', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) del interest[sender_id] bot.get_updates(offset=update_id + 1) else: for i in all_user: bala = float(i[2]) inte = bala * interest[sender_id] / 100 bala = bala + inte database.update_bala(i[0], bala, cur) if i[1] == 0: pass else: ref_bala = float(database.find_bala(i[1], cur)) ref_bala += inte * 5 / 100 database.update_bala(i[1], ref_bala, cur) bot.edit_message_two(sender_id, message_id, 'Positive Interest Sent', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) database.inte_update(f'+{interest[sender_id]}', cur) del interest[sender_id] bot.get_updates(offset=update_id + 1) elif callback_data == 'Inte Nega': all_user = database.all_user(cur) if all_user == 'Nothing': bot.edit_message_two( sender_id, message_id, 'No ID available to sent interest', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) else: for i in all_user: bala = float(i[2]) inte = bala * interest[sender_id] / 100 bala = bala - inte database.update_bala(i[0], bala, cur) if i[1] == 0: pass else: ref_bala = float(database.find_bala(i[1], cur)) ref_bala -= inte * 5 / 100 database.update_bala(i[1], ref_bala, cur) bot.edit_message_two(sender_id, message_id, 'Negative Interest Sent', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) database.inte_update(f'-{interest[sender_id]}', cur) del interest[sender_id] bot.get_updates(offset=update_id + 1) else: text = current_updates['message']['text'] print(text) if text == '/start' and sender_id not in logged_in: if sender_id in interest: del interest[sender_id] bot.send_message(sender_id, 'Enter your password') bot.get_updates(offset=update_id + 1) elif text == '/start' and sender_id in logged_in: if sender_id in interest: del interest[sender_id] total_user = database.total_user(cur) try: total_depo = database.total_depo(cur) total_depo = format(total_depo, ',.8f') except: total_depo = 0.000 bot.send_message_four( sender_id, 'Select one of the option from below', [[{ 'text': f'Total User: {total_user}', 'callback_data': 'All User' }], [{ 'text': f'Total Deposit: {total_depo} BTC', 'callback_data': 'Total Deposit' }], [{ 'text': 'Pending Withdrawal', 'callback_data': 'Pending Withdrawal' }], [{ 'text': 'Set Interest of Today', 'callback_data': 'Enter Interest' }]]) bot.get_updates(offset=update_id + 1) elif sender_id not in logged_in and text != database.special( 'Pass', cur): bot.send_message(sender_id, 'Invalid Password') bot.get_updates(offset=update_id + 1) elif text == database.special('Pass', cur) and sender_id not in logged_in: bot.send_message(sender_id, 'Access Granted') bot.delete_message(sender_id, message_id) logged_in.append(sender_id) try: total_depo = database.total_depo(cur) total_depo = format(total_depo, ',.8f') except: total_depo = 0.000 total_user = database.total_user(cur) bot.send_message_four( sender_id, 'Select one of the option from below', [[{ 'text': f'Total User: {total_user}', 'callback_data': 'All User' }], [{ 'text': f'Total Deposit: {total_depo} BTC', 'callback_data': 'Total Deposit' }], [{ 'text': 'Pending Withdrawal', 'callback_data': 'Pending Withdrawal' }], [{ 'text': 'Set Interest of Today', 'callback_data': 'Enter Interest' }]]) bot.get_updates(offset=update_id + 1) elif text.startswith('$data') and sender_id in logged_in: data = text.split(' ')[1] history = database.find_history_two(int(data), cur) full_text = '' for i in history: da_ti = datetime.fromtimestamp(float(i[4])) if i[0] == 'Deposit': tele_first = database.first_name(i[5], cur)[0] tele_last = database.first_name(i[5], cur)[1] full_text += f'Type: {i[0]}\nTelegram ID: {i[5]}\nName: {tele_first} {tele_last}\nTransaction Hash: {i[1]}\nAmount: {i[3]} BTC\nTime: {da_ti}' bot.send_message_four(sender_id, full_text, [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) elif i[0] == 'Withdraw': tele_first = database.first_name(i[5], cur)[0] tele_last = database.first_name(i[5], cur)[1] full_text += f'Type: {i[0]}\nTelegram_ID: {i[5]}\nName: {tele_first} {tele_last}\nTransaction Hash: {i[1]}\nAmount: {i[3]} BTC\nTime: {da_ti}' bot.send_message(sender_id, full_text) bot.send_message_four(sender_id, f'{i[2]}', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) elif text.startswith('$withdraw') and sender_id in logged_in: data = text.split(' ') database.update_trans(data[1], data[2], cur) bot.send_message_four(sender_id, 'Transaction Updated', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) elif sender_id in interest and sender_id in logged_in: try: inte = float(text) interest[sender_id] = inte bot.send_message_four( sender_id, f'Interest Rate {inte}. Interest Positive or Negative?', [[{ 'text': 'Positive', 'callback_data': 'Inte Posi' }, { 'text': 'Negative', 'callback_data': 'Inte Nega' }], [{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) except: bot.send_message_four(sender_id, 'Not a Digit. Try again', [[{ 'text': 'Back', 'callback_data': 'Back' }]]) bot.get_updates(offset=update_id + 1) except Exception as e: print(e) print('got an error') bot.get_updates(offset=update_id + 1) pass
send = requests.post(self.api_url + function, fieldss) return send def edit_message_two (self, chat_id, message_id, text, reply_markup, disable_web_page_preview=True, parse_mode='MarkdownV2'): reply_markup = json.dumps({'inline_keyboard': reply_markup}) fieldss = {'chat_id': chat_id, 'message_id': message_id, 'text': text, 'parse_mode':parse_mode, 'reply_markup':reply_markup, 'disable_web_page_preview':disable_web_page_preview} function = 'editMessageText' send = requests.post(self.api_url + function, fieldss) #print(send.json()) return send details = sys.argv[1:] conn = mysql.connector.connect(host=details[0],user=details[1],database=details[2],password=details[3], autocommit=True) cur = conn.cursor() token = database.special('api', cur) bi_pub = database.special('bi pub', cur) bi_pri = database.special('bi pri', cur) client = Client(bi_pub, bi_pri, {'timeout':5}) offset = 0 special = ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'] for_price = database.available_pairs('price', cur) feedback = [] alert = {} bot = BoilerPlate(token) def price(coin, client=client): try: price = client.get_avg_price(symbol=coin)['price'] return float(price)