Initial commit
This commit is contained in:
commit
79e7cffb4e
49 changed files with 6399 additions and 0 deletions
127
Commands/Music/ClearQueueCommand.cs
Normal file
127
Commands/Music/ClearQueueCommand.cs
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class ClearQueueCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForHeavy(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Contains(ctx.User.Id))
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.ClearQueue.AlreadyVoted, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Add(ctx.User.Id);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Count >= (conn.Channel.Users.Count - 1) * 0.51)
|
||||
{
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue = [];
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Clear();
|
||||
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.ClearQueue.Cleared, true),
|
||||
}.AsSuccess(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = new DiscordEmbedBuilder()
|
||||
{
|
||||
Description = $"`{this.GetGuildString(CommandKey.ClearQueue.VoteStarted)} ({MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Count}/{Math.Ceiling((conn.Channel.Users.Count - 1.0) * 0.51)})`",
|
||||
}.AsAwaitingInput(ctx);
|
||||
|
||||
var builder = new DiscordMessageBuilder().WithEmbed(embed);
|
||||
|
||||
DiscordButtonComponent DisconnectVote = new(ButtonStyle.Danger, Guid.NewGuid().ToString(), this.GetGuildString(CommandKey.ClearQueue.VoteButton), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("🗑")));
|
||||
_ = builder.AddComponents(DisconnectVote);
|
||||
|
||||
_ = await this.RespondOrEdit(builder);
|
||||
|
||||
_ = Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith(x =>
|
||||
{
|
||||
if (x.IsCompletedSuccessfully)
|
||||
{
|
||||
ctx.Client.ComponentInteractionCreated -= RunInteraction;
|
||||
this.ModifyToTimedOut();
|
||||
}
|
||||
});
|
||||
|
||||
ctx.Client.ComponentInteractionCreated += RunInteraction;
|
||||
|
||||
async Task RunInteraction(DiscordClient s, ComponentInteractionCreateEventArgs e)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (e.Message.Id == ctx.ResponseMessage.Id)
|
||||
{
|
||||
_ = e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Contains(e.User.Id))
|
||||
{
|
||||
_ = e.Interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().WithContent($"❌ {this.GetString(CommandKey.ClearQueue.AlreadyVoted, true)}").AsEphemeral());
|
||||
return;
|
||||
}
|
||||
|
||||
var member = await e.User.ConvertToMember(ctx.Guild);
|
||||
|
||||
if (member.VoiceState is null || member.VoiceState.Channel.Id != conn.Channel.Id)
|
||||
{
|
||||
_ = e.Interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().WithContent($"❌ {this.GetString(CommandKey.NotSameChannel, true)}").AsEphemeral());
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Add(e.User.Id);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Count >= (conn.Channel.Users.Count - 1) * 0.51)
|
||||
{
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue = [];
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Clear();
|
||||
|
||||
_ = await this.RespondOrEdit(new DiscordMessageBuilder().WithEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.ClearQueue.Cleared, true),
|
||||
}.AsSuccess(ctx)));
|
||||
return;
|
||||
}
|
||||
|
||||
embed.Description = $"`{this.GetGuildString(CommandKey.ClearQueue.VoteStarted)} ({MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Count}/{Math.Ceiling((conn.Channel.Users.Count - 1.0) * 0.51)})`";
|
||||
_ = await this.RespondOrEdit(new DiscordMessageBuilder().WithEmbed(embed).AddComponents(DisconnectVote));
|
||||
}
|
||||
}).Add(ctx.Bot);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
131
Commands/Music/DisconnectCommand.cs
Normal file
131
Commands/Music/DisconnectCommand.cs
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class DisconnectCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForHeavy(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Contains(ctx.User.Id))
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Disconnect.AlreadyVoted, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Add(ctx.User.Id);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Count >= (conn.Channel.Users.Count - 1) * 0.51)
|
||||
{
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Dispose(ctx.Bot, ctx.Guild.Id, "Graceful Disconnect");
|
||||
|
||||
_ = await conn.StopAsync();
|
||||
await conn.DisconnectAsync();
|
||||
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Disconnect.Disconnected, true),
|
||||
}.AsSuccess(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = new DiscordEmbedBuilder()
|
||||
{
|
||||
Description = $"`{this.GetGuildString(CommandKey.Disconnect.VoteStarted, true)} ({MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Count}/{Math.Ceiling((conn.Channel.Users.Count - 1.0) * 0.51)})`",
|
||||
}.AsAwaitingInput(ctx);
|
||||
|
||||
var builder = new DiscordMessageBuilder().WithEmbed(embed);
|
||||
|
||||
DiscordButtonComponent DisconnectVote = new(ButtonStyle.Danger, Guid.NewGuid().ToString(), this.GetGuildString(CommandKey.Disconnect.VoteButton), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("⛔")));
|
||||
_ = builder.AddComponents(DisconnectVote);
|
||||
|
||||
_ = await this.RespondOrEdit(builder);
|
||||
|
||||
_ = Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith(x =>
|
||||
{
|
||||
if (x.IsCompletedSuccessfully)
|
||||
{
|
||||
ctx.Client.ComponentInteractionCreated -= RunInteraction;
|
||||
this.ModifyToTimedOut();
|
||||
}
|
||||
});
|
||||
|
||||
ctx.Client.ComponentInteractionCreated += RunInteraction;
|
||||
|
||||
async Task RunInteraction(DiscordClient s, ComponentInteractionCreateEventArgs e)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (e.Message.Id == ctx.ResponseMessage.Id)
|
||||
{
|
||||
_ = e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Contains(e.User.Id))
|
||||
{
|
||||
_ = e.Interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().WithContent($"❌ {this.GetString(CommandKey.Disconnect.AlreadyVoted, true)}").AsEphemeral());
|
||||
return;
|
||||
}
|
||||
|
||||
var member = await e.User.ConvertToMember(ctx.Guild);
|
||||
|
||||
if (member.VoiceState is null || member.VoiceState.Channel.Id != conn.Channel.Id)
|
||||
{
|
||||
_ = e.Interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().WithContent($"❌ {this.GetString(CommandKey.NotSameChannel, true)}").AsEphemeral());
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Add(e.User.Id);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Count >= (conn.Channel.Users.Count - 1) * 0.51)
|
||||
{
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Dispose(ctx.Bot, ctx.Guild.Id, "Graceful Disconnect");
|
||||
|
||||
_ = await conn.StopAsync();
|
||||
await conn.DisconnectAsync();
|
||||
|
||||
_ = await this.RespondOrEdit(new DiscordMessageBuilder().WithEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Disconnect.Disconnected, true)
|
||||
}.AsSuccess(ctx)));
|
||||
return;
|
||||
}
|
||||
|
||||
embed.Description = $"`{this.GetGuildString(CommandKey.Disconnect.VoteStarted, true)} ({MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedDisconnectVotes.Count}/{Math.Ceiling((conn.Channel.Users.Count - 1.0) * 0.51)})`";
|
||||
_ = await this.RespondOrEdit(new DiscordMessageBuilder().WithEmbed(embed).AddComponents(DisconnectVote));
|
||||
}
|
||||
}).Add(ctx.Bot);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
56
Commands/Music/ForceClearQueueCommand.cs
Normal file
56
Commands/Music/ForceClearQueueCommand.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class ForceClearQueueCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForHeavy(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ctx.Member.IsDJ(ctx.Bot.status))
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.DjRole, true, new TVar("Role", "DJ")),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue = [];
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedClearQueueVotes.Clear();
|
||||
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.ForceClearQueue.Cleared, true),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
58
Commands/Music/ForceDisconnectCommand.cs
Normal file
58
Commands/Music/ForceDisconnectCommand.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class ForceDisconnectCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForHeavy(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ctx.Member.IsDJ(ctx.Bot.status))
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.DjRole, true, new TVar("Role", "DJ")),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Dispose(ctx.Bot, ctx.Guild.Id, "Graceful Disconnect");
|
||||
|
||||
_ = await conn.StopAsync();
|
||||
await conn.DisconnectAsync();
|
||||
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.ForceDisconnect.Disconnected, true),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
55
Commands/Music/ForceSkipCommand.cs
Normal file
55
Commands/Music/ForceSkipCommand.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class ForceSkipCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForModerate(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ctx.Member.IsDJ(ctx.Bot.status))
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.DjRole, true, new TVar("Role", "DJ")),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
_ = await conn.StopAsync();
|
||||
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.ForceSkip.Skipped, true),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
77
Commands/Music/JoinCommand.cs
Normal file
77
Commands/Music/JoinCommand.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class JoinCommand : BaseCommand
|
||||
{
|
||||
public override async Task<bool> BeforeExecution(SharedCommandContext ctx) => (await this.CheckVoiceState() && await this.CheckOwnPermissions(Permissions.UseVoice) && await this.CheckOwnPermissions(Permissions.UseVoiceDetection));
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var Announce = arguments?.ContainsKey("announce") ?? false;
|
||||
|
||||
if (Announce)
|
||||
if (await ctx.DbUser.Cooldown.WaitForModerate(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
|
||||
while (!lava.ConnectedSessions.Values.Any(x => x.IsConnected))
|
||||
await Task.Delay(1000);
|
||||
|
||||
var node = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = node.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null)
|
||||
{
|
||||
if (!lava.ConnectedSessions.Any())
|
||||
{
|
||||
throw new Exception("Lavalink connection isn't established.");
|
||||
}
|
||||
|
||||
conn = await node.ConnectAsync(ctx.Member.VoiceState.Channel);
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].QueueHandler(ctx.Bot, ctx.Client, node, conn);
|
||||
|
||||
if (Announce)
|
||||
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Join.Joined, true),
|
||||
}.AsSuccess(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
if (conn.Channel.Users.Count >= 2 && !(ctx.Member.VoiceState.Channel.Id == conn.Channel.Id))
|
||||
{
|
||||
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Join.AlreadyUsed, true),
|
||||
}.AsError(ctx));
|
||||
|
||||
throw new CancelException();
|
||||
}
|
||||
|
||||
if (ctx.Member.VoiceState.Channel.Id != conn.Channel.Id)
|
||||
{
|
||||
await conn.DisconnectAsync();
|
||||
conn = await node.ConnectAsync(ctx.Member.VoiceState.Channel);
|
||||
}
|
||||
|
||||
if (Announce)
|
||||
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Join.Joined, true),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
48
Commands/Music/PauseCommand.cs
Normal file
48
Commands/Music/PauseCommand.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class PauseCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForLight(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].IsPaused = !MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].IsPaused;
|
||||
|
||||
_ = MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].IsPaused ? conn.PauseAsync() : conn.ResumeAsync();
|
||||
|
||||
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].IsPaused ? this.GetString(CommandKey.Pause.Paused, true) : this.GetString(CommandKey.Pause.Resumed, true)),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
110
Commands/Music/PlayCommand.cs
Normal file
110
Commands/Music/PlayCommand.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
using DisCatSharp.Lavalink.Entities;
|
||||
using Xorog.UniversalExtensions;
|
||||
using Xorog.UniversalExtensions.Enums;
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class PlayCommand : BaseCommand
|
||||
{
|
||||
public override async Task<bool> BeforeExecution(SharedCommandContext ctx) => (await this.CheckVoiceState() && await this.CheckOwnPermissions(Permissions.UseVoice) && await this.CheckOwnPermissions(Permissions.UseVoiceDetection));
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var search = (string)arguments["search"];
|
||||
|
||||
if (await ctx.DbUser.Cooldown.WaitForModerate(ctx))
|
||||
return;
|
||||
|
||||
if (search.IsNullOrWhiteSpace())
|
||||
{
|
||||
this.SendSyntaxError();
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Play.Preparing, true),
|
||||
}.AsLoading(ctx);
|
||||
_ = await this.RespondOrEdit(embed);
|
||||
|
||||
try
|
||||
{
|
||||
await new JoinCommand().TransferCommand(ctx, null);
|
||||
}
|
||||
catch (CancelException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var (Tracks, oriResult, Continue) = await MusicModuleAbstractions.GetLoadResult(ctx, search);
|
||||
|
||||
|
||||
embed.Author.IconUrl = ctx.Guild.IconUrl;
|
||||
|
||||
if (!Continue || !Tracks.IsNotNullAndNotEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_ = await this.RespondOrEdit(embed);
|
||||
|
||||
try
|
||||
{
|
||||
await new JoinCommand().TransferCommand(ctx, null);
|
||||
}
|
||||
catch (CancelException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tracks.Count > 1)
|
||||
{
|
||||
var added = 0;
|
||||
|
||||
foreach (var b in Tracks)
|
||||
{
|
||||
added++;
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue = MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Add(new(b.Info.Title, b.Info.Uri.ToString(), b.Info.Length, ctx.Guild.Id, ctx.User.Id));
|
||||
}
|
||||
|
||||
embed.Description = this.GetString(CommandKey.Play.QueuedMultiple, true,
|
||||
new TVar("Count", added),
|
||||
new TVar("Playlist", new EmbeddedLink(search, oriResult.GetResultAs<LavalinkPlaylist>().Info.Name)));
|
||||
|
||||
_ = embed.AddField(new DiscordEmbedField($"📜 {this.GetString(CommandKey.Play.QueuePositions)}", $"{(MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length - added + 1)} - {MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length}", true));
|
||||
|
||||
_ = embed.AsSuccess(ctx);
|
||||
_ = await ctx.BaseCommand.RespondOrEdit(embed);
|
||||
}
|
||||
else if (Tracks.Count == 1)
|
||||
{
|
||||
var track = Tracks[0];
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue = MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Add(new(track.Info.Title, track.Info.Uri.ToString(), track.Info.Length, ctx.Guild.Id, ctx.User.Id));
|
||||
|
||||
embed.Description = this.GetString(CommandKey.Play.QueuedSingle, true,
|
||||
new TVar("Track", new EmbeddedLink(track.Info.Uri.ToString(), track.Info.Title)));
|
||||
|
||||
_ = embed.AddField(new DiscordEmbedField($"📜 {this.GetString(CommandKey.Play.QueuePosition)}", $"{MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length}", true));
|
||||
_ = embed.AddField(new DiscordEmbedField($"🔼 {this.GetString(CommandKey.Play.Uploader)}", $"{track.Info.Author}", true));
|
||||
_ = embed.AddField(new DiscordEmbedField($"🕒 {this.GetString(CommandKey.Play.Duration)}", $"{track.Info.Length.GetHumanReadable(TimeFormat.Minutes)}", true));
|
||||
|
||||
_ = embed.AsSuccess(ctx);
|
||||
_ = await ctx.BaseCommand.RespondOrEdit(embed.Build());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
186
Commands/Music/QueueCommand.cs
Normal file
186
Commands/Music/QueueCommand.cs
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
using System.Diagnostics;
|
||||
using Xorog.UniversalExtensions;
|
||||
using Xorog.UniversalExtensions.Enums;
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class QueueCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForLight(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
var LastInt = 0;
|
||||
int GetInt()
|
||||
{
|
||||
LastInt++;
|
||||
return LastInt;
|
||||
}
|
||||
|
||||
var CurrentPage = 0;
|
||||
|
||||
async Task UpdateMessage()
|
||||
{
|
||||
DiscordButtonComponent Refresh = new(ButtonStyle.Primary, "Refresh", this.GetString(this.t.Common.Refresh), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("🔁")));
|
||||
|
||||
DiscordButtonComponent NextPage = new(ButtonStyle.Primary, "NextPage", this.GetString(this.t.Common.NextPage), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("▶")));
|
||||
DiscordButtonComponent PreviousPage = new(ButtonStyle.Primary, "PreviousPage", this.GetString(this.t.Common.PreviousPage), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("◀")));
|
||||
|
||||
DiscordButtonComponent PlayPause = new(ButtonStyle.Secondary, "Playback", this.GetString(CommandKey.Queue.Play), conn.Player.Track is null, (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].IsPaused ? EmojiTemplates.GetPaused(ctx.Bot) : (conn.Player.Track is not null ? "▶".UnicodeToEmoji() : EmojiTemplates.GetDisabledPlay(ctx.Bot))).ToComponent());
|
||||
DiscordButtonComponent Repeat = new(ButtonStyle.Secondary, "Repeat", this.GetString(CommandKey.Queue.Repeat), conn.Player.Track is null, (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Repeat ? "🔁".UnicodeToEmoji() : EmojiTemplates.GetDisabledRepeat(ctx.Bot)).ToComponent());
|
||||
DiscordButtonComponent Shuffle = new(ButtonStyle.Secondary, "Shuffle", this.GetString(CommandKey.Queue.Shuffle), conn.Player.Track is null, (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Shuffle ? "🔀".UnicodeToEmoji() : EmojiTemplates.GetDisabledShuffle(ctx.Bot)).ToComponent());
|
||||
|
||||
LastInt = CurrentPage * 10;
|
||||
|
||||
var TotalTimespan = TimeSpan.Zero;
|
||||
|
||||
for (var i = 0; i < MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length; i++)
|
||||
{
|
||||
TotalTimespan = TotalTimespan.Add(MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue[i].Length);
|
||||
}
|
||||
|
||||
var Description = $"{this.GetString(CommandKey.Queue.QueueCount, true, new TVar("Count", MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length), new TVar("Timespan", TotalTimespan.GetHumanReadable())).Bold()}\n\n";
|
||||
Description += $"{string.Join("\n", MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Skip(CurrentPage * 10).Take(10).Select(x => $"**{GetInt()}**. `{x.Length.GetShortHumanReadable(TimeFormat.Hours)}` {this.GetString(CommandKey.Queue.Track, new TVar("Video", $"[`{x.VideoTitle}`]({x.Url})"), new TVar("Requester", $"<@{x.UserId}>"))}"))}\n\n";
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length > 0)
|
||||
Description += $"`{this.GetString(this.t.Common.Page)} {CurrentPage + 1}/{Math.Ceiling(MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length / 10.0)}`\n\n";
|
||||
|
||||
Description += $"`{this.GetString(CommandKey.Queue.CurrentlyPlaying)}:` [`{(conn.Player.Track is not null ? conn.Player.Track.Info.Title : this.GetString(CommandKey.Queue.NoSong))}`]({(conn.Player.Track is not null ? conn.Player.Track.Info.Uri.ToString() : "")})\n";
|
||||
Description += $"{(MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Repeat ? "🔁".UnicodeToEmoji() : EmojiTemplates.GetDisabledRepeat(ctx.Bot))}";
|
||||
Description += $"{(MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Shuffle ? "🔀".UnicodeToEmoji() : EmojiTemplates.GetDisabledShuffle(ctx.Bot))}";
|
||||
Description += $" `|` {(MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].IsPaused ? EmojiTemplates.GetPaused(ctx.Bot) : $"{(conn.Player.Track is not null ? "▶".UnicodeToEmoji() : EmojiTemplates.GetDisabledPlay(ctx.Bot))} ")}";
|
||||
|
||||
if (conn.CurrentTrack is not null)
|
||||
{
|
||||
Description += $"`[{((long)Math.Round(conn.Player.PlayerState.Position.TotalSeconds, 0)).GetShortHumanReadable(TimeFormat.Minutes)}/{((long)Math.Round(conn.Player.Track.Info.Length.TotalSeconds, 0)).GetShortHumanReadable(TimeFormat.Minutes)}]` ";
|
||||
Description += $"`{StringTools.GenerateASCIIProgressbar(Math.Round(conn.Player.PlayerState.Position.TotalSeconds, 0), Math.Round(conn.Player.Track.Info.Length.TotalSeconds, 0))}`";
|
||||
}
|
||||
|
||||
if (CurrentPage <= 0)
|
||||
PreviousPage = PreviousPage.Disable();
|
||||
|
||||
if ((CurrentPage * 10) + 10 >= MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length)
|
||||
NextPage = NextPage.Disable();
|
||||
|
||||
_ = await this.RespondOrEdit(new DiscordMessageBuilder().WithEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = Description
|
||||
}.AsInfo(ctx))
|
||||
.AddComponents(PreviousPage, NextPage, Refresh)
|
||||
.AddComponents(PlayPause, Repeat, Shuffle));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await UpdateMessage();
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
while (sw.ElapsedMilliseconds < 120000)
|
||||
{
|
||||
await UpdateMessage();
|
||||
Thread.Sleep(10000);
|
||||
}
|
||||
});
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
while (sw.ElapsedMilliseconds < 120000)
|
||||
Thread.Sleep(1000);
|
||||
|
||||
ctx.Client.ComponentInteractionCreated -= RunInteraction;
|
||||
this.ModifyToTimedOut();
|
||||
});
|
||||
|
||||
ctx.Client.ComponentInteractionCreated += RunInteraction;
|
||||
async Task RunInteraction(DiscordClient s, ComponentInteractionCreateEventArgs e)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (e.Message?.Id == ctx.ResponseMessage.Id && e.User.Id == ctx.User.Id)
|
||||
{
|
||||
sw.Restart();
|
||||
|
||||
switch (e.GetCustomId())
|
||||
{
|
||||
case "Playback":
|
||||
{
|
||||
await new Music.PauseCommand().ExecuteCommand(e, s, "pause", ctx.Bot).Add(ctx.Bot);
|
||||
|
||||
await UpdateMessage();
|
||||
break;
|
||||
}
|
||||
case "Repeat":
|
||||
{
|
||||
await new Music.RepeatCommand().ExecuteCommand(e, s, "repeat", ctx.Bot).Add(ctx.Bot);
|
||||
|
||||
await UpdateMessage();
|
||||
break;
|
||||
}
|
||||
case "Shuffle":
|
||||
{
|
||||
await new Music.ShuffleCommand().ExecuteCommand(e, s, "shuffle", ctx.Bot).Add(ctx.Bot);
|
||||
|
||||
await UpdateMessage();
|
||||
break;
|
||||
}
|
||||
case "Refresh":
|
||||
{
|
||||
_ = e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||
|
||||
await UpdateMessage();
|
||||
break;
|
||||
}
|
||||
case "NextPage":
|
||||
{
|
||||
_ = e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||
|
||||
CurrentPage++;
|
||||
await UpdateMessage();
|
||||
break;
|
||||
}
|
||||
case "PreviousPage":
|
||||
{
|
||||
_ = e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||
|
||||
CurrentPage--;
|
||||
await UpdateMessage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).Add(ctx.Bot, ctx);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
97
Commands/Music/RemoveQueueCommand.cs
Normal file
97
Commands/Music/RemoveQueueCommand.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
using ProjectMakoto.Entities.Guilds;
|
||||
using Xorog.UniversalExtensions;
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class RemoveQueueCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var selection = (string)arguments["video"];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(selection))
|
||||
{
|
||||
this.SendSyntaxError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (await ctx.DbUser.Cooldown.WaitForLight(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
GuildMusic.QueueInfo info = null;
|
||||
|
||||
if (selection.IsDigitsOnly())
|
||||
{
|
||||
var Index = Convert.ToInt32(selection) - 1;
|
||||
|
||||
if (Index < 0 || Index >= MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.RemoveQueue.OutOfRange, true, new TVar("Min", 1), new TVar("Max", MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length)),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
info = MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue[Index];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Any(x => x.VideoTitle.ToLower() == selection.ToLower()))
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.RemoveQueue.NoSong, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
info = MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.First(x => x.VideoTitle.ToLower() == selection.ToLower());
|
||||
}
|
||||
|
||||
if (info is null)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.RemoveQueue.NoSong, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue = MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Remove(x => x.UUID, info);
|
||||
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.RemoveQueue.Removed, true, new TVar("Track", $"`[`{info.VideoTitle}`]({info.Url})`")),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
46
Commands/Music/RepeatCommand.cs
Normal file
46
Commands/Music/RepeatCommand.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class RepeatCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForLight(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Repeat = !MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Repeat;
|
||||
|
||||
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Repeat ? this.GetString(CommandKey.Repeat.On, true) : this.GetString(CommandKey.Repeat.Off, true)),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
46
Commands/Music/ShuffleCommand.cs
Normal file
46
Commands/Music/ShuffleCommand.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class ShuffleCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForLight(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Shuffle = !MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Shuffle;
|
||||
|
||||
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].Shuffle ? this.GetString(CommandKey.Shuffle.On, true) : this.GetString(CommandKey.Shuffle.Off, true)),
|
||||
}.AsSuccess(ctx));
|
||||
});
|
||||
}
|
||||
}
|
||||
125
Commands/Music/SkipCommand.cs
Normal file
125
Commands/Music/SkipCommand.cs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
// Project Makoto
|
||||
// Copyright (C) 2024 Fortunevale
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
namespace ProjectMakoto.Plugins.Music;
|
||||
|
||||
internal sealed class SkipCommand : BaseCommand
|
||||
{
|
||||
public override Task<bool> BeforeExecution(SharedCommandContext ctx) => this.CheckVoiceState();
|
||||
|
||||
public override Task ExecuteCommand(SharedCommandContext ctx, Dictionary<string, object> arguments)
|
||||
{
|
||||
var CommandKey = ((Entities.Translations)MusicPlugin.Plugin!.Translations).Commands.Music;
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (await ctx.DbUser.Cooldown.WaitForModerate(ctx))
|
||||
return;
|
||||
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
var session = lava.ConnectedSessions.Values.First(x => x.IsConnected);
|
||||
var conn = session.GetGuildPlayer(ctx.Member.VoiceState.Guild);
|
||||
|
||||
if (conn is null || conn.Channel.Id != ctx.Member.VoiceState.Channel.Id)
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.NotSameChannel, true),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Contains(ctx.User.Id))
|
||||
{
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Skip.AlreadyVoted),
|
||||
}.AsError(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Add(ctx.User.Id);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Count >= (conn.Channel.Users.Count - 1) * 0.51)
|
||||
{
|
||||
_ = await conn.StopAsync();
|
||||
|
||||
_ = await this.RespondOrEdit(embed: new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Skip.Skipped, true),
|
||||
}.AsSuccess(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = new DiscordEmbedBuilder()
|
||||
{
|
||||
Description = $"`{this.GetGuildString(CommandKey.Skip.VoteStarted)} ({MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Count}/{Math.Ceiling((conn.Channel.Users.Count - 1.0) * 0.51)})`",
|
||||
}.AsAwaitingInput(ctx);
|
||||
|
||||
var builder = new DiscordMessageBuilder().WithEmbed(embed);
|
||||
|
||||
DiscordButtonComponent SkipSongVote = new(ButtonStyle.Danger, Guid.NewGuid().ToString(), this.GetGuildString(CommandKey.Skip.VoteButton), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("⏩")));
|
||||
_ = builder.AddComponents(SkipSongVote);
|
||||
|
||||
_ = await this.RespondOrEdit(builder);
|
||||
|
||||
_ = Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith(x =>
|
||||
{
|
||||
if (x.IsCompletedSuccessfully)
|
||||
{
|
||||
ctx.Client.ComponentInteractionCreated -= RunInteraction;
|
||||
this.ModifyToTimedOut();
|
||||
}
|
||||
});
|
||||
|
||||
ctx.Client.ComponentInteractionCreated += RunInteraction;
|
||||
|
||||
async Task RunInteraction(DiscordClient s, ComponentInteractionCreateEventArgs e)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (e.Message.Id == ctx.ResponseMessage.Id)
|
||||
{
|
||||
_ = e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Contains(e.User.Id))
|
||||
{
|
||||
_ = e.Interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().WithContent($"❌ {this.GetString(CommandKey.Skip.AlreadyVoted, true)}").AsEphemeral());
|
||||
return;
|
||||
}
|
||||
|
||||
var member = await e.User.ConvertToMember(ctx.Guild);
|
||||
|
||||
if (member.VoiceState is null || member.VoiceState.Channel.Id != conn.Channel.Id)
|
||||
{
|
||||
_ = e.Interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().WithContent($"❌ {this.GetString(CommandKey.NotSameChannel, true)}").AsEphemeral());
|
||||
return;
|
||||
}
|
||||
|
||||
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Add(e.User.Id);
|
||||
|
||||
if (MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Count >= (conn.Channel.Users.Count - 1) * 0.51)
|
||||
{
|
||||
_ = await conn.StopAsync();
|
||||
|
||||
_ = await this.RespondOrEdit(new DiscordMessageBuilder().WithEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Description = this.GetString(CommandKey.Skip.Skipped, true),
|
||||
}.AsSuccess(ctx)));
|
||||
return;
|
||||
}
|
||||
|
||||
embed.Description = $"`{this.GetGuildString(CommandKey.Skip.VoteStarted)} ({MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].collectedSkips.Count}/{Math.Ceiling((conn.Channel.Users.Count - 1.0) * 0.51)})`";
|
||||
_ = await this.RespondOrEdit(new DiscordMessageBuilder().WithEmbed(embed).AddComponents(SkipSongVote));
|
||||
}
|
||||
}).Add(ctx.Bot);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue