1
0
mirror of https://gitlab.com/questable/questable_bot synced 2025-10-26 09:50:04 +01:00

5 Commits
1.0.1 ... 1.1

Author SHA1 Message Date
a80a7fbcc5 Add emojis. 2018-11-11 11:21:51 +05:30
7b0ea8bedc Add more emojis. Some minor changes to UI. 2018-11-11 00:52:08 +05:30
93aaebf655 Add emojis to main menu. 2018-11-10 23:40:31 +05:30
2fd5804e87 Update /help 2018-11-10 21:36:31 +05:30
0156419aed Fix typo 2018-11-10 16:00:52 +05:30

136
bot.py
View File

@@ -28,8 +28,8 @@ def start(bot, update):
text = f"Hello {name}!\n" + \
"Welcome to Questable. To get started, check /help."
custom_keyboard = [
['Add Quest', 'Add Side Quest'],
['List Quests', 'List Side Quests']
['❇️ Add Quest', '📯 Add Side Quest'],
['📜 List Quests', '📃 List Side Quests']
]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup)
@@ -80,7 +80,7 @@ def add_name(bot, update, player, type, qid):
chat_id = update.message.chat_id
text = "How difficult is it?"
custom_keyboard = [["Low", "Medium", "High"]]
custom_keyboard = [["📙 Low", "📘 Medium", "📗 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
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):
message = update.message.text.lower()
chat_id = update.message.chat_id
if message == "low":
if message == "low" or message == "📙 low":
diff = 1
elif message == "medium":
elif message == "medium" or message == "📘 medium":
diff = 2
elif message == "high":
elif message == "high" or message == "📗 high":
diff = 3
else:
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()
text = "How important is it?"
custom_keyboard = [["Low", "Medium", "High"]]
custom_keyboard = [["🔹 Low", "🔸 Medium", "🔺 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
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):
message = update.message.text.lower()
chat_id = update.message.chat_id
if message == "low":
if message == "low" or message == "🔹 low":
imp = 1
elif message == "medium":
elif message == "medium" or message == "🔸 medium":
imp = 2
elif message == "high":
elif message == "high" or message == "🔺 high":
imp = 3
else:
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.update_db()
text = "Quest Added!"
text = {"quest": "Quest", "side_quest": "Side Quest"}[type] + " Added!"
bot.send_message(chat_id=chat_id, text=text)
send_status(bot, update, player)
@@ -156,15 +156,15 @@ def send_status(bot, update, player, prefix=""):
total_side_quests = len(player.get_side_quests(None))
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>⭐️ Quests:</b> {completed_quests}/{total_quests}\n'
f'<b>💠 Side Quests:</b> {completed_side_quests}/'
f'{total_side_quests}\n')
chat_id = update.message.chat_id
custom_keyboard = [
['Add Quest', 'Add Side Quest'],
['List Quests', 'List Side Quests']
['❇️ Add Quest', '📯 Add Side Quest'],
['📜 List Quests', '📃 List Side Quests']
]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup,
@@ -187,11 +187,12 @@ def list_quests(bot, update, player, type):
raise ValueError('Not quest or side_quest')
if len(x) == 0:
text = ("<b>You have completed every " +
{"quest": "Quests", "side_quest": "Side Quests"}[type] +
{"quest": "quest", "side_quest": "side quest"}[type] +
" ever known to me.</b>")
else:
text = "<b>List of " + {"quest": "Quests", "side_quest":
"Side Quests"}[type] + "</b>\n"
text = ("<b>" + {"quest": "📖", "side_quest": "📒"}[type] +
" List of " + {"quest": "Quests", "side_quest":
"Side Quests"}[type] + "</b>\n")
x.sort(key=lambda i: (i.imp, -i.QID), reverse=True)
if type == "quest":
for i in x:
@@ -220,7 +221,8 @@ def quest(bot, update, player, qid, type):
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]
+ "\n<b>" + ["📙", "📘", "📗"][x.diff-1] + " Difficulty:</b> "
+ ["Low", "Medium", "High"][x.diff-1]
+ "\n<b>" + ["", ""][x.state] + " Status:</b> "
+ ["Incomplete", "Complete"][x.state])
@@ -231,11 +233,11 @@ def quest(bot, update, player, qid, type):
state = {"quest": "eq", "side_quest": "esq"}[type]
player.set_state(state, qid)
custom_keyboard = [
["Mark as done"],
["Edit Name", "Change Priority"],
["Change Difficulty", "Delete " +
["Mark as done"],
["📝 Edit Name", "⚠️ Change Priority"],
["📚 Change Difficulty", "🗑 Delete " +
{"quest": "Quest", "side_quest": "Side Quest"}[type]],
["Back"]]
["⬅️ Back"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
chat_id = update.message.chat_id
@@ -272,8 +274,8 @@ def mark_as_done(bot, update, player, qid, type):
send_status(bot, update, player, f"<b>🌟 Earned {points} XP</b>\n\n")
chat_id = update.message.chat_id
custom_keyboard = [
['Add Quest', 'Add Side Quest'],
['List Quests', 'List Side Quests']
['❇️ Add Quest', '📯 Add Side Quest'],
['📜 List Quests', '📃 List Side Quests']
]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_animation(chat_id=chat_id, animation=random.choice(config.gifs),
@@ -293,20 +295,31 @@ def edit_quest(bot, update, player, qid, target, type):
if target == "name":
x.name = message
text = "<b>Updated Name</b>"
elif target == "imp" or target == "diff":
text = "<b>☑️ Updated Name</b>"
elif target == "imp":
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")
return
else:
num = {"low": 1, "medium": 2, "high": 3}[message]
if target == "imp":
x.imp = num
text = "<b>Updated Priority</b>"
text = "<b>☑️ Updated Priority</b>"
elif target == "diff":
x.diff = num
text = "<b>Updated Difficulty</b>"
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:
bot.send_message(chat_id=chat_id, text="Invalid Option")
return
text = "<b>☑️ Updated Difficulty</b>"
x.update_db()
if type == "quest":
@@ -314,11 +327,11 @@ def edit_quest(bot, update, player, qid, target, type):
elif type == "side_quest":
player.set_state('esq', qid)
custom_keyboard = [
["Mark as done"],
["Edit Name", "Change Priority"],
["Change Difficulty", "Delete " +
["Mark as done"],
["📝 Edit Name", "⚠️ Change Priority"],
["📚 Change Difficulty", "🗑 Delete " +
{"quest": "Quest", "side_quest": "Side Quest"}[type]],
["Back"]]
["⬅️ Back"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup,
parse_mode="HTML")
@@ -344,8 +357,8 @@ def help_command(bot, update, db):
drop_state(bot, update, player)
chat_id = update.message.chat_id
custom_keyboard = [
['Add Quest', 'Add Side Quest'],
['List Quests', 'List Side Quests']
['❇️ Add Quest', '📯 Add Side Quest'],
['📜 List Quests', '📃 List Side Quests']
]
text = ("*Questable Bot*\n\nQuestable is an RPG-like bot for maintaining "
"events in real life. _Main Tasks_ are _Quests_ while _other "
@@ -354,7 +367,8 @@ def help_command(bot, update, db):
"Quests you get XP based on how difficult and important the "
"Quest/Side Quest was. Quests/Side Quests can be added and "
"modified later.\n\n To get more help check "
"[Extended Help](https://webionite.com/questable/). In case, of "
"[Extended Help](https://webionite.com/questable/) or "
"[this video](https://t.me/quadnite/25). In case, of "
"bugs/feedback/more help, contact @ceda\\_ei or join the "
"[group](https://t.me/questable).")
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
@@ -381,13 +395,13 @@ def message_handling(bot, update, db):
# eqd / esqd: Edit Quest / Side Quest Difficulty
if state["state"] == "none":
if text == "add quest":
if text == "add quest" or text == "❇️ add quest":
add_quest(bot, update, player)
elif text == "add side quest":
elif text == "add side quest" or text == "📯 add side quest":
add_quest(bot, update, player, "side_quest")
elif text == "list quests":
elif text == "list quests" or text == "📜 list quests":
list_quests(bot, update, player, "quest")
elif text == "list side quests":
elif text == "list side quests" or text == "📃 list side quests":
list_quests(bot, update, player, "side_quest")
else:
drop_state(bot, update, player)
@@ -412,32 +426,32 @@ def message_handling(bot, update, db):
add_imp(bot, update, player, "side_quest", state["extra"])
elif state["state"] == "eq":
if text == "back":
if text == "back" or text == "⬅️ back":
player.set_state('none', 0)
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")
elif text == "edit name":
elif text == "edit name" or text == "📝 edit name":
player.set_state('eqn', state["extra"])
text = "What shall the new name of the Quest be?"
reply_markup = telegram.ReplyKeyboardRemove()
bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup)
elif text == "change priority":
elif text == "change priority" or text == "⚠️ change priority":
player.set_state('eqi', state["extra"])
text = "How important is it?"
custom_keyboard = [["Low", "Medium", "High"]]
custom_keyboard = [["🔹 Low", "🔸 Medium", "🔺 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup)
elif text == "change difficulty":
elif text == "change difficulty" or text == "📚 change difficulty":
player.set_state('eqd', state["extra"])
text = "How difficult is it?"
custom_keyboard = [["Low", "Medium", "High"]]
custom_keyboard = [["📙 Low", "📘 Medium", "📗 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text,
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.delete_from_db()
drop_state(bot, update, player)
@@ -448,32 +462,32 @@ def message_handling(bot, update, db):
send_status(bot, update, player)
elif state["state"] == "esq":
if text == "back":
if text == "back" or text == "⬅️ back":
player.set_state('none', 0)
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")
elif text == "edit name":
elif text == "edit name" or text == "📝 edit name":
player.set_state('esqn', state["extra"])
text = "What shall the new name of the Side Quest be?"
reply_markup = telegram.ReplyKeyboardRemove()
bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup)
elif text == "change priority":
elif text == "change priority" or text == "⚠️ change priority":
player.set_state('esqi', state["extra"])
text = "How important is it?"
custom_keyboard = [["Low", "Medium", "High"]]
custom_keyboard = [["🔹 Low", "🔸 Medium", "🔺 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text,
reply_markup=reply_markup)
elif text == "change difficulty":
elif text == "change difficulty" or text == "📚 change difficulty":
player.set_state('esqd', state["extra"])
text = "How difficult is it?"
custom_keyboard = [["Low", "Medium", "High"]]
custom_keyboard = [["📙 Low", "📘 Medium", "📗 High"]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.send_message(chat_id=player.CHAT_ID, text=text,
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.delete_from_db()
drop_state(bot, update, player)