From 81a4d553bec569332f5ef7dd823e73aa2391aef5 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 30 Jan 2017 05:40:19 +0100 Subject: [PATCH] !!smch added. Set music output's text channel. --- .../Modules/Music/Classes/MusicControls.cs | 5 +- src/NadekoBot/Modules/Music/Music.cs | 54 ++++++++++++------- .../Resources/CommandStrings.Designer.cs | 27 ++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 9 ++++ 4 files changed, 75 insertions(+), 20 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index 6d101975..e11b680e 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -71,6 +71,7 @@ namespace NadekoBot.Modules.Music.Classes public event Action OnPauseChanged = delegate { }; public IVoiceChannel PlaybackVoiceChannel { get; private set; } + public ITextChannel OutputTextChannel { get; set; } private bool Destroyed { get; set; } = false; public bool RepeatSong { get; private set; } = false; @@ -84,10 +85,12 @@ namespace NadekoBot.Modules.Music.Classes public event Action SongRemoved = delegate { }; - public MusicPlayer(IVoiceChannel startingVoiceChannel, float? defaultVolume) + public MusicPlayer(IVoiceChannel startingVoiceChannel, ITextChannel outputChannel, float? defaultVolume) { if (startingVoiceChannel == null) throw new ArgumentNullException(nameof(startingVoiceChannel)); + + OutputTextChannel = outputChannel; Volume = defaultVolume ?? 1.0f; PlaybackVoiceChannel = startingVoiceChannel; diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index b229bf84..5ad9918c 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -797,6 +797,23 @@ namespace NadekoBot.Modules.Music await Context.Channel.SendConfirmAsync("✅ Autoplay enabled.").ConfigureAwait(false); } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequireUserPermission(GuildPermission.ManageMessages)] + public async Task SetMusicChannel() + { + MusicPlayer musicPlayer; + if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) + { + await Context.Channel.SendErrorAsync("Music must be playing before you set an ouput channel.").ConfigureAwait(false); + return; + } + + musicPlayer.OutputTextChannel = (ITextChannel)Context.Channel; + + await Context.Channel.SendConfirmAsync("I will now output playing, finished, paused and removed songs in this channel.").ConfigureAwait(false); + } + public static async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) { if (voiceCh == null || voiceCh.Guild != textCh.Guild) @@ -815,7 +832,7 @@ namespace NadekoBot.Modules.Music { vol = uow.GuildConfigs.For(textCh.Guild.Id, set => set).DefaultMusicVolume; } - var mp = new MusicPlayer(voiceCh, vol); + var mp = new MusicPlayer(voiceCh, textCh, vol); IUserMessage playingMessage = null; IUserMessage lastFinishedMessage = null; mp.OnCompleted += async (s, song) => @@ -825,7 +842,7 @@ namespace NadekoBot.Modules.Music if (lastFinishedMessage != null) lastFinishedMessage.DeleteAfter(0); - lastFinishedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() + lastFinishedMessage = await mp.OutputTextChannel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Finished Song").WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo))) @@ -857,7 +874,7 @@ namespace NadekoBot.Modules.Music if (playingMessage != null) playingMessage.DeleteAfter(0); - playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() + playingMessage = await mp.OutputTextChannel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo))) @@ -866,22 +883,21 @@ namespace NadekoBot.Modules.Music catch { } }; mp.OnPauseChanged += async (paused) => - { - try - { - IUserMessage msg; - if (paused) - msg = await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); - else - msg = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); - - if (msg != null) - msg.DeleteAfter(10); - } - catch { } - }; - + { + try + { + IUserMessage msg; + if (paused) + msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); + else + msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); + if (msg != null) + msg.DeleteAfter(10); + } + catch { } + }; + mp.SongRemoved += async (song, index) => { try @@ -892,7 +908,7 @@ namespace NadekoBot.Modules.Music .WithFooter(ef => ef.WithText(song.PrettyInfo)) .WithErrorColor(); - await textCh.EmbedAsync(embed).ConfigureAwait(false); + await mp.OutputTextChannel.EmbedAsync(embed).ConfigureAwait(false); } catch { } diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 4388c9bd..e89ba368 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -6782,6 +6782,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to setmusicchannel smch. + /// + public static string setmusicchannel_cmd { + get { + return ResourceManager.GetString("setmusicchannel_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sets the current channel as the default music output channel. This will output playing, finished, paused and removed songs to that channel instead of the channel where the first song was queued in.. + /// + public static string setmusicchannel_desc { + get { + return ResourceManager.GetString("setmusicchannel_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}smch`. + /// + public static string setmusicchannel_usage { + get { + return ResourceManager.GetString("setmusicchannel_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to setmuterole. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 2dc50365..7ee5714b 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -3033,4 +3033,13 @@ `{0}mal straysocks` + + setmusicchannel smch + + + Sets the current channel as the default music output channel. This will output playing, finished, paused and removed songs to that channel instead of the channel where the first song was queued in. + + + `{0}smch` + \ No newline at end of file