def handle_ref_program(message): chat = message.chat users_db = Users_db(project_variables.DB_NAME) is_eng = users_db.select_stats_field(chat.id, 'is_eng') ref_program_info = users_db.select_ref_all(chat.id) users_db.close() if is_eng: text = "Earned total: *{:.2f} USD*\nEarned total: *{:.8f} BTC*\n\nInvited in 1st line: *{}*\nInvited in 2nd " \ "line: *{}*\nInvited in 3rd line: *{}*\n\nEarned from 1st line: *{:.2f} USD*\nEarned from 1st line: *{" \ ":.8f} BTC*\n\nEarned from 2nd line: *{:.2f} USD*\nEarned from 2nd line: *{:.8f} BTC*\n\nEarned from " \ "3rd line: *{:.2f} USD*\nEarned from 3rd line: *{:.8f} BTC*\n\nYour id in Telegram: *{}* " else: text = "Прибыль вообщем: *{:.2f} USD*\nПрибыль вообщем: *{:.8f} BTC*\n\nПриглашенных в 1-ой линии: *{" \ "}*\nПриглашенных во 2-ой линии: *{}*\nПриглашенных в 3-ей линии: *{}*\n\nПрибыль с 1-ой линии: *{" \ ":.2f} USD*\nПрибыль с 1-ой линии: *{:.8f} BTC*\n\nПрибыль со 2-ой линии: *{:.2f} " \ "USD*\nПрибыль со 2-ой линии: *{:.8f} BTC*\n\nПрибыль с 3-ей линии: *{:.2f} USD*\nПрибыль с " \ "3-ей линии: *{:.8f} BTC*\n\nВаш id в Telegram: *{}*" ref_program_info = tuple( map(lambda line: 0 if line is None else line, ref_program_info)) try: bot.send_message( chat.id, text.format( ref_program_info[2] + ref_program_info[4] + ref_program_info[6], utils.to_bitcoin(ref_program_info[3] + ref_program_info[5] + ref_program_info[7]), ref_program_info[8], ref_program_info[9], ref_program_info[10], ref_program_info[2], utils.to_bitcoin(ref_program_info[3]), ref_program_info[4], utils.to_bitcoin(ref_program_info[5]), ref_program_info[6], utils.to_bitcoin(ref_program_info[7]), chat.id), reply_markup=utils.get_keyboard("ref_program_keyboard", is_eng), parse_mode="Markdown") except telebot.apihelper.ApiException: pass
def handle_withdraw_currency(call): chat = call.message.chat users_db = Users_db(project_variables.DB_NAME) is_eng = users_db.select_stats_field(chat.id, 'is_eng') keyboard = None if call.data == "💸 BTC": balance_btc = users_db.select_stats_field(chat.id, 'balance_btc') users_db.close() if balance_btc < project_variables.MIN_WITHDRAW_BTC: if is_eng: text = "You don't have enough money to withdraw\nMinimum is *{:.8f} BTC*" else: text = "У вас нехватает средств для вывода\nМинимальная сумма: *{:.8f} BTC*" text = text.format( utils.to_bitcoin(project_variables.MIN_WITHDRAW_BTC)) else: if is_eng: text = "🅱 Type in desired amount:\nMinimum is *{:.8f} BTC*\nCurrent bitcoin fee is *{:.8f} BTC*" else: text = "🅱 Укажите желаемую сумму\nМинимальная сумма: *{:.8f} BTC*\nТекущая коммисия, при отправке " \ "bitcoin: *{:.8f} BTC*" cur_fee = coinbase_functions.get_cur_fee() text = text.format( utils.to_bitcoin(project_variables.MIN_WITHDRAW_BTC), utils.to_bitcoin(cur_fee)) keyboard = telebot.types.ForceReply(selective=False) else: balance = users_db.select_stats_field(chat.id, 'balance') users_db.close() if balance < project_variables.MIN_WITHDRAW_USD: if is_eng: text = "You don't have enough money to withdraw\nMinimum is *{} USD*" else: text = "У вас нехватает средств для вывода\nМинимальная сумма: *{} USD*" text = text.format(project_variables.MIN_WITHDRAW_USD) else: text = "Choose payment system:" if is_eng else "Выберете платежную систему:" keyboard = utils.get_keyboard("pay_sys_keyboard") try: bot.send_message(chat.id, text, reply_markup=keyboard, parse_mode="Markdown") except telebot.apihelper.ApiException: pass
def handle_withdraw(call): chat = call.message.chat users_db = Users_db(project_variables.DB_NAME) is_eng = users_db.select_stats_field(chat.id, 'is_eng') balance = users_db.select_stats_field(chat.id, 'balance') balance_btc = users_db.select_stats_field(chat.id, 'balance_btc') users_db.close() keyboard = None if balance < project_variables.MIN_WITHDRAW_USD and balance_btc < project_variables.MIN_WITHDRAW_BTC: if is_eng: text = "You don't have enough money to withdraw\nMinimum is *{} USD* or *{:.8f} BTC*" else: text = "У вас нехватает средств для вывода\nМинимальная сумма: *{} USD* or *{:.8f} BTC*" text = text.format( project_variables.MIN_WITHDRAW_USD, utils.to_bitcoin(project_variables.MIN_WITHDRAW_BTC)) else: if is_eng: text = "Choose currency:" else: text = "Выберете валюту:" keyboard = utils.get_keyboard("withdraw_currency") try: bot.send_message(chat.id, text, reply_markup=keyboard, parse_mode="Markdown") except telebot.apihelper.ApiException: pass
def handle_refill_btc(call): chat = call.message.chat users_db = Users_db(project_variables.DB_NAME) address = users_db.select_addr_address(chat.id)[0] if address is None: address = coinbase_functions.generate_address() users_db.update_addr_by_user(chat.id, address) is_eng = users_db.select_stats_field(chat.id, 'is_eng') users_db.close() if is_eng: text = "*Minimal amount is {:.8f} BTC*\nYou can send desired amount of BTC and the bot will automatically" \ " charge them to your deposit.\nSend only one transaction to this address:\n`{}`\nNote that BTC " \ "transfers are not instant" else: text = "*Минимальная сумма: {:.8f} BTC*\nВы можете отправить желаемую сумму BTC и бот автоматически занесет её " \ "в ваш депозит.\nОтправляйте только одну транзакцию на этот адрес:\n`{}`\nОбратите внимание, что" \ " переводы BTC осуществляются не моментально." try: bot.send_message( chat.id, text.format(utils.to_bitcoin(project_variables.MIN_REFILL_BTC), address), parse_mode="Markdown") except telebot.apihelper.ApiException: pass
def send_money(address, amount, is_eng): balance = get_balance() if amount > balance: if not is_eng: response = "Технические неполадки в платежной системе, попробуйте позже" else: response = "There is technical problems in payment system, try again later" else: cur_fee = get_cur_fee() if amount <= cur_fee: response = "Amount is below the fee" if is_eng else "Сумма вывода меньше коммисии" else: amount -= cur_fee try: primary_account.send_money(to=address, amount="{:.8f}".format( to_bitcoin(amount)), currency="BTC") except APIError as e: error = str(e) semicolon = error.find(':') if semicolon == -1: if is_eng: response = "Something went wrong. Check validity of your requisites or try again later" else: response = "Что-то пошло не так. Проверьте правильность введеных реквизитов или повторите " \ "попытку позднее " else: response = error[semicolon + 1:] else: response = "Withdraw completed successfully!" if is_eng else "Вывод завершен успешно!" return response
def balance_command(message): if message.chat.id != project_variables.HOST_ID: return try: bot.send_message( project_variables.HOST_ID, "{:.8f}".format( utils.to_bitcoin(coinbase_functions.get_balance()))) except telebot.apihelper.ApiException: pass
def handle_statistics(message): chat = message.chat users_db = Users_db(project_variables.DB_NAME) user_stats = users_db.select_stats(chat.id) users_db.close() is_eng = user_stats[7] if is_eng: text = "Your balance: *{:.2f} USD*\nYour balance: *{:.8f} BTC*\n\nSum of your investments: *{:.2f} USD*\nSum " \ "of your investments: *{:.8f} BTC*" else: text = "Ваш баланс: *{:.2f} USD*\nВаш баланс: *{:.8f} BTC*\n\nСумма ваших инвестиций: *{:.2f} USD*\nСумма " \ "ваших инвестиций: *{:.8f} BTC*" try: bot.send_message(chat.id, text.format(user_stats[1], utils.to_bitcoin(user_stats[2]), user_stats[3], utils.to_bitcoin(user_stats[4])), reply_markup=utils.get_keyboard( "balance_keyboard", user_stats[7]), parse_mode="Markdown") except telebot.apihelper.ApiException: pass
def handle_withdraw_btc_entered(message): chat = message.chat try: amount = utils.to_satoshi(float(message.text.strip())) except ValueError: amount = -1 users_db = Users_db(project_variables.DB_NAME) is_eng = users_db.select_stats_field(chat.id, 'is_eng') requisite = users_db.select_requisite(chat.id, 'bitcoin') balance_btc = users_db.select_stats_field(chat.id, 'balance_btc') users_db.close() keyboard = None if requisite is None: if is_eng: text = "Requisite is not provided. You can change it in settings" else: text = "Реквизит не указан. Вы можете изменить это в настройках" else: if amount > balance_btc: text = "🅱 You don't have enough money to withdraw" if is_eng else "🅱 Нехватает средств для вывода" keyboard = telebot.types.ForceReply(selective=False) elif amount >= project_variables.MIN_WITHDRAW_BTC: text = coinbase_functions.send_money(requisite, amount, is_eng) if (len(text) == 23 or len(text) == 23) and text[-1] == '!': users_db.update_stats_dec_balance(chat.id, amount, is_btc=1) else: if amount == -1: text = "🅱 Invalid amount provided" if is_eng else "🅱 Введена неправильная сумма" else: text = "🅱 Amount should be greater than *{:.8f} BTC*" if is_eng else "🅱 Сумма должна быть больше *{" \ ":.8f} BTC* " text = text.format( utils.to_bitcoin(project_variables.MIN_WITHDRAW_BTC)) keyboard = telebot.types.ForceReply(selective=False) try: bot.send_message(chat.id, text, reply_markup=keyboard, parse_mode="Markdown") except telebot.apihelper.ApiException: pass