Complete adding quests and side quests.
Add add_name, add_imp, add_diff functions. Add states and relevant if clauses. Add state of quest on first add.
This commit is contained in:
parent
260d1f6fde
commit
7fca63a2ab
112
bot.py
112
bot.py
|
@ -45,12 +45,12 @@ def add_quest(bot, update, player, type="quest"):
|
|||
x.sort(key=lambda i: i.QID, reverse=True)
|
||||
qid = x[0].QID + 1
|
||||
|
||||
# Add quest / sub_quest
|
||||
# Add quest / side_quest
|
||||
if type == 'quest':
|
||||
questable.add_quest(player.DB, player.CHAT_ID, qid)
|
||||
questable.add_quest(player.DB, player.CHAT_ID, qid, state=0)
|
||||
player.set_state('aq', qid)
|
||||
if type == 'side_quest':
|
||||
questable.add_side_quest(player.DB, player.CHAT_ID, qid)
|
||||
questable.add_side_quest(player.DB, player.CHAT_ID, qid, state=0)
|
||||
player.set_state('asq', qid)
|
||||
|
||||
# Send message
|
||||
|
@ -61,15 +61,121 @@ def add_quest(bot, update, player, type="quest"):
|
|||
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup)
|
||||
|
||||
|
||||
def add_name(bot, update, player, type, qid):
|
||||
if type == "quest":
|
||||
x = questable.get_quest(player.DB, player.CHAT_ID, qid)
|
||||
player.set_state('qd', qid)
|
||||
elif type == "side_quest":
|
||||
x = questable.get_side_quest(player.DB, player.CHAT_ID, qid)
|
||||
player.set_state('sqd', qid)
|
||||
else:
|
||||
raise ValueError('Not quest or side_quest')
|
||||
|
||||
x.name = update.message.text
|
||||
x.update_db()
|
||||
|
||||
chat_id = update.message.chat_id
|
||||
text = "How difficult is it?"
|
||||
custom_keyboard = [["Low", "Medium", "High"]]
|
||||
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
|
||||
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup)
|
||||
|
||||
|
||||
def add_diff(bot, update, player, type, qid):
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
if message == "Low":
|
||||
diff = 1
|
||||
elif message == "Medium":
|
||||
diff = 2
|
||||
elif message == "High":
|
||||
diff = 3
|
||||
else:
|
||||
bot.send_message(chat_id=chat_id, text="Invalid Option")
|
||||
return False
|
||||
|
||||
if type == "quest":
|
||||
x = questable.get_quest(player.DB, player.CHAT_ID, qid)
|
||||
player.set_state('qi', qid)
|
||||
elif type == "side_quest":
|
||||
x = questable.get_side_quest(player.DB, player.CHAT_ID, qid)
|
||||
player.set_state('sqi', qid)
|
||||
else:
|
||||
raise ValueError('Not quest or side_quest')
|
||||
|
||||
x.diff = diff
|
||||
x.update_db()
|
||||
|
||||
text = "How important is it?"
|
||||
custom_keyboard = [["Low", "Medium", "High"]]
|
||||
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
|
||||
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup)
|
||||
|
||||
|
||||
def add_imp(bot, update, player, type, qid):
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
if message == "Low":
|
||||
imp = 1
|
||||
elif message == "Medium":
|
||||
imp = 2
|
||||
elif message == "High":
|
||||
imp = 3
|
||||
else:
|
||||
bot.send_message(chat_id=chat_id, text="Invalid Option")
|
||||
return False
|
||||
|
||||
if type == "quest":
|
||||
x = questable.get_quest(player.DB, player.CHAT_ID, qid)
|
||||
player.set_state('none', 0)
|
||||
elif type == "side_quest":
|
||||
x = questable.get_side_quest(player.DB, player.CHAT_ID, qid)
|
||||
player.set_state('none', 0)
|
||||
else:
|
||||
raise ValueError('Not quest or side_quest')
|
||||
|
||||
x.imp = imp
|
||||
x.update_db()
|
||||
|
||||
text = "Quest Added!"
|
||||
custom_keyboard = [
|
||||
['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)
|
||||
|
||||
|
||||
def message_handling(bot, update, db):
|
||||
text = update.message.text
|
||||
player = questable.player(db, update.message.chat_id)
|
||||
state = player.get_state()
|
||||
|
||||
# states
|
||||
# none: in the middle of nothing
|
||||
# aq / asq: Added Quest: User has pressed add Quest/Side Quest
|
||||
# qd / sqd: (Side) Quest difficulty: User has entered title, difficulty
|
||||
# requested
|
||||
# qi / sqi: (Side) Quest importance: User has entered difficulty,
|
||||
# importance requested
|
||||
|
||||
if state["state"] == "none":
|
||||
if text == "Add Quest":
|
||||
add_quest(bot, update, player)
|
||||
elif text == "Add Side Quest":
|
||||
add_quest(bot, update, player, "side_quest")
|
||||
elif state["state"] == "aq":
|
||||
add_name(bot, update, player, "quest", state["extra"])
|
||||
elif state["state"] == "asq":
|
||||
add_name(bot, update, player, "side_quest", state["extra"])
|
||||
elif state["state"] == "qd":
|
||||
add_diff(bot, update, player, "quest", state["extra"])
|
||||
elif state["state"] == "sqd":
|
||||
add_diff(bot, update, player, "side_quest", state["extra"])
|
||||
elif state["state"] == "qi":
|
||||
add_imp(bot, update, player, "quest", state["extra"])
|
||||
elif state["state"] == "sqi":
|
||||
add_imp(bot, update, player, "side_quest", state["extra"])
|
||||
|
||||
|
||||
db = sqlite3.connect("questable.db", check_same_thread=False)
|
||||
|
|
Loading…
Reference in New Issue