public async Task RemoveSongAsync(string songId, [Remainder] string paramString = null) { if (IsAdmin()) { var server = ServerService.GetServer(); if (server == null) { await ReplyAsync(embed : "The Server is not running, so we can't can't get any event info".ErrorEmbed()); } else { var eventId = paramString.ParseArgs("eventId"); if (string.IsNullOrEmpty(eventId)) { await ReplyAsync(embed : ("Usage: `removeSong -eventId \"[event id]\" -song [song link]`\n" + "To find event ids, please run `listEvents`\n" + "Note: You may also need to include difficulty and modifier info to be sure you remove the right song").ErrorEmbed()); return; } var knownPairs = await HostScraper.ScrapeHosts(server.State.KnownHosts, $"{server.CoreServer.Address}:{server.CoreServer.Port}", 0); var targetPair = knownPairs.FirstOrDefault(x => x.Value.Events.Any(y => y.EventId.ToString() == eventId)); var targetEvent = targetPair.Value.Events.FirstOrDefault(x => x.EventId.ToString() == eventId); var songPool = targetEvent.QualifierMaps.ToList(); //Parse the difficulty input, either as an int or a string BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus; string difficultyArg = paramString.ParseArgs("difficulty"); if (difficultyArg != null) { //If the enum conversion doesn't succeed, try it as an int if (!Enum.TryParse(difficultyArg, true, out difficulty)) { await ReplyAsync(embed : ("Could not parse difficulty parameter.\n" + "Usage: `removeSong [songId] [difficulty]`").ErrorEmbed()); return; } } string characteristic = paramString.ParseArgs("characteristic"); characteristic = characteristic ?? "Standard"; GameOptions gameOptions = GameOptions.None; PlayerOptions playerOptions = PlayerOptions.None; //Load up the GameOptions and PlayerOptions foreach (GameOptions o in Enum.GetValues(typeof(GameOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { gameOptions = (gameOptions | o); } } foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { playerOptions = (playerOptions | o); } } //Sanitize input if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/")) { //Strip off the trailing slash if there is one if (songId.EndsWith("/")) { songId = songId.Substring(0, songId.Length - 1); } //Strip off the beginning of the url to leave the id songId = songId.Substring(songId.LastIndexOf("/") + 1); } if (songId.Contains("&")) { songId = songId.Substring(0, songId.IndexOf("&")); } //Get the hash for the song var hash = BeatSaverDownloader.GetHashFromID(songId); var song = FindSong(songPool, $"custom_level_{hash.ToUpper()}", characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions); if (song != null) { targetEvent.QualifierMaps = RemoveSong(songPool, $"custom_level_{hash.ToUpper()}", characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions).ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed : ($"Removed {song.Beatmap.Name} ({difficulty}) ({characteristic}) from the song list" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed : response.Message.ErrorEmbed()); } } else { await ReplyAsync(embed : $"Specified song does not exist with that difficulty / characteristic / gameOptions / playerOptions ({difficulty} {characteristic} {gameOptions} {playerOptions})".ErrorEmbed()); } } } }
public async Task AddSongAsync([Remainder] string paramString = null) { if (IsAdmin()) { var eventId = paramString.ParseArgs("eventId"); var songId = paramString.ParseArgs("song"); if (string.IsNullOrEmpty(eventId) || string.IsNullOrEmpty(songId)) { await ReplyAsync(embed : ("Usage: `addSong -eventId \"[event id]\" -song [song link]`\n" + "To find event ids, please run `listEvents`\n" + "Optional parameters: `-difficulty [difficulty]`, `-characteristic [characteristic]` (example: `-characteristic onesaber`), `-[modifier]` (example: `-nofail`)").ErrorEmbed()); return; } //Parse the difficulty input, either as an int or a string BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus; string difficultyArg = paramString.ParseArgs("difficulty"); if (difficultyArg != null) { //If the enum conversion doesn't succeed, try it as an int if (!Enum.TryParse(difficultyArg, true, out difficulty)) { await ReplyAsync(embed : "Could not parse difficulty parameter".ErrorEmbed()); return; } } string characteristic = paramString.ParseArgs("characteristic"); characteristic = characteristic ?? "Standard"; GameOptions gameOptions = GameOptions.None; PlayerOptions playerOptions = PlayerOptions.None; //Load up the GameOptions and PlayerOptions foreach (GameOptions o in Enum.GetValues(typeof(GameOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { gameOptions = (gameOptions | o); } } foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { playerOptions = (playerOptions | o); } } //Sanitize input if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/")) { //Strip off the trailing slash if there is one if (songId.EndsWith("/")) { songId = songId.Substring(0, songId.Length - 1); } //Strip off the beginning of the url to leave the id songId = songId.Substring(songId.LastIndexOf("/") + 1); } if (songId.Contains("&")) { songId = songId.Substring(0, songId.IndexOf("&")); } var server = ServerService.GetServer(); if (server == null) { await ReplyAsync(embed : "The Server is not running, so we can't can't add songs to it".ErrorEmbed()); } else { //Get the hash for the song var hash = BeatSaverDownloader.GetHashFromID(songId); var knownPairs = await HostScraper.ScrapeHosts(server.State.KnownHosts, $"{server.CoreServer.Address}:{server.CoreServer.Port}", 0); var targetPair = knownPairs.FirstOrDefault(x => x.Value.Events.Any(y => y.EventId.ToString() == eventId)); var targetEvent = targetPair.Value.Events.FirstOrDefault(x => x.EventId.ToString() == eventId); var songPool = targetEvent.QualifierMaps.ToList(); if (OstHelper.IsOst(hash)) { if (!SongExists(songPool, hash, characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions)) { GameplayParameters parameters = new GameplayParameters { Beatmap = new Beatmap { Name = OstHelper.GetOstSongNameFromLevelId(hash), LevelId = hash, Characteristic = new Characteristic { SerializedName = characteristic }, Difficulty = difficulty }, GameplayModifiers = new GameplayModifiers { Options = gameOptions }, PlayerSettings = new PlayerSpecificSettings { Options = playerOptions } }; songPool.Add(parameters); targetEvent.QualifierMaps = songPool.ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed : ($"Added: {parameters.Beatmap.Name} ({difficulty}) ({characteristic})" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed : response.Message.ErrorEmbed()); } } else { await ReplyAsync(embed : "Song is already active in the database".ErrorEmbed()); } } else { BeatSaverDownloader.DownloadSong(hash, async(songPath) => { if (songPath != null) { DownloadedSong song = new DownloadedSong(hash); string songName = song.Name; if (!song.GetBeatmapDifficulties(characteristic).Contains(difficulty)) { BeatmapDifficulty nextBestDifficulty = song.GetClosestDifficultyPreferLower(difficulty); if (SongExists(songPool, hash, characteristic, (int)nextBestDifficulty, (int)gameOptions, (int)playerOptions)) { await ReplyAsync(embed: $"{songName} doesn't have {difficulty}, and {nextBestDifficulty} is already in the event".ErrorEmbed()); } else { GameplayParameters parameters = new GameplayParameters { Beatmap = new Beatmap { Name = songName, LevelId = $"custom_level_{hash.ToUpper()}", Characteristic = new Characteristic { SerializedName = characteristic }, Difficulty = nextBestDifficulty }, GameplayModifiers = new GameplayModifiers { Options = gameOptions }, PlayerSettings = new PlayerSpecificSettings { Options = playerOptions } }; songPool.Add(parameters); targetEvent.QualifierMaps = songPool.ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed: ($"{songName} doesn't have {difficulty}, using {nextBestDifficulty} instead.\n" + $"Added to the song list" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed: response.Message.ErrorEmbed()); } } } else { GameplayParameters parameters = new GameplayParameters { Beatmap = new Beatmap { Name = songName, LevelId = $"custom_level_{hash.ToUpper()}", Characteristic = new Characteristic { SerializedName = characteristic }, Difficulty = difficulty }, GameplayModifiers = new GameplayModifiers { Options = gameOptions }, PlayerSettings = new PlayerSpecificSettings { Options = playerOptions } }; songPool.Add(parameters); targetEvent.QualifierMaps = songPool.ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed: ($"{songName} ({difficulty}) ({characteristic}) downloaded and added to song list" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed: response.Message.ErrorEmbed()); } } } else { await ReplyAsync(embed: "Could not download song.".ErrorEmbed()); } }); } } } else { await ReplyAsync(embed : "You do not have sufficient permissions to use this command".ErrorEmbed()); } }
public async Task RemoveSongAsync([Remainder] string paramString = null) { if (IsAdmin()) { var server = ServerService.GetServer(); if (server == null) { await ReplyAsync(embed : "服务器不在线,所以不能获取赛事信息".ErrorEmbed()); } else { var eventId = paramString.ParseArgs("赛事"); var songId = paramString.ParseArgs("歌曲"); if (string.IsNullOrEmpty(eventId)) { await ReplyAsync(embed : ("用法: `删除歌曲 -赛事 \"[赛事ID]\" -歌曲 [链接/key]`\n" + "赛事ID可以通过`赛事列表`命令查找\n" + "注意: 你可能需要在命令种包含难度或者修改项信息来确保你删除的是正确的歌曲").ErrorEmbed()); return; } var knownPairs = await HostScraper.ScrapeHosts(server.State.KnownHosts, $"{server.CoreServer.Address}:{server.CoreServer.Port}", 0); var targetPair = knownPairs.FirstOrDefault(x => x.Value.Events.Any(y => y.EventId.ToString() == eventId)); var targetEvent = targetPair.Value.Events.FirstOrDefault(x => x.EventId.ToString() == eventId); var songPool = targetEvent.QualifierMaps.ToList(); //Parse the difficulty input, either as an int or a string BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus; string difficultyArg = paramString.ParseArgs("难度"); if (difficultyArg != null) { //If the enum conversion doesn't succeed, try it as an int if (!Enum.TryParse(difficultyArg, true, out difficulty)) { await ReplyAsync(embed : ("请检查难度参数\n" + "用法: `删除歌曲 [歌曲ID] [难度]`").ErrorEmbed()); return; } } string characteristic = paramString.ParseArgs("谱型"); characteristic = characteristic ?? "Standard"; GameOptions gameOptions = GameOptions.None; PlayerOptions playerOptions = PlayerOptions.None; //Load up the GameOptions and PlayerOptions foreach (GameOptions o in Enum.GetValues(typeof(GameOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { gameOptions = (gameOptions | o); } } foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { playerOptions = (playerOptions | o); } } //Sanitize input if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/")) { //Strip off the trailing slash if there is one if (songId.EndsWith("/")) { songId = songId.Substring(0, songId.Length - 1); } //Strip off the beginning of the url to leave the id songId = songId.Substring(songId.LastIndexOf("/") + 1); } if (songId.Contains("&")) { songId = songId.Substring(0, songId.IndexOf("&")); } //Get the hash for the song var hash = BeatSaverDownloader.GetHashFromID(songId); var song = FindSong(songPool, $"custom_level_{hash.ToUpper()}", characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions); if (song != null) { targetEvent.QualifierMaps = RemoveSong(songPool, $"custom_level_{hash.ToUpper()}", characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions).ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed : ($"已从歌曲列表中删除 {song.Beatmap.Name} ({difficulty}) ({characteristic}) " + $"{(gameOptions != GameOptions.None ? $" 附加游戏参数: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" 附加玩家参数: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed : response.Message.ErrorEmbed()); } } else { await ReplyAsync(embed : $"指定歌曲没有相对应 难度/谱型/游戏选项/玩家选项 ({difficulty} {characteristic} {gameOptions} {playerOptions})".ErrorEmbed()); } } } }
public async Task AddSongAsync([Remainder] string paramString = null) { if (IsAdmin()) { var eventId = paramString.ParseArgs("赛事"); var songId = paramString.ParseArgs("歌曲"); if (string.IsNullOrEmpty(eventId) || string.IsNullOrEmpty(songId)) { await ReplyAsync(embed : ("用法: `添加歌曲 -赛事 \"[赛事ID]\" -歌曲 [链接/key]`\n" + "赛事ID可以通过`赛事列表`命令查找\n" + "可选参数: `-难度 [Easy/Normal/Hard/Expert/ExpertPlus]`, `-谱型 [例如: onesaber]`, `-[修改项]` (例如: 不死模式为 `-nofail`)").ErrorEmbed()); return; } //Parse the difficulty input, either as an int or a string BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus; string difficultyArg = paramString.ParseArgs("难度"); if (difficultyArg != null) { //If the enum conversion doesn't succeed, try it as an int if (!Enum.TryParse(difficultyArg, true, out difficulty)) { await ReplyAsync(embed : "请检查难度参数".ErrorEmbed()); return; } } string characteristic = paramString.ParseArgs("谱型"); characteristic = characteristic ?? "Standard"; GameOptions gameOptions = GameOptions.None; PlayerOptions playerOptions = PlayerOptions.None; //Load up the GameOptions and PlayerOptions foreach (GameOptions o in Enum.GetValues(typeof(GameOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { gameOptions = (gameOptions | o); } } foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions))) { if (paramString.ParseArgs(o.ToString()) == "true") { playerOptions = (playerOptions | o); } } //Sanitize input if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/")) { //Strip off the trailing slash if there is one if (songId.EndsWith("/")) { songId = songId.Substring(0, songId.Length - 1); } //Strip off the beginning of the url to leave the id songId = songId.Substring(songId.LastIndexOf("/") + 1); } if (songId.Contains("&")) { songId = songId.Substring(0, songId.IndexOf("&")); } var server = ServerService.GetServer(); if (server == null) { await ReplyAsync(embed : "服务器不在线,所以不能添加歌曲".ErrorEmbed()); } else { //Get the hash for the song var hash = BeatSaverDownloader.GetHashFromID(songId); var knownPairs = await HostScraper.ScrapeHosts(server.State.KnownHosts, $"{server.CoreServer.Address}:{server.CoreServer.Port}", 0); var targetPair = knownPairs.FirstOrDefault(x => x.Value.Events.Any(y => y.EventId.ToString() == eventId)); var targetEvent = targetPair.Value.Events.FirstOrDefault(x => x.EventId.ToString() == eventId); var songPool = targetEvent.QualifierMaps.ToList(); if (OstHelper.IsOst(hash)) { if (!SongExists(songPool, hash, characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions)) { GameplayParameters parameters = new GameplayParameters { Beatmap = new Beatmap { Name = OstHelper.GetOstSongNameFromLevelId(hash), LevelId = hash, Characteristic = new Characteristic { SerializedName = characteristic }, Difficulty = difficulty }, GameplayModifiers = new GameplayModifiers { Options = gameOptions }, PlayerSettings = new PlayerSpecificSettings { Options = playerOptions } }; songPool.Add(parameters); targetEvent.QualifierMaps = songPool.ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed : ($"已添加: {parameters.Beatmap.Name} ({difficulty}) ({characteristic})" + $"{(gameOptions != GameOptions.None ? $" 附加游戏参数: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" 附加玩家参数: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed : response.Message.ErrorEmbed()); } } else { await ReplyAsync(embed : "歌曲已存在于数据库".ErrorEmbed()); } } else { var songInfo = await BeatSaverDownloader.GetSongInfo(songId); string songName = songInfo.Name; if (!songInfo.HasDifficulty(characteristic, difficulty)) { BeatmapDifficulty nextBestDifficulty = songInfo.GetClosestDifficultyPreferLower(characteristic, difficulty); if (SongExists(songPool, hash, characteristic, (int)nextBestDifficulty, (int)gameOptions, (int)playerOptions)) { await ReplyAsync(embed : $"{songName} 不存在 {difficulty} 难度, 而且 {nextBestDifficulty} 已存在于赛事".ErrorEmbed()); } else { GameplayParameters parameters = new GameplayParameters { Beatmap = new Beatmap { Name = songName, LevelId = $"custom_level_{hash.ToUpper()}", Characteristic = new Characteristic { SerializedName = characteristic }, Difficulty = nextBestDifficulty }, GameplayModifiers = new GameplayModifiers { Options = gameOptions }, PlayerSettings = new PlayerSpecificSettings { Options = playerOptions } }; songPool.Add(parameters); targetEvent.QualifierMaps = songPool.ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed : ($"{songName} 不存在 {difficulty} 难度, 使用 {nextBestDifficulty} 难度代替。\n" + $"已添加至歌曲列表" + $"{(gameOptions != GameOptions.None ? $" 附加游戏参数: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" 附加玩家参数: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed : response.Message.ErrorEmbed()); } } } else { GameplayParameters parameters = new GameplayParameters { Beatmap = new Beatmap { Name = songName, LevelId = $"custom_level_{hash.ToUpper()}", Characteristic = new Characteristic { SerializedName = characteristic }, Difficulty = difficulty }, GameplayModifiers = new GameplayModifiers { Options = gameOptions }, PlayerSettings = new PlayerSpecificSettings { Options = playerOptions } }; songPool.Add(parameters); targetEvent.QualifierMaps = songPool.ToArray(); var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent); if (response.Type == Response.ResponseType.Success) { await ReplyAsync(embed : ($"{songName} ({difficulty}) ({characteristic}) 已下载并添加至歌曲列表" + $"{(gameOptions != GameOptions.None ? $" 附加游戏参数: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" 附加玩家参数: ({playerOptions})" : "!")}").SuccessEmbed()); } else if (response.Type == Response.ResponseType.Fail) { await ReplyAsync(embed : response.Message.ErrorEmbed()); } } } } } else { await ReplyAsync(embed : "你没有足够的权限使用该命令".ErrorEmbed()); } }
public async Task RemoveSongAsync(string songId, [Remainder] string paramString = null) { if (IsAdmin()) { //Parse the difficulty input, either as an int or a string BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus; string difficultyArg = ParseArgs(paramString, "difficulty"); if (difficultyArg != null) { //If the enum conversion doesn't succeed, try it as an int if (!Enum.TryParse(difficultyArg, true, out difficulty)) { await ReplyAsync("Could not parse difficulty parameter.\n" + "Usage: removeSong [songId] [difficulty]"); return; } } string characteristic = ParseArgs(paramString, "characteristic"); characteristic = characteristic ?? "Standard"; GameOptions gameOptions = GameOptions.None; PlayerOptions playerOptions = PlayerOptions.None; //Load up the GameOptions and PlayerOptions foreach (GameOptions o in Enum.GetValues(typeof(GameOptions))) { if (ParseArgs(paramString, o.ToString()) == "true") { gameOptions = (gameOptions | o); } } foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions))) { if (ParseArgs(paramString, o.ToString()) == "true") { playerOptions = (playerOptions | o); } } //Sanitize input if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/")) { //Strip off the trailing slash if there is one if (songId.EndsWith("/")) { songId = songId.Substring(0, songId.Length - 1); } //Strip off the beginning of the url to leave the id songId = songId.Substring(songId.LastIndexOf("/") + 1); } if (songId.Contains("&")) { songId = songId.Substring(0, songId.IndexOf("&")); } //Get the hash for the song var hash = BeatSaverDownloader.GetHashFromID(songId); var song = FindSong(Context.Guild.Id, hash, characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions); if (song != null) { song.Old = true; await ReplyAsync($"Removed {song.Name} ({difficulty}) ({characteristic}) from the song list" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}"); } else { await ReplyAsync("Specified song does not exist with that difficulty / characteristic / gameOptions / playerOptions"); } } }
public async Task AddSongAsync(string songId, [Remainder] string paramString = null) { if (IsAdmin()) { //Parse the difficulty input, either as an int or a string BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus; string difficultyArg = ParseArgs(paramString, "difficulty"); if (difficultyArg != null) { //If the enum conversion doesn't succeed, try it as an int if (!Enum.TryParse(difficultyArg, true, out difficulty)) { await ReplyAsync("Could not parse difficulty parameter.\n" + "Usage: addSong [songId] [difficulty]"); return; } } string characteristic = ParseArgs(paramString, "characteristic"); characteristic = characteristic ?? "Standard"; GameOptions gameOptions = GameOptions.None; PlayerOptions playerOptions = PlayerOptions.None; //Load up the GameOptions and PlayerOptions foreach (GameOptions o in Enum.GetValues(typeof(GameOptions))) { if (ParseArgs(paramString, o.ToString()) == "true") { gameOptions = (gameOptions | o); } } foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions))) { if (ParseArgs(paramString, o.ToString()) == "true") { playerOptions = (playerOptions | o); } } //Sanitize input if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/")) { //Strip off the trailing slash if there is one if (songId.EndsWith("/")) { songId = songId.Substring(0, songId.Length - 1); } //Strip off the beginning of the url to leave the id songId = songId.Substring(songId.LastIndexOf("/") + 1); } if (songId.Contains("&")) { songId = songId.Substring(0, songId.IndexOf("&")); } //Get the hash for the song var hash = BeatSaverDownloader.GetHashFromID(songId); if (OstHelper.IsOst(hash)) { //if (!Song.Exists(hash, parsedDifficulty, characteristicArg, true)) if (!SongExists(Context.Guild.Id, hash, characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions)) { Song song = new Song { Name = OstHelper.GetOstSongNameFromLevelId(hash), GuildId = Context.Guild.Id, LevelId = hash, Characteristic = characteristic, BeatmapDifficulty = (int)difficulty, GameOptions = (int)gameOptions, PlayerOptions = (int)playerOptions }; await ReplyAsync($"Added: {song.Name} ({difficulty}) ({characteristic})" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions.ToString()})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions.ToString()})" : "!")}"); } else { await ReplyAsync("Song is already active in the database"); } } else { BeatSaverDownloader.DownloadSong(hash, async(songPath) => { if (songPath != null) { DownloadedSong song = new DownloadedSong(hash); string songName = song.Name; if (!song.GetBeatmapDifficulties(characteristic).Contains(difficulty)) { BeatmapDifficulty nextBestDifficulty = song.GetClosestDifficultyPreferLower(difficulty); if (SongExists(Context.Guild.Id, hash, characteristic, (int)nextBestDifficulty, (int)gameOptions, (int)playerOptions)) { await ReplyAsync($"{songName} doesn't have {difficulty}, and {nextBestDifficulty} is already in the database.\n" + $"Song not added."); } else { Song databaseSong = new Song { Name = OstHelper.GetOstSongNameFromLevelId(hash), GuildId = Context.Guild.Id, LevelId = hash, Characteristic = characteristic, BeatmapDifficulty = (int)nextBestDifficulty, GameOptions = (int)gameOptions, PlayerOptions = (int)playerOptions }; await ReplyAsync($"{songName} doesn't have {difficulty}, using {nextBestDifficulty} instead.\n" + $"Added to the song list" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}"); } } else { Song databaseSong = new Song { Name = OstHelper.GetOstSongNameFromLevelId(hash), GuildId = Context.Guild.Id, LevelId = hash, Characteristic = characteristic, BeatmapDifficulty = (int)difficulty, GameOptions = (int)gameOptions, PlayerOptions = (int)playerOptions }; await ReplyAsync($"{songName} ({difficulty}) ({characteristic}) downloaded and added to song list" + $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" + $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}"); } } else { await ReplyAsync("Could not download song."); } }); } } }