Add listing quests / side quest details.

Sets status to eq/esq along with the qid in extra
This commit is contained in:
Ceda EI 2018-11-03 03:31:08 +05:30
parent 6fda911046
commit 48bce46990
1 changed files with 46 additions and 4 deletions

50
bot.py
View File

@ -4,7 +4,8 @@ import logging
import telegram import telegram
import sqlite3 import sqlite3
import questable import questable
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, \
RegexHandler
try: try:
import config import config
@ -153,9 +154,10 @@ def send_status(bot, update, player):
completed_side_quests = len(player.get_side_quests(1)) completed_side_quests = len(player.get_side_quests(1))
text = (f'<b>{name}</b>\n\n' text = (f'<b>{name}</b>\n\n'
f'🔥XP: {points}\n' f'<b>🔥 XP:</b> {points}\n'
f'Quests: {completed_quests}/{total_quests}\n' f'<b>⭐️ Quests:</b> {completed_quests}/{total_quests}\n'
f'💠Side Quests: {completed_side_quests}/{total_side_quests}\n') f'<b>💠 Side Quests:</b> {completed_side_quests}/'
f'{total_side_quests}\n')
chat_id = update.message.chat_id chat_id = update.message.chat_id
custom_keyboard = [ custom_keyboard = [
['Add Quest', 'Add Side Quest'], ['Add Quest', 'Add Side Quest'],
@ -193,6 +195,41 @@ def list_quests(bot, update, player, type):
bot.send_message(chat_id=chat_id, text=text, parse_mode="HTML") bot.send_message(chat_id=chat_id, text=text, parse_mode="HTML")
def quest(bot, update, player, qid, type):
if type == "quest":
x = questable.get_quest(player.DB, player.CHAT_ID, qid)
elif type == "side_quest":
x = questable.get_side_quest(player.DB, player.CHAT_ID, qid)
else:
raise ValueError('Not quest or side_quest')
text = ("<b>🗺 " + {"quest": "Quest", "side_quest": "Side Quest"}[type]
+ f":</b> {x.name}"
"\n<b>📌 Priority:</b> " + ["Low", "Medium", "High"][x.imp-1]
+ "\n<b>📘 Difficulty:</b> " + ["Low", "Medium", "High"][x.diff-1])
state = {"quest": "eq", "side_quest": "esq"}[type]
player.set_state(state, qid)
custom_keyboard = [
["Mark as done"],
["Edit Name", "Change Priority", "Change Difficulty"],
["Back"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
chat_id = update.message.chat_id
bot.send_message(chat_id=chat_id, text=text, parse_mode="HTML",
reply_markup=reply_markup)
def quest_handling(bot, update, db):
text = update.message.text.lower().split("_")
chat_id = update.message.chat_id
player = questable.player(db, chat_id)
if text[0] == "/q":
quest(bot, update, player, text[1], "quest")
elif text[0] == "/sq":
quest(bot, update, player, text[1], "side_quest")
def message_handling(bot, update, db): def message_handling(bot, update, db):
text = update.message.text.lower() text = update.message.text.lower()
player = questable.player(db, update.message.chat_id) player = questable.player(db, update.message.chat_id)
@ -205,6 +242,7 @@ def message_handling(bot, update, db):
# requested # requested
# qi / sqi: (Side) Quest importance: User has entered difficulty, # qi / sqi: (Side) Quest importance: User has entered difficulty,
# importance requested # importance requested
# eq / qsq: Edit Quest / Side Quest. the user press /Q_\d+ or /SQ_\d+
if state["state"] == "none": if state["state"] == "none":
if text == "add quest": if text == "add quest":
@ -263,4 +301,8 @@ dispatcher.add_handler(start_handler)
handler = MessageHandler(Filters.text, lambda x, y: message_handling(x, y, db)) handler = MessageHandler(Filters.text, lambda x, y: message_handling(x, y, db))
dispatcher.add_handler(handler) dispatcher.add_handler(handler)
quest_handler = RegexHandler(r"/[Ss]?[Qq]_\d+", lambda x, y:
quest_handling(x, y, db))
dispatcher.add_handler(quest_handler)
updater.start_polling() updater.start_polling()