def remove_admin(msg): if msg.chat.id not in storage.admin_chats: bot.send_message(msg.chat.id, loc.ADMIN_ONLY_USAGE) else: storage.admin_chats.remove(msg.chat.id) storage.save() bot.send_message(msg.chat.id, loc.ADMIN_REMOVED_MESSAGE)
def on_user_notification(self, alarm_type, next_alarm_datetime, is_first_alarm): if is_first_alarm: # Reset storage.chats_to_notify storage.chats_to_notify = storage.subscribed_chats.copy() storage.save() #text = loc.NOTIFY_LINEN_CHANGE.format(_to_printable_datetime(storage.time_next_change[1], no_date=True))\ # if not is_last_call else loc.NOTIFY_LAST_LINEN_CHANGE #for chat_id in storage.chats_to_notify: # bot.send_message(chat_id, text) text = None use_markdown = False if alarm_type == scheduler.USER_NOTIFY_TYPE_USUAL: text = loc.NOTIFY_LINEN_CHANGE_USUAL.format( _to_printable_datetime(storage.time_next_change[1], no_date=True), _to_printable_datetime(next_alarm_datetime.timestamp(), no_date=True)) # use_markdown = True elif alarm_type == scheduler.USER_NOTIFY_TYPE_1HOUR_TO_END: text = loc.NOTIFY_LINEN_CHANGE_IN_1HOUR elif alarm_type == scheduler.USER_NOTIFY_TYPE_30MIN_TO_END: text = loc.NOTIFY_LINEN_CHANGE_IN_30MIN elif alarm_type == scheduler.USER_NOTIFY_TYPE_15MIN_TO_END: text = loc.NOTIFY_LINEN_CHANGE_IN_15MIN elif alarm_type == scheduler.USER_NOTIFY_TYPE_LAST: text = loc.NOTIFY_LINEN_CHANGE_LAST for chat_id in storage.chats_to_notify: bot.send_message(chat_id, text, parse_mode="Markdown" if use_markdown else None)
def update_chat_with_changed_linen(msg): if msg.chat.id in storage.chats_to_notify: storage.chats_to_notify.remove(msg.chat.id) storage.save() bot.send_message(msg.chat.id, loc.LINEN_CHANGED_MESSAGE) else: bot.send_message(msg.chat.id, loc.LINEN_ALREADY_CHANGED_MESSAGE)
def unsubscribe(msg): chat_id = msg.chat.id if chat_id not in storage.subscribed_chats: bot.send_message(chat_id, loc.NOT_SUBSCRIBED) return storage.subscribed_chats.remove(chat_id) storage.save() bot.send_message(chat_id, loc.UNSUBSCRIBE_MESSAGE)
def subscribe(msg): chat_id = msg.chat.id if chat_id in storage.subscribed_chats: bot.send_message(chat_id, loc.ALREADY_SUBSCRIBED) return storage.subscribed_chats.append(chat_id) storage.save() bot.send_message(chat_id, loc.SUBSCRIBE_MESSAGE)
def add_admin(msg): space_index = msg.text.find(' ') key = msg.text[space_index + 1:] if space_index != -1 else '' if not key: bot.send_message(msg.chat.id, loc.ADMIN_COMMAND_ABOUT) elif key == admin_key: if msg.chat.id in storage.admin_chats: bot.send_message(msg.chat.id, loc.ALREADY_ADMIN_MESSAGE) else: storage.admin_chats.append(msg.chat.id) storage.save() bot.send_message(msg.chat.id, loc.ADMIN_ADDED_MESSAGE) else: bot.send_message(msg.chat.id, loc.WRONG_ADMIN_KEY_MESSAGE)