def btc_bot_new_messages(update: Update, context: CallbackContext): message = update.message.text user_telegram_id = update.message.chat_id bot = telepot.Bot(settings.TOKEN) if ProposalBtc.objects.filter( user_telegram_id=user_telegram_id).count() == 1: proposal_btc = ProposalBtc.objects.get( user_telegram_id=user_telegram_id) if not proposal_btc.is_count: try: value = float(message.replace(',', '.')) if proposal_btc.buy: exchange_points = ExchangePoint.objects.filter( sells__gte=value) else: exchange_points = ExchangePoint.objects.filter( stocks__gte=value) if exchange_points: keyboard = [] for exchange_point in exchange_points: keyboard.append([ InlineKeyboardButton(text=exchange_point.name, callback_data='ep {}'.format( exchange_point.name)) ]) keyboard = InlineKeyboardMarkup(inline_keyboard=keyboard) proposal_btc.count = value proposal_btc.save() bot_message = 'Теперь выбери точку обмена' bot.sendMessage(user_telegram_id, bot_message, reply_markup=keyboard) else: bot_message = 'У точек нет столько денег :с\nПопробуй ввести сумму меньше' bot.sendMessage(user_telegram_id, bot_message) except ValueError: bot_message = 'Я тебя не понял, попробуй написать сумму еще раз' bot.sendMessage(user_telegram_id, bot_message) elif not proposal_btc.is_date: keyboard = [] for number in range(20): if number % 5 == 0: keyboard.append([]) keyboard[number // 5].append( InlineKeyboardButton( text=(datetime.today() + timedelta(days=number)).strftime("%d.%m"), callback_data='date {}'.format(number))) keyboard = InlineKeyboardMarkup(inline_keyboard=keyboard) bot_message = 'Отлично! Теперь выбери дату визита' bot.sendMessage(user_telegram_id, bot_message, reply_markup=keyboard) elif not proposal_btc.is_time: keyboard = [] for number in range(12): if number % 4 == 0: keyboard.append([]) keyboard[number // 4].append( InlineKeyboardButton( text='{}:00'.format(number + 9), callback_data='time {}'.format(number))) keyboard = InlineKeyboardMarkup(inline_keyboard=keyboard) bot_message = 'Осталось выбрать время визита' bot.sendMessage(user_telegram_id, bot_message, reply_markup=keyboard) elif not proposal_btc.is_number: if len(message) < 11: bot_message = 'Я не понимаю твоего номера' else: proposal_btc.user_number = message proposal_btc.is_number = True proposal_btc.save() bot_message = 'Ура! Твоя заявка готова' bot.sendMessage(user_telegram_id, bot_message) else: bot.sendMessage(user_telegram_id, 'Заявка уже создана') else: if message == '/start' or message == 'начать': bot_message = 'Привет, я бот по обмену крипты :)\nЧто ты хочешь сделать?' keyboard = InlineKeyboardMarkup(inline_keyboard=[[ InlineKeyboardButton(text='Купить', callback_data='buy'), InlineKeyboardButton(text='Продать', callback_data='sell') ]]) bot.sendMessage(chat_id=user_telegram_id, text=bot_message, reply_markup=keyboard) else: bot_message = 'Я тебя не понял, воспользуйся кнопкой ниже, чтобы начать обмен' keyboard = InlineKeyboardMarkup(inline_keyboard=[[ InlineKeyboardButton(text='Начать', callback_data='start') ]]) bot.sendMessage(chat_id=user_telegram_id, text=bot_message, reply_markup=keyboard)
def Unlock(self): # Unlock global Select_Group global Select_Button try: Bot.deleteMessage( (self.Chat_ID, self.Message['message']['message_id'])) except: pass Chats = blocked.ChatFind(self.Chat_ID) if Chats[0] == True and self.Message_Type == 'Chat': try: Bot.deleteMessage( (self.Chat_ID, self.Message['message']['message_id'])) except: pass if not self.Chat_ID in Select_Button.keys(): return False if Select_Button[self.Chat_ID] == 'unlock_info' and self.Message[ 'text'].count('-') == 7: Ref = moderation.CheckRef(self.Message['text']) print(Ref) if Ref[0] == True and blocked.Check(self.Chat_ID)[0] == True: if not self.Chat_ID in Select_Group.keys(): return None Group_ID = Select_Group[self.Chat_ID] Get_Chat = Bot.getChat(Group_ID) if 'username' in Get_Chat.keys(): ChatLink = 'https://t.me/' + Get_Chat['username'] else: ChatLink = Bot.exportChatInviteLink(Group_ID) FirstName = Get_Chat['title'].split()[0].title() Message = '🎉 [ Desbloqueado ]\n\n' Message += '📌 Parabéns! Seu acesso ao grupo {0} foi desbloqueado 😁\n\n'.format( FirstName) Message += '- x - \n\n' Keyboard = InlineKeyboardMarkup( inline_keyboard=[[ InlineKeyboardButton(text='Voltar ao Grupo', url=ChatLink) ], [ InlineKeyboardButton( text='Voltar ao Menu', callback_data='back_to_menu') ]]) blocked.Unlock(Group_ID, self.Chat_ID) try: Bot.restrictChatMember(Group_ID, self.Chat_ID, can_send_messages=True, can_send_other_messages=True) except: pass return Bot.sendMessage(self.Chat_ID, Message, reply_markup=Keyboard) elif Chats[0] in [True, False] and self.Message_Type == 'Callback': if re.findall('\-[\d]+', self.Query_Data) and Select_Button[ self.Chat_ID] == 'unlock_group_list': Name = self.Message['message']['chat']['first_name'] Name = str(Name).split()[0].title() Message = '🎉 [ Desbloquear Meu Acesso ]' Message += '\n\n📌 {0}! Preciso que você me envie o código de referência que você recebeu de um de nossos administradores 😀'.format( Name) Message += '\n\nExemplo ➡️ 2CRT-71AB-C790-XXXX-XXX-30D2-XXXX-XXX-XXX-XXX' Message += '\n\n - x - \n\n' Keyboard = InlineKeyboardMarkup(inline_keyboard=[[ InlineKeyboardButton(text='Voltar ao Menu', callback_data='back_to_menu') ]]) Select_Button[self.Chat_ID] = 'unlock_info' Select_Group[self.Chat_ID] = self.Query_Data return Bot.sendMessage(self.Chat_ID, Message, reply_markup=Keyboard) elif self.Query_Data == 'unlock': Keyboard = [] for Chat in Chats: if not Chat in [True, False]: name = str( Bot.getChat(Chat)['title']).split()[0].title() Keyboard.append( InlineKeyboardButton(text=str(name) + ' ✔️', callback_data=str(Chat))) Message = '🎉 [ Desbloquear Conta ]\n\n' Message += '📌 Escolha o grupo que você deseja inserir o código de referência 😀\n\n' Message += ' - x - \n\n' Keyboard = InlineKeyboardMarkup(inline_keyboard=[ Keyboard, [ InlineKeyboardButton(text='Voltar ao Menu', callback_data='back_to_menu') ] ]) if Chats[0] == True: Select_Button[self.Chat_ID] = 'unlock_group_list' return Bot.sendMessage(self.Chat_ID, Message, reply_markup=Keyboard)
def btc_bot_edit_messages(update: Update, context: CallbackContext): query = update.callback_query button_press = query.data edit_message = (query.message.chat_id, query.message.message_id) user_telegram_id = query.message.chat_id bot = telepot.Bot(settings.TOKEN) if 'start' in button_press: try: bot.deleteMessage(edit_message) except telepot.exception.TelegramError: pass finally: bot_message = 'Привет, я бот по обмену крипты :)\nДля что ты хочешь сделать?' keyboard = InlineKeyboardMarkup(inline_keyboard=[[ InlineKeyboardButton(text='Купить', callback_data='buy'), InlineKeyboardButton(text='Продать', callback_data='sell') ]]) bot.sendMessage(chat_id=user_telegram_id, text=bot_message, reply_markup=keyboard) elif 'buy' in button_press: try: bot.deleteMessage(edit_message) except telepot.exception.TelegramError: pass finally: percent = got_now_btc_run() * 0.015 bot_text = "Текущий курс: \n\n 1 BTC -> {0} RUB\n\n".format( round(got_now_btc_run() - percent, 2)) bot_text += "На какую сумму ₽ хотите купить BTC?" ProposalBtc.objects.create(user_telegram_id=user_telegram_id, buy=True) bot.sendMessage(chat_id=user_telegram_id, text=bot_text) elif 'sell' in button_press: try: bot.deleteMessage(edit_message) except telepot.exception.TelegramError: pass finally: percent = got_now_btc_run() * 0.02 bot_text = "Текущий курс: \n\n 1 BTC -> {0} RUB\n\n".format( round(got_now_btc_run() + percent, 2)) bot_text += "На какую сумму ₽ хотите продать BTC?" ProposalBtc.objects.create(user_telegram_id=user_telegram_id) bot.sendMessage(chat_id=user_telegram_id, text=bot_text) elif 'ep' in button_press: try: bot.deleteMessage(edit_message) except telepot.exception.TelegramError: pass finally: proposal_btc = ProposalBtc.objects.get( user_telegram_id=user_telegram_id) proposal_btc.point_name = button_press.split(' ')[1] proposal_btc.is_count = True proposal_btc.is_point = True proposal_btc.save() keyboard = [] for number in range(20): if number % 5 == 0: keyboard.append([]) keyboard[number // 5].append( InlineKeyboardButton( text=(datetime.today() + timedelta(days=number)).strftime("%d.%m"), callback_data='date {}'.format(number))) keyboard = InlineKeyboardMarkup(inline_keyboard=keyboard) bot_message = 'Отлично! Теперь выбери дату визита' bot.sendMessage(user_telegram_id, bot_message, reply_markup=keyboard) elif 'date' in button_press: try: bot.deleteMessage(edit_message) except telepot.exception.TelegramError: pass finally: proposal_btc = ProposalBtc.objects.get( user_telegram_id=user_telegram_id) proposal_btc.date_visit = (datetime.today() + timedelta( days=int(button_press.split(' ')[1]))).strftime("%d.%m.%y") proposal_btc.is_date = True proposal_btc.save() keyboard = [] for number in range(12): if number % 4 == 0: keyboard.append([]) keyboard[number // 4].append( InlineKeyboardButton( text='{}:00'.format(number + 9), callback_data='time {}'.format(number + 9))) keyboard = InlineKeyboardMarkup(inline_keyboard=keyboard) bot_message = 'Осталось выбрать время визита' bot.sendMessage(user_telegram_id, bot_message, reply_markup=keyboard) elif 'time' in button_press: try: bot.deleteMessage(edit_message) except telepot.exception.TelegramError: pass finally: proposal_btc = ProposalBtc.objects.get( user_telegram_id=user_telegram_id) proposal_btc.time_visit = '{}:00'.format( button_press.split(' ')[1]) proposal_btc.is_time = True proposal_btc.save() bot_message = 'Последний шаг. Введите номер телефона' bot.sendMessage(user_telegram_id, bot_message)
def Menu(self): # Menu Select_Button[self.Chat_ID] = 'Menu' if self.Message_Type == 'Callback': (Name, MessageID) = (self.Message['message']['chat'], None) try: Bot.deleteMessage( (self.Chat_ID, self.Message['message']['message_id'])) except: pass if self.Message_Type == 'Chat': (Name, MessageID) = (self.Message['chat'], self.Message['message_id']) try: Bot.deleteMessage( (self.Chat_ID, self.Message['message_id'] - 1)) except: pass Name = Name['first_name'].split()[0].title() Message = '🎉 [ Menu ]\n\n' Message = '🎉 Olá, {0}! Como posso \nte ajudar? 😀'.format(Name) Message += '\n\n- x -\n\n' if moderation.CheckMode(self.Chat_ID)[0] == True: Keyboard = InlineKeyboardMarkup(inline_keyboard=[ [ InlineKeyboardButton(text='Minha Conta', callback_data='account') ], [ InlineKeyboardButton(text='Meus Produtos', callback_data='products') ], [ InlineKeyboardButton(text='Meu Relatorio', callback_data='report') ] ]) return Bot.sendMessage(self.Chat_ID, Message, reply_to_message_id=MessageID, reply_markup=Keyboard) else: Check = blocked.Check(self.Chat_ID) Keyboard = [] if Check[0] == True: ExportChatInvitedLink = Bot.exportChatInviteLink(Check[1]) Keyboard.append( InlineKeyboardButton(text='Voltar ao Grupo', url=ExportChatInvitedLink)) Keyboard = InlineKeyboardMarkup( inline_keyboard=[[ InlineKeyboardButton(text='Desbloquear Acesso ', callback_data='unlock') ], [ InlineKeyboardButton( text='Mostrar Produtos', callback_data='show_product_user') ], Keyboard]) return Bot.sendMessage(self.Chat_ID, Message, reply_to_message_id=MessageID, reply_markup=Keyboard)