Add more emojis. Some minor changes to UI.

This commit is contained in:
Ceda EI 2018-11-11 00:51:57 +05:30
parent 93aaebf655
commit 7b0ea8bedc
1 changed files with 59 additions and 46 deletions

105
bot.py
View File

@ -80,7 +80,7 @@ def add_name(bot, update, player, type, qid):
chat_id = update.message.chat_id chat_id = update.message.chat_id
text = "How difficult is it?" text = "How difficult is it?"
custom_keyboard = [["Low", "Medium", "High"]] custom_keyboard = [["📙 Low", "📘 Medium", "📗 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup) bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup)
@ -88,11 +88,11 @@ def add_name(bot, update, player, type, qid):
def add_diff(bot, update, player, type, qid): def add_diff(bot, update, player, type, qid):
message = update.message.text.lower() message = update.message.text.lower()
chat_id = update.message.chat_id chat_id = update.message.chat_id
if message == "low": if message == "low" or message == "📙 low":
diff = 1 diff = 1
elif message == "medium": elif message == "medium" or message == "📘 medium":
diff = 2 diff = 2
elif message == "high": elif message == "high" or message == "📗 high":
diff = 3 diff = 3
else: else:
bot.send_message(chat_id=chat_id, text="Invalid Option") bot.send_message(chat_id=chat_id, text="Invalid Option")
@ -111,7 +111,7 @@ def add_diff(bot, update, player, type, qid):
x.update_db() x.update_db()
text = "How important is it?" text = "How important is it?"
custom_keyboard = [["Low", "Medium", "High"]] custom_keyboard = [["🔹 Low", "🔸 Medium", "🔺 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup) bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup)
@ -119,11 +119,11 @@ def add_diff(bot, update, player, type, qid):
def add_imp(bot, update, player, type, qid): def add_imp(bot, update, player, type, qid):
message = update.message.text.lower() message = update.message.text.lower()
chat_id = update.message.chat_id chat_id = update.message.chat_id
if message == "low": if message == "low" or message == "🔹 low":
imp = 1 imp = 1
elif message == "medium": elif message == "medium" or message == "🔸 medium":
imp = 2 imp = 2
elif message == "high": elif message == "high" or message == "🔺 high":
imp = 3 imp = 3
else: else:
bot.send_message(chat_id=chat_id, text="Invalid Option") bot.send_message(chat_id=chat_id, text="Invalid Option")
@ -141,7 +141,7 @@ def add_imp(bot, update, player, type, qid):
x.imp = imp x.imp = imp
x.update_db() x.update_db()
text = "Quest Added!" text = {"quest": "Quest", "side_quest": "Side Quest"}[type] + " Added!"
bot.send_message(chat_id=chat_id, text=text) bot.send_message(chat_id=chat_id, text=text)
send_status(bot, update, player) send_status(bot, update, player)
@ -156,7 +156,7 @@ def send_status(bot, update, player, prefix=""):
total_side_quests = len(player.get_side_quests(None)) total_side_quests = len(player.get_side_quests(None))
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' + prefix + text = (prefix + f'<b>👤 {name}</b>\n'
f'<b>🔥 XP:</b> {points}\n' f'<b>🔥 XP:</b> {points}\n'
f'<b>⭐️ Quests:</b> {completed_quests}/{total_quests}\n' f'<b>⭐️ Quests:</b> {completed_quests}/{total_quests}\n'
f'<b>💠 Side Quests:</b> {completed_side_quests}/' f'<b>💠 Side Quests:</b> {completed_side_quests}/'
@ -190,8 +190,9 @@ def list_quests(bot, update, player, type):
{"quest": "quest", "side_quest": "side quest"}[type] + {"quest": "quest", "side_quest": "side quest"}[type] +
" ever known to me.</b>") " ever known to me.</b>")
else: else:
text = "<b>List of " + {"quest": "Quests", "side_quest": text = ("<b>" + {"quest": "📖", "side_quest": "📒"}[type] +
"Side Quests"}[type] + "</b>\n" " List of " + {"quest": "Quests", "side_quest":
"Side Quests"}[type] + "</b>\n")
x.sort(key=lambda i: (i.imp, -i.QID), reverse=True) x.sort(key=lambda i: (i.imp, -i.QID), reverse=True)
if type == "quest": if type == "quest":
for i in x: for i in x:
@ -220,7 +221,8 @@ def quest(bot, update, player, qid, type):
text = ("<b>🗺 " + {"quest": "Quest", "side_quest": "Side Quest"}[type] text = ("<b>🗺 " + {"quest": "Quest", "side_quest": "Side Quest"}[type]
+ f":</b> {x.name}" + f":</b> {x.name}"
"\n<b>📌 Priority:</b> " + ["Low", "Medium", "High"][x.imp-1] "\n<b>📌 Priority:</b> " + ["Low", "Medium", "High"][x.imp-1]
+ "\n<b>📘 Difficulty:</b> " + ["Low", "Medium", "High"][x.diff-1] + "\n<b>" + ["📙", "📘", "📗"][x.diff-1] + " Difficulty:</b> "
+ ["Low", "Medium", "High"][x.diff-1]
+ "\n<b>" + ["", ""][x.state] + " Status:</b> " + "\n<b>" + ["", ""][x.state] + " Status:</b> "
+ ["Incomplete", "Complete"][x.state]) + ["Incomplete", "Complete"][x.state])
@ -231,11 +233,11 @@ def quest(bot, update, player, qid, type):
state = {"quest": "eq", "side_quest": "esq"}[type] state = {"quest": "eq", "side_quest": "esq"}[type]
player.set_state(state, qid) player.set_state(state, qid)
custom_keyboard = [ custom_keyboard = [
["Mark as done"], ["Mark as done"],
["Edit Name", "Change Priority"], ["📝 Edit Name", "⚠️ Change Priority"],
["Change Difficulty", "Delete " + ["📚 Change Difficulty", "🗑 Delete " +
{"quest": "Quest", "side_quest": "Side Quest"}[type]], {"quest": "Quest", "side_quest": "Side Quest"}[type]],
["Back"]] ["⬅️ Back"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
chat_id = update.message.chat_id chat_id = update.message.chat_id
@ -294,19 +296,30 @@ def edit_quest(bot, update, player, qid, target, type):
if target == "name": if target == "name":
x.name = message x.name = message
text = "<b>Updated Name</b>" text = "<b>Updated Name</b>"
elif target == "imp" or target == "diff": elif target == "imp":
message = message.lower() message = message.lower()
if message != "low" and message != "medium" and message != "high": if message == "low" or message == "🔹 low":
x.imp = 1
elif message == "medium" or message == "🔸 medium":
x.imp = 2
elif message == "high" or message == "🔺 high":
x.imp = 3
else:
bot.send_message(chat_id=chat_id, text="Invalid Option") bot.send_message(chat_id=chat_id, text="Invalid Option")
return return
text = "<b>Updated Priority</b>"
elif target == "diff":
message = message.lower()
if message == "low" or message == "📙 low":
x.diff = 1
elif message == "medium" or message == "📘 medium":
x.diff = 2
elif message == "high" or message == "📗 high":
x.diff = 3
else: else:
num = {"low": 1, "medium": 2, "high": 3}[message] bot.send_message(chat_id=chat_id, text="Invalid Option")
if target == "imp": return
x.imp = num text = "<b>Updated Difficulty</b>"
text = "<b>Updated Priority</b>"
elif target == "diff":
x.diff = num
text = "<b>Updated Difficulty</b>"
x.update_db() x.update_db()
if type == "quest": if type == "quest":
@ -314,11 +327,11 @@ def edit_quest(bot, update, player, qid, target, type):
elif type == "side_quest": elif type == "side_quest":
player.set_state('esq', qid) player.set_state('esq', qid)
custom_keyboard = [ custom_keyboard = [
["Mark as done"], ["Mark as done"],
["Edit Name", "Change Priority"], ["📝 Edit Name", "⚠️ Change Priority"],
["Change Difficulty", "Delete " + ["📚 Change Difficulty", "🗑 Delete " +
{"quest": "Quest", "side_quest": "Side Quest"}[type]], {"quest": "Quest", "side_quest": "Side Quest"}[type]],
["Back"]] ["⬅️ Back"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup, bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup,
parse_mode="HTML") parse_mode="HTML")
@ -413,32 +426,32 @@ def message_handling(bot, update, db):
add_imp(bot, update, player, "side_quest", state["extra"]) add_imp(bot, update, player, "side_quest", state["extra"])
elif state["state"] == "eq": elif state["state"] == "eq":
if text == "back": if text == "back" or text == "⬅️ back":
player.set_state('none', 0) player.set_state('none', 0)
send_status(bot, update, player) send_status(bot, update, player)
elif text == "mark as done": elif text == "mark as done" or text == "✅ mark as done":
mark_as_done(bot, update, player, state["extra"], "quest") mark_as_done(bot, update, player, state["extra"], "quest")
elif text == "edit name": elif text == "edit name" or text == "📝 edit name":
player.set_state('eqn', state["extra"]) player.set_state('eqn', state["extra"])
text = "What shall the new name of the Quest be?" text = "What shall the new name of the Quest be?"
reply_markup = telegram.ReplyKeyboardRemove() reply_markup = telegram.ReplyKeyboardRemove()
bot.send_message(chat_id=player.CHAT_ID, text=text, bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup) reply_markup=reply_markup)
elif text == "change priority": elif text == "change priority" or text == "⚠️ change priority":
player.set_state('eqi', state["extra"]) player.set_state('eqi', state["extra"])
text = "How important is it?" text = "How important is it?"
custom_keyboard = [["Low", "Medium", "High"]] custom_keyboard = [["🔹 Low", "🔸 Medium", "🔺 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text, bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup) reply_markup=reply_markup)
elif text == "change difficulty": elif text == "change difficulty" or text == "📚 change difficulty":
player.set_state('eqd', state["extra"]) player.set_state('eqd', state["extra"])
text = "How difficult is it?" text = "How difficult is it?"
custom_keyboard = [["Low", "Medium", "High"]] custom_keyboard = [["📙 Low", "📘 Medium", "📗 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text, bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup) reply_markup=reply_markup)
elif text == "delete quest": elif text == "delete quest" or text == "🗑 delete quest":
quest = questable.get_quest(db, player.CHAT_ID, state["extra"]) quest = questable.get_quest(db, player.CHAT_ID, state["extra"])
quest.delete_from_db() quest.delete_from_db()
drop_state(bot, update, player) drop_state(bot, update, player)
@ -449,32 +462,32 @@ def message_handling(bot, update, db):
send_status(bot, update, player) send_status(bot, update, player)
elif state["state"] == "esq": elif state["state"] == "esq":
if text == "back": if text == "back" or text == "⬅️ back":
player.set_state('none', 0) player.set_state('none', 0)
send_status(bot, update, player) send_status(bot, update, player)
elif text == "mark as done": elif text == "mark as done" or text == "✅ mark as done":
mark_as_done(bot, update, player, state["extra"], "side_quest") mark_as_done(bot, update, player, state["extra"], "side_quest")
elif text == "edit name": elif text == "edit name" or text == "📝 edit name":
player.set_state('esqn', state["extra"]) player.set_state('esqn', state["extra"])
text = "What shall the new name of the Side Quest be?" text = "What shall the new name of the Side Quest be?"
reply_markup = telegram.ReplyKeyboardRemove() reply_markup = telegram.ReplyKeyboardRemove()
bot.send_message(chat_id=player.CHAT_ID, text=text, bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup) reply_markup=reply_markup)
elif text == "change priority": elif text == "change priority" or text == "⚠️ change priority":
player.set_state('esqi', state["extra"]) player.set_state('esqi', state["extra"])
text = "How important is it?" text = "How important is it?"
custom_keyboard = [["Low", "Medium", "High"]] custom_keyboard = [["🔹 Low", "🔸 Medium", "🔺 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text, bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup) reply_markup=reply_markup)
elif text == "change difficulty": elif text == "change difficulty" or text == "📚 change difficulty":
player.set_state('esqd', state["extra"]) player.set_state('esqd', state["extra"])
text = "How difficult is it?" text = "How difficult is it?"
custom_keyboard = [["Low", "Medium", "High"]] custom_keyboard = [["📙 Low", "📘 Medium", "📗 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text, bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup) reply_markup=reply_markup)
elif text == "delete side quest": elif text == "delete quest" or text == "🗑 delete quest":
sq = questable.get_side_quest(db, player.CHAT_ID, state["extra"]) sq = questable.get_side_quest(db, player.CHAT_ID, state["extra"])
sq.delete_from_db() sq.delete_from_db()
drop_state(bot, update, player) drop_state(bot, update, player)