def about(update: Update, context: CallbackContext): checkuser(update.message.chat) msg = ( "Dieser Bot wurde von @Alwinius entwickelt.\n" "Der Quellcode ist unter https://github.com/Alwinius/Bewegungsmelder-Telegram verfügbar.\n" "Weitere interessante Bots: \n - " "@mydealz\\_bot\n - @aachenmensabot") print(msg) send(context.bot, update.message.chat_id, msg)
def start(update: Update, context: CallbackContext, message_id=None): checkuser(update.message.chat) msg = "Willkommen beim Telegram-Bot des Bewegungsmelders. Über die Buttons unten kannst du nach aktuellen " \ "Veranstaltungen suchen und deine Benachrichtigungen verwalten. Informationen über diesen Bot gibt's hier " \ "/about. " reply_markup = InlineKeyboardMarkup( [[InlineKeyboardButton("📅 Veranstaltungen", callback_data="0$0")], [ InlineKeyboardButton("⏰ Benachrichtigungen", callback_data="3"), InlineKeyboardButton("🗂️ Filter", callback_data="4") ]]) send(context.bot, update.message.chat_id, msg, reply_markup, message_id)
def send_weekly_notifications(bot=None): if bot is None: bot = Bot(token=config['BotToken']) reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📅 Veranstaltungen", callback_data="0$0"), InlineKeyboardButton("⏰ Benachrichtigungen ändern", callback_data="3") ]]) session = Session() users = session.query(User) \ .filter((User.notify_schedule == Schedule.WEEKLY) | (User.notify_schedule == Schedule.WEEKLYANDDAILY)) for user in users: user.counter += 1 session.commit() msg = get_week(user.id) if msg is not None: send(bot, user.id, msg, reply_markup=reply_markup) session.close()
def inline_callback(update: Update, context: CallbackContext): message: Message = update.callback_query.message checkuser(message.chat) args: List[str] = update.callback_query.data.split("$") # message structure: ID$payload # ID: H - Home # 0 - list events according to saved filters, payload: day # 1 - modify groups, payload: id, show 1 /exclude 0 # 2 - modify event categories: id, enable 1 /disable 0 # 3 - modify notifications: Schedule.name # 4 - filter overview if args[0] == "H": # this is not called by a button anymore start(update.callback_query, context, message.message_id) elif args[0] == "0": msg, _ = get_events(int(args[1]), message.chat.id) if args[1] == "0": reply_markup = InlineKeyboardMarkup( [[InlineKeyboardButton("➡️", callback_data="0$1")], [ InlineKeyboardButton("⏰ Benachrichtigungen", callback_data="3"), InlineKeyboardButton("🗂️ Filter", callback_data="4") ]]) else: reply_markup = InlineKeyboardMarkup( [[ InlineKeyboardButton("⬅️", callback_data="0$" + str(int(args[1]) - 1)), InlineKeyboardButton("➡️", callback_data="0$" + str(int(args[1]) + 1)) ], [ InlineKeyboardButton("⏰ Benachrichtigungen", callback_data="3"), InlineKeyboardButton("🗂️ Filter", callback_data="4") ]]) send(context.bot, message.chat.id, msg, reply_markup, message_id=message.message_id) elif args[0] == "4": msg, reply_markup = get_filter_overview(message.chat.id) send(context.bot, message.chat.id, msg, reply_markup, message_id=message.message_id, callback_id=update.callback_query.id) elif args[0] == "1": msg, reply_markup = process_groups(message.chat.id, args) send(context.bot, message.chat.id, msg, reply_markup, message_id=message.message_id, callback_id=update.callback_query.id) elif args[0] == "2": msg, reply_markup = process_categories(message.chat.id, args) send(context.bot, message.chat.id, msg, reply_markup, message_id=message.message_id, callback_id=update.callback_query.id) elif args[0] == "3": msg = process_notifications(message.chat.id, args) reply_markup = InlineKeyboardMarkup([ [ InlineKeyboardButton("⏰ tägliche Benachrichtigungen", callback_data="3$" + Schedule.DAILY.name) ], [ InlineKeyboardButton("📅 wöchentliche Benachrichtigungen", callback_data="3$" + Schedule.WEEKLY.name) ], [ InlineKeyboardButton("🔭 keine Benachrichtigungen", callback_data="3$" + Schedule.NONE.name) ], [ InlineKeyboardButton("📅 Veranstaltungen", callback_data="0$0"), InlineKeyboardButton("🗂️ Filter", callback_data="4") ] ]) send(context.bot, message.chat.id, msg, reply_markup, message_id=message.message_id, callback_id=update.callback_query.id) else: logging.error("unknown inline command") msg = "Kommando nicht erkannt" send(context.bot, message.chat_id, msg, message_id=message.message_id, callback_id=update.callback_query.id) dev_msg = f"Inlinekommando nicht erkannt.\n\nData: {update.callback_query.data}\nUser:{message.chat}" send_developer_message(context.bot, dev_msg)