From: Daniel Karbach Date: Sat, 28 May 2022 15:47:47 +0000 (+0200) Subject: accept case insensitive presets over api X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=19a773da8abaffaa9806a2f9733a6c8af04b9c42;p=alttp.git accept case insensitive presets over api --- diff --git a/app/DiscordAppCommands/AosrPresetCommand.php b/app/DiscordAppCommands/AosrPresetCommand.php index 5ad05e0..7a8907a 100644 --- a/app/DiscordAppCommands/AosrPresetCommand.php +++ b/app/DiscordAppCommands/AosrPresetCommand.php @@ -54,6 +54,18 @@ class AosrPresetCommand { $discord->application->commands->save($cmd); } + public static function presetByName($name) { + if (isset(static::$presets[$name])) { + return static::$presets[$name]; + } + foreach (static::$presets as $presetName => $preset) { + if (strcasecmp($name, $presetName) === 0) { + return $preset; + } + } + return null; + } + public static function listen(Discord $discord) { $discord->listenCommand(['aosr', 'preset'], function(Interaction $interaction) use ($discord) { $interaction diff --git a/app/Http/Controllers/AosSeedController.php b/app/Http/Controllers/AosSeedController.php index 1e2aa73..19f6f4b 100644 --- a/app/Http/Controllers/AosSeedController.php +++ b/app/Http/Controllers/AosSeedController.php @@ -31,10 +31,10 @@ class AosSeedController extends Controller $presetName = $validatedData['preset']; $race = $validatedData['race'] ?? false; - if (!isset(AosrPresetCommand::$presets[$presetName])) { + $preset = AosrPresetCommand::presetByName($presetName); + if (!$preset) { abort(404); } - $preset = AosrPresetCommand::$presets[$presetName]; $seed = AosSeed::generateSurge($presetName, $preset['settings'], $race); Artisan::call('aos:generate '.intval($seed->id));