Merged projects with plugins and modules

This commit is contained in:
2024-07-22 01:18:00 +03:00
parent 1fd065f4c2
commit 8ace51c840
59 changed files with 1669 additions and 73 deletions

View File

@@ -0,0 +1,54 @@
using Discord;
using Discord.WebSocket;
using DiscordBotCore.Interfaces;
namespace MusicPlayer.SlashCommands;
public class Loop: DBSlashCommand
{
public string Name => "loop";
public string Description => "Loop the current song for a certain amount of times. If no times are specified, it will loop once";
public bool canUseDM => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => new()
{
new()
{
Type = ApplicationCommandOptionType.Integer,
Name = "times",
Description = "How many times to loop the song",
IsRequired = false
}
};
public void ExecuteServer(SocketSlashCommand context)
{
if (Variables._MusicPlayer.CurrentlyPlaying == null)
{
context.RespondAsync("There is nothing playing right now");
return;
}
var times = context.Data.Options.FirstOrDefault()?.Value.ToString() ?? "1";
if (!int.TryParse(times, out var timesToLoop))
{
context.RespondAsync("Invalid number");
return;
}
if (timesToLoop < 1)
{
context.RespondAsync("You need to specify a number greater than 0");
return;
}
Variables._MusicPlayer.Loop(timesToLoop);
context.RespondAsync($"Looping {Variables._MusicPlayer.CurrentlyPlaying.Title} {timesToLoop} times. Check the queue to see the progress");
}
}

View File

@@ -0,0 +1,78 @@
using Discord;
using Discord.WebSocket;
using DiscordBotCore;
using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
namespace MusicPlayer.SlashCommands;
public class Play: DBSlashCommand
{
public string Name => "play";
public string Description => "Play music command";
public bool canUseDM => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => new()
{
new()
{
IsRequired = true,
Description = "The music name to be played",
Name = "music-name",
Type = ApplicationCommandOptionType.String
}
};
public async void ExecuteServer(SocketSlashCommand context)
{
var melodyName = context.Data.Options.First().Value as string;
if (melodyName is null)
{
await context.RespondAsync("Failed to retrieve melody with name " + melodyName);
return;
}
var melody = Variables._MusicDatabase.GetMusicInfo(melodyName);
if (melody is null)
{
await context.RespondAsync("The searched melody does not exists in the database. Sorry :(");
return;
}
var user = context.User as IGuildUser;
if (user is null)
{
await context.RespondAsync("Failed to get user data from channel ! Check error log at " + DateTime.Now.ToLongTimeString());
Application.CurrentApplication.Logger.Log("User is null while trying to convert from context.User to IGuildUser.", typeof(Play), LogType.Error);
return;
}
var voiceChannel = user.VoiceChannel;
if (voiceChannel is null)
{
await context.RespondAsync("Unknown voice channel. Maybe I do not have permission to join it ?");
return;
}
if (Variables.audioClient is null)
{
Variables.audioClient = await voiceChannel.ConnectAsync(true); // self deaf
}
Variables._MusicPlayer ??= new MusicPlayer();
if (!Variables._MusicPlayer.Enqueue(melodyName))
{
await context.RespondAsync("Failed to enqueue your request. Something went wrong !");
return;
}
await context.RespondAsync("Enqueued your request");
await Variables._MusicPlayer.PlayQueue(); //start queue
}
}

View File

@@ -0,0 +1,49 @@
using Discord;
using Discord.WebSocket;
using DiscordBotCore.Interfaces;
namespace MusicPlayer.SlashCommands;
public class Queue: DBSlashCommand
{
public string Name => "queue";
public string Description => "Queue a melody to play";
public bool canUseDM => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => null;
public async void ExecuteServer(SocketSlashCommand context)
{
if (Variables._MusicPlayer is null)
{
await context.RespondAsync("No music is currently playing.");
return;
}
if (Variables._MusicPlayer.MusicQueue.Count == 0 && Variables._MusicPlayer.CurrentlyPlaying == null)
{
await context.RespondAsync("No music is currently playing");
return;
}
var builder = new EmbedBuilder()
{
Title = "Music Queue",
Description = "Here is the current music queue",
Color = Color.Blue
};
if (Variables._MusicPlayer.CurrentlyPlaying != null)
builder.AddField("Current music", Variables._MusicPlayer.CurrentlyPlaying.Title);
var i = 1;
foreach (var melody in Variables._MusicPlayer.MusicQueue)
{
builder.AddField($"#{i}", melody.Title);
i++;
}
await context.RespondAsync(embed: builder.Build());
}
}

View File

@@ -0,0 +1,35 @@
using Discord;
using Discord.WebSocket;
using DiscordBotCore.Interfaces;
namespace MusicPlayer.SlashCommands;
public class Skip: DBSlashCommand
{
public string Name => "skip";
public string Description => "Skip the current melody";
public bool canUseDM => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => null;
public async void ExecuteServer(SocketSlashCommand context)
{
if (Variables._MusicPlayer is null)
{
await context.RespondAsync("No music is currently playing.");
return;
}
if (Variables._MusicPlayer.MusicQueue.Count == 0 && Variables._MusicPlayer.CurrentlyPlaying == null)
{
await context.RespondAsync("No music is currently playing");
return;
}
var melodyTitle = Variables._MusicPlayer.CurrentlyPlaying.Title;
await context.RespondAsync($"Skipping {melodyTitle} ...");
Variables._MusicPlayer.Skip();
await context.ModifyOriginalResponseAsync(x => x.Content = $"Skipped {melodyTitle}");
}
}