def main_message(state: State, telegram_api: telebot.TeleBot, todoist_api: (Todoist,None), chat_id): first_run = state.last_random_todo_str == "not inited" main_markup = telebot.types.ReplyKeyboardMarkup() main_button = telebot.types.KeyboardButton('MOAR!') settings_button = telebot.types.KeyboardButton('Settings') list_button = telebot.types.KeyboardButton('List') main_markup.row(main_button) main_markup.row(settings_button, list_button) main_markup.row() if state.excluded_projects: excluded_str = f"Excluded projects: {state.excluded_projects}." else: excluded_str = "No excluded projects." if state.excluded_items: excluded_str += f"{newline}Excluded items: {state.excluded_items}." else: excluded_str += f"{newline}No excluded items." if first_run: messages = telegrame.send_message(telegram_api, chat_id=chat_id, text="Please, wait...") todo_updater(state=state, todoist_api=todoist_api, telegram_api=telegram_api, chat_id=chat_id, cnt=False) for message in messages: telegrame.delete_message(telegram_api, chat_id, message.message_id) current_todo = state.last_random_todo_str telegrame.send_message(telegram_api, chat_id=chat_id, disable_web_page_preview=True, # text=f"{excluded_str}{newline}{current_todo}") # , reply_markup=main_markup) text=current_todo, reply_markup=main_markup) state.last_todo_str = Str.substring(current_todo, "", "<", safe=True).strip() todo_updater_thread = MyThread(todo_updater, args=(state, todoist_api, telegram_api, chat_id, first_run), daemon=True, quiet=False) todo_updater_thread.start()
def reply_all_messages_ola(message): if message.chat.id == my_chat_id: if message.text: if message.text.startswith("help"): reply = "Commands not implemented now :(" else: telegram_api.forward_message(ola_chat_id, message.chat.id, message.message_id, disable_notification=True) reply = f"Forwarded to Ola: {message.text}" else: telegram_api.forward_message(ola_chat_id, message.chat.id, message.message_id, disable_notification=True) reply = f"Forwarded to Ola: [sticker]" Print.rewrite() print(reply) telegrame.send_message(telegram_api, message.chat.id, reply, disable_notification=True) else: telegram_api.forward_message(my_chat_id, message.chat.id, message.message_id, disable_notification=True) Print.rewrite() print(f"from {message.chat.id}: {message.text}")
def main_message(): State.sent_messages = 1 main_markup = telebot.types.ReplyKeyboardMarkup() main_button = telebot.types.KeyboardButton('MOAR!') settings_button = telebot.types.KeyboardButton('Settings') list_button = telebot.types.KeyboardButton('List') main_markup.row(main_button) main_markup.row(settings_button, list_button) if State.excluded_projects: excluded_str = f"Excluded projects: {State.excluded_projects}." else: excluded_str = "No excluded projects." if State.excluded_items: excluded_str += f"{newline}Excluded items: {State.excluded_items}." else: excluded_str += f"{newline}No excluded items." current_todo = State.last_radnom_todo_str telegrame.send_message( telegram_api, chat_id=message.chat.id, # text=f"{excluded_str}{newline}{current_todo}") # , reply_markup=main_markup) text=current_todo, reply_markup=main_markup) State.last_todo_str = Str.substring(current_todo, "", "<").strip() todo_updater_thread = MyThread(todo_updater, args=(todoist_api, telegram_api, message.chat.id), daemon=True, quiet=False) todo_updater_thread.start()
def _start_ola_bot_sender_mine(): while True: nowdt = datetime.datetime.now() now = nowdt.strftime("%H:%M") weekday = int(nowdt.strftime("%w")) Time.sleep(20) if now in ["11:05", "17:05" ] and State.last_sent != now and weekday in Int.from_to( 1, 5): State.last_sent = now message_text = "Егор, на кухне печеньки!" if weekday == 3: message_text = "Егор, зохавай фруктиков!" telegrame.send_message(telegram_api, my_chat_id, message_text) elif now == "16:00" and State.last_sent != now: State.last_sent = now message_text = "Сходи, покушой, зоебал сидеть!" telegrame.send_message(telegram_api, my_chat_id, message_text)
def message_hanlder(message): # init vars chat_id = message.chat.id message_id = message.message_id try: print(chat_id, message_id, message.text) except: print(chat_id, message_id) # actual logic try: count = int(message.text) except ValueError: count = 1 integers = [] for i in range(count): integer = int(File.read(last_int_path)) while not archived_nums.check_archive(integer): integer += 1 File.write(last_int_path, integer, mode="w") integers.append(str(integer)) markup = telebot.types.ReplyKeyboardMarkup() more_button = telebot.types.KeyboardButton("Ещё одну") i2_button = telebot.types.KeyboardButton("2") i5_button = telebot.types.KeyboardButton("5") i10_button = telebot.types.KeyboardButton("10") i100_button = telebot.types.KeyboardButton("100") markup.row(more_button) markup.row(i2_button, i5_button, i10_button, i100_button) telegrame.send_message(telegram_api, chat_id, f"{newline.join(integers)}", reply_markup=markup)
def start_message(message): markup = telebot.types.ReplyKeyboardMarkup() more_button = telebot.types.KeyboardButton("Номер карточки!") i2_button = telebot.types.KeyboardButton("2") i5_button = telebot.types.KeyboardButton("5") i10_button = telebot.types.KeyboardButton("10") i100_button = telebot.types.KeyboardButton("100") markup.row(more_button) markup.row(i2_button, i5_button, i10_button, i100_button) telegrame.send_message( telegram_api, message.chat.id, f"Приветствую в боте для выдачи номеров карт! Укажите цифрой нужное вам количество номеров, " f"или воспользуйтесь специальной клавиатурой для этого. Приятного использования!", reply_markup=markup)
def reply_all_messages(message): if message.chat.id == my_chat_id: if message.text: print(fr"input: {message.text}") if message.text.lower().startswith("help"): reply = "no help in here" message_obj = telegrame.send_message( telegram_api, message.chat.id, reply, disable_notification=True) elif message.text.lower() == "привет!": reply = "Ну что там у тебя?" message_obj = telegrame.send_message( telegram_api, message.chat.id, reply, disable_notification=True) elif message.text.lower() == "пока": reply = "Ну бывай" message_obj = telegrame.send_message( telegram_api, message.chat.id, reply, disable_notification=True) elif message.text.lower() == "как твои?": for obj in State.saved: if File.exist(obj): photo = open(obj, 'rb') telegram_api.send_photo(message.chat.id, photo) reply = "Ну бывай" message_obj = telegrame.send_message( telegram_api, message.chat.id, reply, disable_notification=True) else: reply = "Unknown command, enter 'help'" message_obj = telegrame.send_message( telegram_api, message.chat.id, reply, disable_notification=True) else: reply = "Stickers doesn't supported" message_obj = telegrame.send_message(telegram_api, message.chat.id, reply, disable_notification=True) else: telegram_api.forward_message(my_chat_id, message.chat.id, message.message_id, disable_notification=True) Print.rewrite() print(f"from {message.chat.id}: {message.text}")
def reply_all_messages(message): if message.chat.id == my_chat_id: if message.text.lower().startswith("t "): try: State.timeout = Str.get_integers(message.text)[0] telegrame.send_message(telegram_api, my_chat_id, f"set timeout to {State.timeout}") except IndexError: telegrame.send_message(telegram_api, my_chat_id, f"Failed change timeout {State.timeout}") elif message.text.lower().startswith("cd"): try: os.chdir(message.text[3:]) telegrame.send_message(telegram_api, my_chat_id, f"Dir changed to {Path.working()}") except Exception as e: telegrame.send_message(telegram_api, my_chat_id, str(e)) else: print(f"running {message.text}") telegrame.send_message(telegram_api, my_chat_id, f"running {message.text}") # output, err = Console.get_output("ping 8.8.8.8", pureshell=True, return_merged=False, timeout=2, # decoding="cp866", print_std=True) try: output, err = Console.get_output(message.text, return_merged=False, timeout=State.timeout, print_std=True) if not output and not err: output = "Done!" except FileNotFoundError: try: output, err = Console.get_output(message.text, return_merged=False, timeout=State.timeout, print_std=True, pureshell=True) if not output and not err: output = "Done!" except Exception as e: telegrame.send_message(telegram_api, my_chat_id, str(e)) output, err = "", "" except Exception as e: telegrame.send_message(telegram_api, my_chat_id, str(e)) output, err = "", "" if err: output += newline + "ERROR:" + newline + err message_chunks = Str.split_every(output.replace(newline, "{newline}").replace(newline2, "{newline}"), 4096) for chunk in message_chunks: chunk = chunk.replace("{newline}", newline) if not chunk: chunk = "__nil__" telegrame.send_message(telegram_api, my_chat_id, chunk) else: telegrame.send_message(telegram_api, message.chat.id, "ACCESS DENIED")
def _start_ola_bot_sender(): while True: nowdt = datetime.datetime.now() now = nowdt.strftime("%H:%M") Time.sleep(20) if now == "08:00" and State.last_sent != now: State.last_sent = now message_text = "Завтрак это важно и полезно, мне мама так говор... ой, у меня же нет мамы, я программка :(" telegrame.send_message(telegram_api, ola_chat_id, message_text) telegrame.send_message(telegram_api, my_chat_id, message_text) elif now == "14:00" and State.last_sent != now: State.last_sent = now message_text = f"Ну давай, поешь, ну чего ты? Nani the fucc???" telegrame.send_message(telegram_api, ola_chat_id, message_text) telegrame.send_message(telegram_api, my_chat_id, message_text) elif now == "20:00" and State.last_sent != now: State.last_sent = now message_text = "Девять из десяти диетологов рекомендуют есть после шести." telegrame.send_message(telegram_api, ola_chat_id, message_text) telegrame.send_message(telegram_api, my_chat_id, message_text)
def reply_all_messages(message): def main_message(): State.sent_messages = 1 main_markup = telebot.types.ReplyKeyboardMarkup() main_button = telebot.types.KeyboardButton('MOAR!') settings_button = telebot.types.KeyboardButton('Settings') list_button = telebot.types.KeyboardButton('List') main_markup.row(main_button) main_markup.row(settings_button, list_button) if State.excluded_projects: excluded_str = f"Excluded projects: {State.excluded_projects}." else: excluded_str = "No excluded projects." if State.excluded_items: excluded_str += f"{newline}Excluded items: {State.excluded_items}." else: excluded_str += f"{newline}No excluded items." current_todo = State.last_radnom_todo_str telegrame.send_message( telegram_api, chat_id=message.chat.id, # text=f"{excluded_str}{newline}{current_todo}") # , reply_markup=main_markup) text=current_todo, reply_markup=main_markup) State.last_todo_str = Str.substring(current_todo, "", "<").strip() todo_updater_thread = MyThread(todo_updater, args=(todoist_api, telegram_api, message.chat.id), daemon=True, quiet=False) todo_updater_thread.start() if message.chat.id != my_chat_id: telegrame.send_message(telegram_api, message.chat.id, "ACCESS DENY!") return if State.getting_project_name: if message.text == "Cancel": pass else: message_text = message.text.strip() if message_text in State.excluded_projects: State.excluded_projects.remove(message_text) else: State.excluded_projects.append(message_text) State.getting_project_name = False main_message() elif State.getting_item_name: if message.text == "Cancel": pass else: message_text = message.text.strip() if message_text in State.excluded_items: State.excluded_items.remove(message_text) else: State.excluded_items.append(message_text) State.getting_item_name = False State._message = True main_message() elif message.text == "MOAR!": # MAIN MESSAGE main_message() elif message.text == "List": if not State.all_todo_str: get_random_todo(todoist_api, None, None) if State.all_todo_str: telegrame.send_message(telegram_api, message.chat.id, State.all_todo_str) else: telegrame.send_message(telegram_api, message.chat.id, "Todo list for today is empty!") elif message.text == "Settings": markup = telebot.types.ReplyKeyboardMarkup() project_exclude_button = telebot.types.KeyboardButton( "Exclude project") project_include_button = telebot.types.KeyboardButton( "Include project") items_exclude_button = telebot.types.KeyboardButton( "Exclude items") items_include_button = telebot.types.KeyboardButton( "Include items") clean_black_list_button = telebot.types.KeyboardButton( "Clean black list") counter_for_left_items_button = telebot.types.KeyboardButton( "Toggle left items counter") markup.row(project_exclude_button, project_include_button) markup.row(items_exclude_button, items_include_button) markup.row(clean_black_list_button) markup.row(counter_for_left_items_button) telegrame.send_message(telegram_api, message.chat.id, "Settings:", reply_markup=markup) elif message.text == "Exclude project": markup = telebot.types.ReplyKeyboardMarkup() for project_name, project_id in Dict.iterable( todoist_api.projects_all_names()): if project_name not in State.excluded_projects: project_button = telebot.types.KeyboardButton(project_name) markup.row(project_button) cancel_button = telebot.types.KeyboardButton("Cancel") markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me project name to exclude:", reply_markup=markup) State.getting_project_name = True elif message.text == "Include project": if State.excluded_projects: markup = telebot.types.ReplyKeyboardMarkup() for project_name in State.excluded_projects: project_button = telebot.types.KeyboardButton(project_name) markup.row(project_button) cancel_button = telebot.types.KeyboardButton("Cancel") markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me project name to include:", reply_markup=markup) State.getting_project_name = True else: telegrame.send_message(telegram_api, message.chat.id, "No excluded projects, skip...") main_message() elif message.text == "Exclude items": # main_markup = telebot.types.ForceReply(selective=False) it doesn't show up default keyboard :( markup = telebot.types.ReplyKeyboardMarkup() default_items = False default_items_list = [r"Vacuum/sweep", "Wash the floor"] if State.last_todo_str: default_items_list.append(State.last_todo_str) for item_name in default_items_list: if item_name not in State.excluded_items: project_button = telebot.types.KeyboardButton(item_name) markup.row(project_button) default_items = True if not default_items: project_button = telebot.types.KeyboardButton( "Enter item manually") markup.row(project_button) cancel_button = telebot.types.KeyboardButton("Cancel") markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me item name:", reply_markup=markup) State.getting_item_name = True elif message.text == "Include items": if State.excluded_items: markup = telebot.types.ReplyKeyboardMarkup() for item_name in State.excluded_items: project_button = telebot.types.KeyboardButton(item_name) markup.row(project_button) cancel_button = telebot.types.KeyboardButton("Cancel") markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me item name:", reply_markup=markup) State.getting_item_name = True else: telegrame.send_message(telegram_api, message.chat.id, "No excluded items, skip...") main_message() elif message.text == "Clean black list": State.excluded_items.purge() State.excluded_projects.purge() main_message() elif message.text == "Toggle left items counter": if State.counter_for_left_items: State.counter_for_left_items = False else: State.counter_for_left_items = True main_message() else: telegrame.send_message(telegram_api, message.chat.id, f"ERROR! <{message.text}>") State.sent_messages += 1 main_message()
def get_random_todo(todo_api, telegram_api, chat_id): Print.rewrite("Getting random todo") bench = Bench(prefix="Get random item in", quiet=True) bench.start() incomplete_items = todo_api.all_incomplete_items_in_account() # Print.debug(Print.prettify(incomplete_items, quiet=True)) bench.end() counter_for_left_items_int = 0 counter_all_items = 0 all_todo_str = "" for project_name, project_items in Dict.iterable( incomplete_items.copy()): # removing excluded counter_all_items += len(project_items) if project_name.strip() in State.excluded_projects: incomplete_items[project_name] = [] continue if project_items: # print(f'"{project_name}"') all_todo_str += project_name + newline for item in project_items.copy(): if item["content"].strip() in State.excluded_items: incomplete_items[project_name].remove(item) # print(f' "{item["content"]}" excluded') else: counter_for_left_items_int += 1 # print(f' "{item["content"]}"') all_todo_str += " " + item["content"] + newline for project_name, project_items in Dict.iterable( incomplete_items.copy()): # removing empty projects if not project_items: incomplete_items.pop(project_name) # Print.debug("counter_for_left_items_int", counter_for_left_items_int, # "counter_all_items", counter_all_items) # "all_todo_str", all_todo_str) State.counter_for_left_items_int = counter_for_left_items_int State.counter_all_items = counter_all_items State.all_todo_str = all_todo_str try: random_project_name, random_project_items = Random.item( incomplete_items) except IndexError: return "All done!" random_item = Random.item(random_project_items) try: if not random_item["due_date_utc"].endswith("20:59:59 +0000"): time_string = " " + random_item["date_string"] except KeyError: time_string = "" if State.counter_for_left_items and telegram_api and chat_id: counter_for_left_items_str = f"({State.counter_for_left_items_int}/{State.counter_all_items} left)" telegrame.send_message(telegram_api, chat_id, f"{counter_for_left_items_str} v{__version__}") Print.rewrite() return f"{random_item['content']} <{random_project_name}>{time_string}".replace( "> (", "> (")
def reply_all_messages(message): # init vars chat_id = message.chat.id message_id = message.message_id try: print(chat_id, message_id, message.text) except: print(chat_id, message_id) # check State object if chat_id not in Users.state: Users.state[chat_id] = State(chat_id) CurrentState = Users.state[chat_id] if message.text == CurrentState.Text.reset_api_key_and_password: # reset state CurrentState.__init__(chat_id) # delete api key Users.delete_todoist_api_key_encrypted(chat_id) # delete todoist obj Users.todoist.pop(chat_id, None) # get new todoist api key and password telegram_api.send_message(chat_id, "API key and password reset, send new Todoist API password:"******"API password key reset, send correct password:"******"Yes": Users.secrets.pop(chat_id, None) Users.todoist.pop(chat_id, None) CurrentState.getting_api_key_password = False # check Todoist object if chat_id not in Users.todoist: if not CurrentState.todoist_api_key_password: telegram_api.send_message(chat_id, "Please, enter password to encrypt Todoist API Key.\n" "For security reasons, I will not write it to disk.") if Users.get_todoist_api_key_password(chat_id): try: telegram_api.send_message(chat_id, "Probably, message with last correct password:"******"Please, enter API key for Todoist. It will be encrypted.") CurrentState.getting_api_key = True return try: decrypted_api_key = Str.decrypt(Users.get_todoist_api_key_encrypted(chat_id), CurrentState.todoist_api_key_password) except ValueError: telegram_api.send_message(chat_id, "Wrong password. Password reset.\n" "Enter password:"******"[to all]") and chat_id == my_chat_id: f = Path.safe__file__(__file__) workdir = Path.combine(os.path.split(f)[0], "configs") for file in Dir.list_of_files(workdir): if file.startswith("telegram_bot_todoist_"): try: to_chat_id = Str.get_integers(file)[0] telegram_api.forward_message(to_chat_id, chat_id, message_id) except IndexError: pass elif CurrentState.getting_project_name: if message.text == CurrentState.Text.cancel: pass else: message_text = message.text.strip() if message_text in CurrentState.excluded_projects: CurrentState.excluded_projects.remove(message_text) else: CurrentState.excluded_projects.append(message_text) CurrentState.getting_project_name = False main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif CurrentState.getting_item_name: if message.text == CurrentState.Text.cancel: pass else: message_text = message.text.strip() if message_text in CurrentState.excluded_items: CurrentState.excluded_items.remove(message_text) else: CurrentState.excluded_items.append(message_text) CurrentState.getting_item_name = False CurrentState._message = True main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == "MOAR!": # MAIN MESSAGE main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == "List": if not CurrentState.all_todo_str: get_random_todo(state=CurrentState, todoist_api=CurrentTodoistApi, telegram_api=None, chat_id=None) if CurrentState.all_todo_str: telegrame.send_message(telegram_api, message.chat.id, CurrentState.all_todo_str, disable_web_page_preview=True) else: telegrame.send_message(telegram_api, message.chat.id, "Todo list for today is empty!") elif message.text == "Settings": markup = telebot.types.ReplyKeyboardMarkup() project_exclude_button = telebot.types.KeyboardButton(CurrentState.Text.exclude_project) project_include_button = telebot.types.KeyboardButton(CurrentState.Text.include_project) items_exclude_button = telebot.types.KeyboardButton(CurrentState.Text.exclude_items) items_include_button = telebot.types.KeyboardButton(CurrentState.Text.include_items) clean_excluded_list_button = telebot.types.KeyboardButton(CurrentState.Text.clean_excluded_list) counter_for_remaining_items_button = telebot.types.KeyboardButton(CurrentState.Text.toggle_remaining_items_counter) cancel_button = telebot.types.KeyboardButton(CurrentState.Text.cancel) reset_api_key_button = telebot.types.KeyboardButton(CurrentState.Text.reset_api_key_and_password) reset_api_key_password_button = telebot.types.KeyboardButton(CurrentState.Text.reset_password_for_api_key) disable_emoji_button = telebot.types.KeyboardButton(CurrentState.Text.disable_emoji) enable_emoji_button = telebot.types.KeyboardButton(CurrentState.Text.enable_emoji) markup.row(project_exclude_button, project_include_button) markup.row(items_exclude_button, items_include_button) markup.row(clean_excluded_list_button, counter_for_remaining_items_button) markup.row(cancel_button) markup.row(reset_api_key_button, reset_api_key_password_button) markup.row(disable_emoji_button, enable_emoji_button) telegrame.send_message(telegram_api, message.chat.id, "Settings:", reply_markup=markup) elif message.text == CurrentState.Text.exclude_project: markup = telebot.types.ReplyKeyboardMarkup() for project_name, project_id in Dict.iterable(CurrentTodoistApi.projects_all_names()): if project_name not in CurrentState.excluded_projects: project_button = telebot.types.KeyboardButton(project_name) markup.row(project_button) cancel_button = telebot.types.KeyboardButton(CurrentState.Text.cancel) markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me project name to exclude:", reply_markup=markup) CurrentState.getting_project_name = True elif message.text == CurrentState.Text.include_project: if CurrentState.excluded_projects: markup = telebot.types.ReplyKeyboardMarkup() for project_name in CurrentState.excluded_projects: project_button = telebot.types.KeyboardButton(project_name) markup.row(project_button) cancel_button = telebot.types.KeyboardButton(CurrentState.Text.cancel) markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me project name to include:", reply_markup=markup) CurrentState.getting_project_name = True else: telegrame.send_message(telegram_api, message.chat.id, "No excluded projects, skip...") main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == CurrentState.Text.exclude_items: # main_markup = telebot.types.ForceReply(selective=False) it doesn't show up default keyboard :( markup = telebot.types.ReplyKeyboardMarkup() default_items = False default_items_list = [r"Vacuum/sweep", "Wash the floor"] if CurrentState.last_todo_str and CurrentState.last_todo_str not in default_items_list: default_items_list.append(CurrentState.last_todo_str) for item_name in default_items_list: if item_name not in CurrentState.excluded_items: project_button = telebot.types.KeyboardButton(item_name) markup.row(project_button) default_items = True if not default_items: project_button = telebot.types.KeyboardButton("Enter item manually") markup.row(project_button) cancel_button = telebot.types.KeyboardButton(CurrentState.Text.cancel) markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me item name:", reply_markup=markup) CurrentState.getting_item_name = True elif message.text == CurrentState.Text.include_items: if CurrentState.excluded_items: markup = telebot.types.ReplyKeyboardMarkup() for item_name in CurrentState.excluded_items: project_button = telebot.types.KeyboardButton(item_name) markup.row(project_button) cancel_button = telebot.types.KeyboardButton(CurrentState.Text.cancel) markup.row(cancel_button) telegrame.send_message(telegram_api, message.chat.id, "Send me item name:", reply_markup=markup) CurrentState.getting_item_name = True else: telegrame.send_message(telegram_api, message.chat.id, "No excluded items, skip...") main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == CurrentState.Text.clean_excluded_list: CurrentState.excluded_items.purge() CurrentState.excluded_projects.purge() main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == CurrentState.Text.toggle_remaining_items_counter: CurrentState.counter_for_remaining_items = not CurrentState.counter_for_remaining_items CurrentState.config_json["remaining_cnt"] = CurrentState.counter_for_remaining_items CurrentState.config_json.save() main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == CurrentState.Text.cancel: main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == CurrentState.Text.enable_emoji: CurrentState.Text = CurrentState.TextEmoji CurrentState.config_json["emoji"] = True CurrentState.config_json.save() main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == CurrentState.Text.disable_emoji: CurrentState.Text = CurrentState.TextNoEmoji CurrentState.config_json["emoji"] = False CurrentState.config_json.save() main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) elif message.text == "69": gifs = ['https://media3.giphy.com/media/VTnKWKVuExtYc/giphy.gif', 'https://media1.tenor.com/images/87433eeab910a8467cb23253fbed51ac/tenor.gif?itemid=4571547', 'https://i.makeagif.com/media/2-22-2015/3wrPKL.gif', 'https://thumbs.gfycat.com/ComplexUnsteadyChinesecrocodilelizard-size_restricted.gif', 'https://i.kym-cdn.com/photos/images/original/000/967/326/252.gif', 'https://thumbs.gfycat.com/GratefulBriefIberianbarbel-size_restricted.gif', 'https://media1.tenor.com/images/3738b88b7d2883f046c7f7cf1cf44d12/tenor.gif?itemid=5963604', 'http://www.gifimagesdownload.com/wp-content/uploads/2016/02/free-noice-gif-666-1.gif', 'https://media.giphy.com/media/3oEdv6KUnfOnIDmUcU/giphy.gif', 'https://i.makeagif.com/media/3-17-2015/h1Qm8Z.gif', 'http://www.gifimagesdownload.com/wp-content/uploads/2016/02/cool-noice-gif-484-1.gif', 'https://thumbs.gfycat.com/TemptingGaseousGarpike-size_restricted.gif', 'https://i.imgflip.com/k8p3a.gif', 'http://i.cubeupload.com/2lXIYI.gif', 'https://i.kym-cdn.com/photos/images/list/000/922/397/e39.gif', 'http://68.media.tumblr.com/18c85a433e657241db5e6fe44f16aac9/tumblr_inline_njzowqhntg1sqilv2.gif', 'https://media.giphy.com/media/yJFeycRK2DB4c/giphy.gif', 'https://thumbs.gfycat.com/AnimatedPoorDuckbillcat-max-1mb.gif', 'https://memebomb.net/wp-content/uploads/2019/03/nice-memes-sandboarding-.gif', 'https://thumbs.gfycat.com/BareRealLarva-small.gif', 'https://i.gifer.com/Es2m.gif', 'https://media3.giphy.com/media/gRRy5PkDTK4OQ/giphy.gif', 'https://i.ytimg.com/vi/a8c5wmeOL9o/maxresdefault.jpg', 'https://orig00.deviantart.net/d03f/f/2015/349/e/6/noice__model__michael_rosen_edition__by_doctoroctoroc-d9k8m6z.gif', 'http://33.media.tumblr.com/9550a2974ba353be964add2a6ce66504/tumblr_inline_njzoy7yiKJ1sqilv2.gif', 'https://cdn.dopl3r.com/memes_files/noice-intensifies-M6GmQ.jpg', 'https://gifimage.net/wp-content/uploads/2017/10/michael-rosen-nice-gif-8.gif', 'https://media.tenor.com/images/d8a67b9408c210c7e93923c5e5baca05/tenor.gif' ] random_gif = Random.item(gifs) texts = ["Nice!", "Noice!", "It's time to stop!", "Catch them all!1", "Do you find _that_ one?", "Yeah!", "Nice", "NiCe!", "Nooice", "Pluck!", "Noiice"] random_text = Random.item(texts) try: if random_gif.endswith(".jpg"): telegram_api.send_photo(chat_id, random_gif, caption=random_text) else: telegram_api.send_video(chat_id, random_gif, caption=random_text) except Exception as e: print(e) telegram_api.send_message(chat_id, "No gif for you! (just kidding, try again)") main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id) else: telegrame.send_message(telegram_api, message.chat.id, f"Unknown command '{message.text}'.\n" f"Please, enter one of commands: \n" f"'MOAR!' - next random command\n" f"'List' - list of all tasks\n" f"'Settings' - for change settings\n" f"'Include\Exclude project\items' to include or exclude tasks\n" f"'Clean excluded list' to include all tasks\n" f"'Toggle remaining items counter' to enable or disable sending counter of remaining items\n" f"'Reset API key and password' - change bot API key and password for it for Todoist" f"'Reset password for API key' - change password to decrypt API key for Todoist (API key stays encrypted, change only if you entered wrong password)") main_message(state=CurrentState, telegram_api=telegram_api, todoist_api=CurrentTodoistApi, chat_id=chat_id)
def _start_taskplayer_bot_sender(): while True: time.sleep(0.5) time_passed = State.current_task_timer.get() time_paused = State.get_pause_timer() time_passed -= time_paused Print( f"{time_passed=:.2f} {time_paused=:.2f} {State.pause_task_timer_started=}" ) seconds_passed = int(time_passed / 1) minutes_passed = int(time_passed / 60) seconds_all = int(State.current_task_time / 1) minutes_all = int(State.current_task_time / 60) seconds_left = seconds_all - seconds_passed minutes_left = minutes_all - minutes_passed if time_passed > State.current_task_time: State.set_next_task() if State.current_task_message_id: telegram_api.delete_message(my_chat_id, State.current_task_message_id) State.current_task_started = 0 if State.previous_task_message_id: telegram_api.delete_message(my_chat_id, State.previous_task_message_id) State.previous_task_message_id = 0 State.current_task_started = False continue if State.current_task_time >= 60: # minutes mode if not State.current_task_started: message_text = f"Task {State.current_task_name} started - {minutes_left} minutes" message_obj = send_message_with_saving(telegram_api, my_chat_id, message_text)[0] State.current_task_message_id = message_obj.message_id State.current_task_started = True State.last_sent_mins = minutes_passed elif minutes_passed != State.last_sent_mins: message_text = f"Current task is {State.current_task_name} {minutes_left} minutes left" telegram_api.edit_message_text( chat_id=my_chat_id, message_id=State.current_task_message_id, text=message_text) State.last_message_obj.text = message_text State.last_sent_mins = minutes_passed else: # seconds mode if not State.current_task_started: message_text = f"Task {State.current_task_name} started - {seconds_left} seconds" message_obj = telegrame.send_message(telegram_api, my_chat_id, message_text)[0] State.current_task_message_id = message_obj.message_id State.current_task_started = True State.last_sent_secs = seconds_passed if seconds_passed != State.last_sent_secs: message_text = f"Current task is {State.current_task_name} {seconds_left} seconds left" telegram_api.edit_message_text( chat_id=my_chat_id, message_id=State.current_task_message_id, text=message_text) State.last_sent_secs = seconds_passed print(f"{State.force_resend_message=}") if State.force_resend_message: # message_obj = telegram_api.copy_message(my_chat_id, my_chat_id, State.current_task_message_id) print(f"{State.current_task_message_id=}") if State.current_task_message_id: telegram_api.delete_message(my_chat_id, State.current_task_message_id) State.current_task_started = 0 if State.previous_task_message_id: telegram_api.delete_message(my_chat_id, State.previous_task_message_id) State.previous_task_message_id = 0 # print(f"{State.last_message_obj.text}") message_obj = telegrame.send_message( telegram_api, my_chat_id, State.last_message_obj.text + (" - paused" if State.pause_task_timer_started else ""))[0] State.previous_task_message_id = State.current_task_message_id State.current_task_message_id = message_obj.message_id State.force_resend_message = False
def reply_all_messages(message): if message.chat.id == my_chat_id: if message.text: print(fr"input: {message.text}") if message.text.lower().startswith("help") \ or message.text.lower().startswith("/help"): reply = "To set todos enter python dict with format like 'dict {'task1': 1800, 'task2': 3600}'" \ + newline reply += "To skip task, enter '/skip'" + newline reply += "To start task enter '/resume'" + newline reply += "To pause task enter '/pause'" + newline buttons = ["", "", "", ""] telegram_api.delete_message(my_chat_id, message.id) telegrame.send_message(telegram_api, my_chat_id, reply, reply_markup=main_markup) elif message.text.lower().startswith("dict "): message.text = message.text[5:] temp_dict = {} try: temp_dict = eval(message.text) except (SyntaxError, TypeError, ValueError) as e: print(e) reply = f"Cannot change dict: {str(e)}" telegrame.send_message(telegram_api, message.chat.id, reply, disable_notification=True) if temp_dict: if not Dict.isinstance_keys(temp_dict, str): temp_dict = Dict.all_keys_lambda(temp_dict, str) State.set_dict(temp_dict) else: reply = f"Cannot set empty {temp_dict} list, return to {State.task_dict}" telegrame.send_message(telegram_api, message.chat.id, reply, disable_notification=True) elif message.text.lower() == "skip" \ or message.text.lower() == "/skip": State.set_next_task() telegram_api.delete_message(my_chat_id, message.id) elif message.text.lower() == "/start": State.start_task() elif message.text.lower() == "pause" \ or message.text.lower() == "/pause": State.start_pause() telegram_api.delete_message(my_chat_id, message.id) elif message.text.lower() == "resume" \ or message.text.lower() == "/resume": State.resume_pause() telegram_api.delete_message(my_chat_id, message.id) else: reply = "Unknown command, enter '/help'" telegrame.send_message(telegram_api, message.chat.id, reply, disable_notification=True) telegram_api.delete_message(my_chat_id, message.id) else: reply = "Stickers doesn't supported" telegrame.send_message(telegram_api, message.chat.id, reply, disable_notification=True) telegram_api.delete_message(my_chat_id, message.id) else: telegram_api.forward_message(my_chat_id, message.chat.id, message.message_id, disable_notification=True) Print.rewrite() print(f"from {message.chat.id}: {message.text}")
def send_message_with_saving(*args, **kwargs): message_obj = telegrame.send_message(*args, **kwargs) State.last_message_obj = message_obj[0] return message_obj