Initial commit

This commit is contained in:
Mira 2025-01-27 18:36:22 +01:00
commit 79e7cffb4e
Signed by untrusted user who does not match committer: Xorog
GPG key ID: 983798ED9C3E7C36
49 changed files with 6399 additions and 0 deletions

View file

@ -0,0 +1,70 @@
// 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 AddToQueueCommand : BaseCommand
{
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 playlistId = (string)arguments["playlist"];
if (!MusicPlugin.Plugin.Users[ctx.User.Id].Playlists.Any(x => x.PlaylistId == playlistId))
{
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
{
Description = this.GetString(CommandKey.Playlists.NoPlaylist, true),
}.AsError(ctx, this.GetString(CommandKey.Playlists.Title)));
return;
}
var SelectedPlaylist = MusicPlugin.Plugin.Users[ctx.User.Id].Playlists.First(x => x.PlaylistId == playlistId);
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
{
Description = this.GetString(CommandKey.Play.Preparing, true),
}.AsLoading(ctx, this.GetString(CommandKey.Playlists.Title)));
try
{
await new JoinCommand().TransferCommand(ctx, null);
}
catch (CancelException)
{
this.DeleteOrInvalidate();
return;
}
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
{
Description = this.GetString(CommandKey.Playlists.AddToQueue.Adding, true,
new TVar("Name", SelectedPlaylist.PlaylistName),
new TVar("", SelectedPlaylist.List.Length)),
}.AsLoading(ctx, this.GetString(CommandKey.Playlists.Title)));
MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue = MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.AddRange(SelectedPlaylist.List.Select(x => new GuildMusic.QueueInfo(x.Title, x.Url, x.Length.Value, ctx.Guild.Id, ctx.User.Id)));
_ = await this.RespondOrEdit(new DiscordEmbedBuilder
{
Description = this.GetString(CommandKey.Play.QueuedMultiple, true,
new TVar("Count", SelectedPlaylist.List.Length),
new TVar("Playlist", SelectedPlaylist.PlaylistName))
}
.AddField(new DiscordEmbedField($"📜 {this.GetString(CommandKey.Play.QueuePositions)}", $"{(MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length - SelectedPlaylist.List.Length + 1)} - {MusicPlugin.Plugin!.Guilds![ctx.Guild.Id].SongQueue.Length}"))
.AsSuccess(ctx, this.GetString(CommandKey.Playlists.Title)));
});
}
}