Reworked the Config system

This commit is contained in:
2024-08-06 19:07:08 +03:00
parent 8366de28cc
commit 721c28c283
28 changed files with 740 additions and 318 deletions

View File

@@ -78,8 +78,7 @@ public class AddMelody: DBCommand
await msg.ModifyAsync(a => a.Content = "Done");
var info =
MusicInfoExtensions.CreateMusicInfo(title, location, description ?? "Unknown", aliases.ToList(), bsize);
var info = MusicInfoExtensions.CreateMusicInfo(title, location, description ?? "Unknown", aliases.ToList(), bsize);
Variables._MusicDatabase?.Add(title, info);

View File

@@ -21,6 +21,13 @@ public class AddMelodyYoutube: DBCommand
public async void ExecuteServer(DbCommandExecutingArguments args)
{
if(Variables._MusicDatabase is null)
{
await args.Context.Channel.SendMessageAsync("Music Database is not loaded !");
return;
}
if (args.Arguments is null)
{
await args.Context.Channel.SendMessageAsync("Invalid arguments given. Please use the following format:\nadd_melody_youtube [URL]");
@@ -28,9 +35,9 @@ public class AddMelodyYoutube: DBCommand
}
var URL = args.Arguments[0];
var url = args.Arguments[0];
if (!URL.StartsWith("https://www.youtube.com/watch?v=") && !URL.StartsWith("https://youtu.be/"))
if (!url.StartsWith("https://www.youtube.com/watch?v=") && !url.StartsWith("https://youtu.be/"))
{
await args.Context.Channel.SendMessageAsync("Invalid URL given. Please use the following format:\nadd_melody_youtube [URL]");
return;
@@ -44,7 +51,7 @@ public class AddMelodyYoutube: DBCommand
var msg = await args.Context.Channel.SendMessageAsync("Saving melody ...");
var title = await YoutubeDLP.DownloadMelody(URL);
var title = await YoutubeDLP.DownloadMelody(url);
if (title == null)
{
@@ -56,8 +63,11 @@ public class AddMelodyYoutube: DBCommand
List<string> aliases = joinedAliases.Split('|').ToList();
if (Variables._MusicDatabase.ContainsMelodyWithNameOrAlias(title))
Variables._MusicDatabase.Remove(title);
if (Variables._MusicDatabase.GetMusicInfoWithTitleOrAlias(title).Any())
{
await msg.ModifyAsync(x => x.Content = "Melody already exists !");
return;
}
Variables._MusicDatabase.Add(title, new MusicInfo()
{

View File

@@ -15,6 +15,19 @@ public class SearchMelody: DBCommand
public void ExecuteServer(DbCommandExecutingArguments args)
{
if(Variables._MusicDatabase is null)
{
args.Context.Channel.SendMessageAsync("Music Database is not loaded !");
return;
}
if (args.Arguments is null || args.Arguments.Length == 0)
{
args.Context.Channel.SendMessageAsync("You need to specify a melody name");
return;
}
var title = string.Join(" ", args.Arguments);
if (string.IsNullOrWhiteSpace(title))
@@ -23,16 +36,13 @@ public class SearchMelody: DBCommand
return;
}
List<MusicInfo>? info = Variables._MusicDatabase.GetMusicInfoList(title);
if (info == null || info.Count == 0)
List<MusicInfo> info = Variables._MusicDatabase.GetMusicInfoWithTitleOrAlias(title);
if (!info.Any())
{
args.Context.Channel.SendMessageAsync("No melody with that name or alias was found");
return;
}
if (info.Count > 1)
args.Context.Channel.SendMessageAsync(embed: info.ToEmbed(Color.DarkOrange));
else
args.Context.Channel.SendMessageAsync(embed: info[0].ToEmbed(Color.DarkOrange));
args.Context.Channel.SendMessageAsync(embed: info.Count > 1 ? info.ToEmbed(Color.DarkOrange) : info[0].ToEmbed(Color.DarkOrange));
}
}