def subscribe(message): chat_id = message.chat.id result = scheduler.subscribe(chat_id) if result: bot.send_message(chat_id, 'You subscribed <3') else: bot.send_message(chat_id, 'You already subscribed')
def unsubscribe(message): chat_id = message.chat.id result = scheduler.unsubscribe(chat_id) if result: bot.send_message(chat_id, 'You unsubscribed') else: bot.send_message(chat_id, 'You not subscribed yet')
def change_sending_time(message): chat_id = message.chat.id if chat_id in scheduler.SUBSCRIBED_CHAT_IDS: bot.send_message( chat_id, 'When do you want to get mailing ? (Example -> 15:45)') bot.register_next_step_handler(message, handle_new_mailing_time) else: bot.send_message(chat_id, 'You have to subscribe first. Use /startsending')
def list_tests(message): tests = api.get_tests() buttons = [ telebot.types.InlineKeyboardButton( text=test.get('title'), callback_data=create_test_callback_data(test)) for test in tests ] keyboard = telebot.types.InlineKeyboardMarkup() keyboard.row(*buttons) bot.send_message(message.chat.id, "Let's select one of the available tests:", reply_markup=keyboard)
def show_leaderboard(message): users = api.get_users() leaderboard = '\n'.join( f"{user[api.USER_FIELD_USERNAME]:<20} {user[api.USER_FIELD_RATING]}" for user in users) bot.send_message(message.chat.id, f"""LEADERBOARD: ``` {leaderboard} ``` """, parse_mode="Markdown")
def next_question(call): test_result = call.data.get('test_result') test_result = api.get_test_result(test_result.get('id')) question = api.get_test_question( test_result.get('test'), test_result.get(api.RESULT_FIELD_CURRENT_ORDER_NUMBER)) keyboard = telebot.types.InlineKeyboardMarkup() test_buttons = [ telebot.types.InlineKeyboardButton( text=choice.get('text'), callback_data=create_question_callback_data(choice, test_result)) for idx, choice in enumerate(question.get('choices')) ] keyboard.row(*test_buttons) info = f'#{test_result.get(api.RESULT_FIELD_CURRENT_ORDER_NUMBER)}/{test_result.get(api.RESULT_FIELD_QUESTIONS_COUNT)}: '\ f'{question.get("text")}' bot.send_message(chat_id=call.message.chat.id, text=f'Question {info}', reply_markup=keyboard)
def next_question_on_choice_selection(call): choice_id, test_result_id = parse_question_callback_data(call.data) test_result = api.get_test_result(test_result_id) choice = api.get_choice(choice_id) question = api.get_test_question( test_result.get(api.RESULT_FIELD_TEST), test_result.get(api.RESULT_FIELD_CURRENT_ORDER_NUMBER)) payload = { 'choice_id': choice_id, api.RESULT_FIELD_CURRENT_ORDER_NUMBER: test_result.get(api.RESULT_FIELD_CURRENT_ORDER_NUMBER) } test_result = api.update_test_result(test_result_id, payload=payload) info = f'{"CORRECT 👍" if choice.get("is_correct") else "INCORRECT 😢"}' bot.edit_message_text( text= f'Answer {question.get("text")}={choice.get("text")} is given ({info})!', message_id=call.message.message_id, chat_id=call.message.chat.id) if test_result.get('get_state_display') == api.TEST_STATE_FINISHED: bot.send_message( chat_id=call.message.chat.id, text='Test is accomplished!\n'\ 'Your result is: '\ f'{test_result.get("num_correct_answers")}/{test_result.get(api.RESULT_FIELD_QUESTIONS_COUNT)}' ) else: test_result = api.update_test_result( test_result_id=test_result_id, payload={ api.RESULT_FIELD_CURRENT_ORDER_NUMBER: test_result.get(api.RESULT_FIELD_CURRENT_ORDER_NUMBER) + 1 }) call.data = {'test_result': test_result} next_question(call)
def send_anime(self): if not self.anime: bot.send_message(self.instance, "*No he encontrado nada* 😢", self.conversation) else: if self.param == 'season_list': text = "*Animes de Temporada*\n" count = 1 for anime in self.anime: text += str(count) + ". " + anime + "\n" count += 1 text += "*Elige un anime -> !anime temp {número}*" bot.send_message(self.instance, text, self.conversation) else: if len(self.anime) > 1: text = "*Resultados*\n" count = 1 for anime in self.anime: text += str(count) + ". " + anime['title'] + "\n" count += 1 text += "*Elige un anime -> !anime {número}*" waiting_respond[self.person] = self.anime bot.send_message(self.instance, text, self.conversation) else: text = "*" + str( self.anime[0]['title']) + "* \n*Estado*: " + str( self.anime[0]['status']) + "\n*Géneros*: " + str( self.anime[0] ['genres']) + "\n*Sinopsis*: " + str( self.anime[0]['description']) image_path = helper.get_image(self.anime[0]['image_url'], self.anime[0]['title']) bot.send_image(self.instance, self.conversation, image_path, text)
def start_message(message): bot.send_message(message.chat.id, 'Hi, you sent me /start') bot.send_message( message.chat.id, f"""List of available commands: /{COMMANDS_LIST_TESTS} /continue_test /{COMMANDS_LEADERBOARD} """) bot.send_message(message.chat.id, "Please, select one of commands")
def handle_new_mailing_time(message): chat_id = message.chat.id new_mailing_time = message.text if validator.is_valid_time(new_mailing_time): result = scheduler.change_mailing_time(chat_id, new_mailing_time) if result: bot.send_message(chat_id, f'Done! New mailing time set {new_mailing_time}') else: bot.send_message(chat_id, 'You have to subscribe first. Use /startsending') else: bot.send_message(chat_id, 'You dummy... Date invalid')
def send_text(message): bot.send_message(message.chat.id, 'Sorry! Did not get your request: %s' % message.text)
def send_yesno(self): bot.send_message(self.instance, "*" + self.siono + "*", self.conversation)
def check(message): current_price = fetch_price() bot.send_message(message.chat.id, f'Current price {current_price} ₴')
from app.bot import bot, dp from app.config import SERVERLESS throttled = "Too many requests, relax!" # start, help command handler @dp.message_handler( filters.Command(commands=["start", "help"], prefixes="!/", ignore_case=False)) @dp.throttled( lambda msg, loop, *args, **kwargs: loop.create_task( bot.send_message( msg.from_user.id, throttled, parse_mode=types.ParseMode.MARKDOWN, reply_to_message_id=msg.message_id, )), rate=2, ) async def cmd_start(message: types.Message) -> None: await bot.send_message( message.from_user.id, "Welcome!", parse_mode=types.ParseMode.MARKDOWN, ) # version command handler @dp.message_handler( filters.Command(commands=["v", "version"],
def send_chiste(self): bot.send_message(self.instance, self.chiste, self.conversation)
def _send_price(chat_id): current_price = fetch_price() bot.send_message(chat_id, f'Sup! Current price {current_price} ₴')
def start(message): bot.send_message(message.chat.id, 'Yoooooooo wazzzzzuuup')
def handle_message(instance, command, predicate, message_entity, who, conversation): if command == "hola": who_name = helper.sender_name(message_entity) bot.send_message(instance, "Hola *" + who_name + "*".decode('utf8'), conversation) elif command == "ayuda": answer = """*Lista de comandos*\n !hola\n !noticia <videojuegos,ciencia,series,música,actualidad>\n !chollo\n !anime <temp, temp lista, búsqueda>\n !adv\n !chiste\n !siono \n !ayuda""" bot.send_message(instance, answer, conversation) elif command == "siono": yesno = YesNo(instance, conversation) yesno.send_yesno() elif command == "anime": anime = None person = helper.get_who_send(message_entity) if predicate: if predicate == "temp": anime = Anime(instance, conversation, person, param='season') elif predicate == "temp lista": anime = Anime(instance, conversation, person, param='season_list') elif predicate.isdigit(): anime = Anime(instance, conversation, person, param='anime_num', num=predicate) else: commands = predicate.split() if len(commands) == 2 and commands[0] == "temp" and commands[ 1].isdigit(): anime = Anime(instance, conversation, person, param='season_num', num=commands[1]) # Buscar anime else: anime = Anime(instance, conversation, person, param=predicate) else: #Anime aleatorio anime = Anime(instance, conversation, person) if (anime): anime.send_anime() elif command == "chollo": chollo = Chollo(instance, conversation) chollo.build() chollo.send_chollo() # elif command == "frase": # quote = Quote(instance, conversation) # quote.send_quote() elif command == "chiste": chiste = Chiste(instance, conversation) chiste.send_chiste() # elif command == "wur": # wur = WUR(instance, conversation) # wur.build() # wur.send_wur() elif command == "adv": adv = ADV(instance, conversation) adv.send_adv() elif command == "noticia": l = ['videojuegos', 'ciencia', 'series', 'música', 'actualidad'] if predicate.encode('utf8') in l: noticia = Noticias(instance, conversation, predicate) noticia.send_noticia() #cambia la foto del perfil elif command == "fotoPerfil": path = get_avatar() bot.profile_set_picture(instance, path) #cambia el estado del perfil elif command == "estado": if predicate: bot.profile_setStatus(instance, predicate) else: #return answer = cleverbot_answer(command + " " + predicate) bot.send_message(instance, answer, conversation)
def send_noticia(self): bot.send_message( self.instance, "*" + self.noticia['title'] + "*\n" + self.noticia['body'] + "\n" + self.noticia['link'], self.conversation)
def send_adv(self): bot.send_message(self.instance, "*" + self.adv + "*", self.conversation)
def send_quote(self): bot.send_message(self.instance, "*" + self.quote + "* \n -" + self.autor, self.conversation)