From 6fda911046d49e87aa835884d12782446bae1f29 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Thu, 1 Nov 2018 22:54:56 +0530 Subject: [PATCH] Add List Quests/Side Quests --- bot.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bot.py b/bot.py index 3549038..2c68afe 100644 --- a/bot.py +++ b/bot.py @@ -172,6 +172,27 @@ def me_handler(bot, update, db): send_status(bot, update, player) +def list_quests(bot, update, player, type): + if type == "quest": + x = player.get_quests(0) + elif type == "side_quest": + x = player.get_side_quests(0) + else: + raise ValueError('Not quest or side_quest') + text = "List of " + {"quest": "Quests", "side_quest": + "Side Quests"}[type] + "\n" + x.sort(key=lambda i: (i.imp, -i.QID), reverse=True) + if type == "quest": + for i in x: + text += f"\n/Q_{i.QID} {i.name}" + else: + for i in x: + text += f"\n/SQ_{i.QID} {i.name}" + + chat_id = update.message.chat_id + bot.send_message(chat_id=chat_id, text=text, parse_mode="HTML") + + def message_handling(bot, update, db): text = update.message.text.lower() player = questable.player(db, update.message.chat_id) @@ -190,6 +211,10 @@ def message_handling(bot, update, db): add_quest(bot, update, player) elif text == "add side quest": add_quest(bot, update, player, "side_quest") + elif text == "list quests": + list_quests(bot, update, player, "quest") + elif text == "list side quests": + list_quests(bot, update, player, "side_quest") elif state["state"] == "aq": add_name(bot, update, player, "quest", state["extra"]) elif state["state"] == "asq":