def controlCenterAction(action): logAction() questId = request.args['questId'] discordId = session.get("discordId") quest = db.getQuest(questId) player = db.getPlayer(discordId) if action == "claimRole": roleId = request.args['roleId'] result, message = quest.setRole(player, roleId) if result: role = Roles[roleId] player.leadership -= role['cost'] elif action == "releaveRole": roleId = quest.getPlayerRole(player) result, message = quest.setRole(player, None) if result: role = Roles[roleId] player.leadership += role['cost'] elif action == "useActive": activeId = request.args['activeId'] result, message = quest.activateRolePower(player, activeId) if result: active = Roles[quest.getPlayerRole(player)]['actives'][activeId] player.leadership -= active['cost'] # if activeId == "striketrue" and player.discordId == 153199290641022977: # db.pushTask("WHISPER") else: return "Unknown action", 400 if result: db.setQuest(quest) db.setPlayer(player) return message, 200 else: return message, 400
def questPlayerAction(action): logAction() questId = request.args['questId'] discordId = session.get("discordId") quest = db.getQuest(questId) player = db.getPlayer(discordId) if action == "claimCommander": result, message = quest.setCommander(player) if result: player.leadership -= quest.leadershipReq elif action == "releaveCommander": result, message = quest.setCommander(None) if result: player.leadership += quest.leadershipReq elif action == "joinQuest": # Recredit the leadership if they are currently a commander if player.discordId == quest.commander: player.leadership += quest.leadershipReq result, message = quest.addPlayer(player) elif action == "leaveQuest": result, message = quest.removePlayer(player) else: return "Unknown action", 400 if result: db.setQuest(quest) db.setPlayer(player) return message, 200 else: return message, 400
def unsetDate(): logAction() quest = db.getQuest(request.args['questId']) if quest == None: return "Unknown Quest", 404 result, message = quest.setDate(None) if result: db.setQuest(quest) return message, 200 else: return message, 400
def dmClaimQuest(): logAction() questId = request.args['questId'] discordId = session.get("discordId") quest = db.getQuest(questId) player = db.getPlayer(discordId) if quest.dm != None: return "This quest already has a DM", 403 quest.setDm(player) db.setQuest(quest) if quest.dm != None: db.pushTask("NEWQUEST " + quest.questId) return redirect("/dmcorner", code=302)
def addQuest(): logAction() formData = request.form.to_dict() questId = formData.get("questId") quest = None if questId == "" or questId == None: formData.pop("questId") newquest = True else: quest = db.getQuest(questId) if quest: quest.deserialise(json.dumps(formData)) newquest = False else: quest = Quest(jsonData=json.dumps(formData)) newquest = True db.setQuest(quest) # if newquest and quest.dm != None: # db.pushTask("NEWQUEST " + quest.questId) return redirect("/questadmin", code=302)
def addQuestDM(): logAction() formData = request.form.to_dict() questId = formData.get("questId") quest = None if questId == "" or questId == None: formData.pop("questId") else: quest = db.getQuest(questId) if quest: quest.deserialise(json.dumps(formData)) newquest = False else: quest = Quest(jsonData=json.dumps(formData)) newquest = True if quest.dm and quest.dm != int(session.get("discordId")): return "You cannot set other people to be the DM of your quest", 403 else: db.setQuest(quest) if newquest and quest.dm != None: db.pushTask("NEWQUEST " + quest.questId) return redirect("/dmcorner", code=302)
def setDateSubmit(): logAction() quest = db.getQuest(request.form.to_dict().get("questId")) if quest == None: return "Unknown Quest", 404 if request.form.to_dict().get("date") == None: # utc_date = None date = None else: date = request.form['date'] try: date = int(date) except ValueError: return "Invalid timestamp", 400 # tz = pytz.timezone(config.TimeZone) # date = datetime.fromtimestamp(date) # local_date = tz.localize(date, is_dst=None) # utc_date = local_date.astimezone(pytz.utc).timestamp() # quest.setDate(utc_date) quest.setDate(date) db.setQuest(quest) return redirect("/dmcorner", code=302)
def dmCornerAction(action): logAction() questId = request.args['questId'] discordId = request.args.get('discordId') quest = db.getQuest(questId) if discordId == None: player = None else: player = db.getPlayer(discordId) result, message = None, None # if action == "setDate": # result, message = quest.setDate(request.args.get("date")) if action == "kickPlayer": result, message = quest.removePlayer(player) elif action == "releaveDM": result, message = quest.setDm(None) else: return "Unknown action", 400 if result: db.setQuest(quest) return message, 200 else: return message, 400
def questAdminAction(action): logAction() questId = request.args['questId'] discordId = request.args.get("discordId") quest = db.getQuest(questId) if discordId == None: player = None else: player = db.getPlayer(discordId) if action == "changeCommander": result, message = quest.setCommander(player, forceAdd=True) elif action == "changeDM": result, message = quest.setDm(player, forceAdd=True) elif action == "addPlayer": result, message = quest.addPlayer(player, removeCommander=False, forceAdd=True) elif action == "removePlayer": result, message = quest.removePlayer(player) elif action == "changeRole": roleId = request.args['roleId'] if roleId == "unselected": roleId = None result, message = quest.setRole(player, roleId, forceAdd=True) elif action == "refreshPlayerRole": result, message = quest.refreshPlayerRole(player) elif action == "setVoidRewards": boolparam = request.args["boolparam"] if boolparam == "false": boolparam = False elif boolparam == "true": boolparam = True else: return "Missing boolparam", 400 result, message = quest.setVoidRewards(player, boolparam) else: return "Unknown action", 400 if result: db.setQuest(quest) return message, 200 else: return message, 400