def put(self, playsound_name, **options): playsound_name = PlaysoundModule.massage_name(playsound_name) if not PlaysoundModule.validate_name(playsound_name): return ( { "error": "Invalid Playsound name. The playsound name may only contain lowercase latin letters, 0-9, -, or _. No spaces :rage:" }, 400, ) post_parser = RequestParser() post_parser.add_argument("link", required=True) args = post_parser.parse_args() try: link = args["link"] except (ValueError, KeyError): return {"error": "Invalid `link` parameter."}, 400 with DBManager.create_session_scope() as db_session: count = db_session.query(Playsound).filter(Playsound.name == playsound_name).count() if count >= 1: return "Playsound already exists", 400 # the rest of the parameters are initialized with defaults playsound = Playsound(name=playsound_name, link=link) db_session.add(playsound) return "OK", 200
def playsound_create(playsound_name: str, **options) -> ResponseReturnValue: # Create playsound playsound_name = PlaysoundModule.massage_name(playsound_name) if not PlaysoundModule.validate_name(playsound_name): return ( { "error": "Invalid Playsound name. The playsound name may only contain lowercase latin letters, 0-9, -, or _. No spaces :rage:" }, 400, ) try: json_data = request.get_json() if not json_data: return {"error": "Missing json body"}, 400 data = CreatePlaysoundSchema().load(json_data) except ValidationError as err: return {"error": f"Did not match schema: {json.dumps(err.messages)}"}, 400 with DBManager.create_session_scope() as db_session: count = db_session.query(Playsound).filter(Playsound.name == playsound_name).count() if count >= 1: return "Playsound already exists", 400 # the rest of the parameters are initialized with defaults playsound = Playsound(name=playsound_name, link=data.link) db_session.add(playsound) log_msg = f"The {playsound_name} playsound has been added" AdminLogManager.add_entry("Playsound added", options["user"], log_msg) return "OK", 200
def add_playsound_command(self, bot, source, message, **rest): """Method for creating playsounds. Usage: !add playsound PLAYSOUNDNAME LINK [options] Multiple options available: --volume VOLUME --cooldown COOLDOWN --enabled/--disabled """ options, name, link = self.parse_playsound_arguments(message) # the parser does not enforce a link being present because the edit function # doesn't require it strictly, so apart from "False" link is being checked # for being None here. if options is False or name is False or link is False or link is None: bot.whisper( source, "Invalid usage. Correct syntax: !add playsound <name> <link> " + "[--volume 0-100] [--cooldown 60/none] [--enabled/--disabled]", ) return name = self.massage_name(name) if not self.validate_name(name): bot.whisper( source, "Invalid Playsound name. The playsound name may only contain lowercase latin letters, 0-9, -, or _. No spaces :rage:", ) return with DBManager.create_session_scope() as session: count = session.query(Playsound).filter( Playsound.name == name).count() if count > 0: bot.whisper( source, "A Playsound with that name already exists. Use !edit playsound " + "or !remove playsound to edit or delete it.", ) return playsound = Playsound(name=name) if not self.update_link(bot, source, playsound, link): return if not self.update_volume(bot, source, playsound, options): return if not self.update_cooldown(bot, source, playsound, options): return if not self.update_enabled(bot, source, playsound, options): return session.add(playsound) bot.whisper(source, "Successfully added your playsound.")
def put(self, playsound_name, **options): post_parser = RequestParser() post_parser.add_argument("link", required=True) args = post_parser.parse_args() try: link = args["link"] except (ValueError, KeyError): return {"error": "Invalid `link` parameter."}, 400 with DBManager.create_session_scope() as db_session: count = db_session.query(Playsound).filter(Playsound.name == playsound_name).count() if count >= 1: return "Playsound already exists", 400 # the rest of the parameters are initialized with defaults playsound = Playsound(name=playsound_name, link=link) db_session.add(playsound) return "OK", 200