!!smch added. Set music output's text channel.

This commit is contained in:
Kwoth 2017-01-30 05:40:19 +01:00
parent 69cf15f07b
commit 81a4d553be
4 changed files with 75 additions and 20 deletions

View File

@ -71,6 +71,7 @@ namespace NadekoBot.Modules.Music.Classes
public event Action<bool> OnPauseChanged = delegate { }; public event Action<bool> OnPauseChanged = delegate { };
public IVoiceChannel PlaybackVoiceChannel { get; private set; } public IVoiceChannel PlaybackVoiceChannel { get; private set; }
public ITextChannel OutputTextChannel { get; set; }
private bool Destroyed { get; set; } = false; private bool Destroyed { get; set; } = false;
public bool RepeatSong { get; private set; } = false; public bool RepeatSong { get; private set; } = false;
@ -84,10 +85,12 @@ namespace NadekoBot.Modules.Music.Classes
public event Action<Song, int> SongRemoved = delegate { }; public event Action<Song, int> SongRemoved = delegate { };
public MusicPlayer(IVoiceChannel startingVoiceChannel, float? defaultVolume) public MusicPlayer(IVoiceChannel startingVoiceChannel, ITextChannel outputChannel, float? defaultVolume)
{ {
if (startingVoiceChannel == null) if (startingVoiceChannel == null)
throw new ArgumentNullException(nameof(startingVoiceChannel)); throw new ArgumentNullException(nameof(startingVoiceChannel));
OutputTextChannel = outputChannel;
Volume = defaultVolume ?? 1.0f; Volume = defaultVolume ?? 1.0f;
PlaybackVoiceChannel = startingVoiceChannel; PlaybackVoiceChannel = startingVoiceChannel;

View File

@ -797,6 +797,23 @@ namespace NadekoBot.Modules.Music
await Context.Channel.SendConfirmAsync("✅ Autoplay enabled.").ConfigureAwait(false); 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) 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) 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; 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 playingMessage = null;
IUserMessage lastFinishedMessage = null; IUserMessage lastFinishedMessage = null;
mp.OnCompleted += async (s, song) => mp.OnCompleted += async (s, song) =>
@ -825,7 +842,7 @@ namespace NadekoBot.Modules.Music
if (lastFinishedMessage != null) if (lastFinishedMessage != null)
lastFinishedMessage.DeleteAfter(0); 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()) .WithAuthor(eab => eab.WithName("Finished Song").WithMusicIcon())
.WithDescription(song.PrettyName) .WithDescription(song.PrettyName)
.WithFooter(ef => ef.WithText(song.PrettyInfo))) .WithFooter(ef => ef.WithText(song.PrettyInfo)))
@ -857,7 +874,7 @@ namespace NadekoBot.Modules.Music
if (playingMessage != null) if (playingMessage != null)
playingMessage.DeleteAfter(0); 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()) .WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon())
.WithDescription(song.PrettyName) .WithDescription(song.PrettyName)
.WithFooter(ef => ef.WithText(song.PrettyInfo))) .WithFooter(ef => ef.WithText(song.PrettyInfo)))
@ -871,9 +888,9 @@ namespace NadekoBot.Modules.Music
{ {
IUserMessage msg; IUserMessage msg;
if (paused) if (paused)
msg = await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false);
else else
msg = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
if (msg != null) if (msg != null)
msg.DeleteAfter(10); msg.DeleteAfter(10);
@ -881,7 +898,6 @@ namespace NadekoBot.Modules.Music
catch { } catch { }
}; };
mp.SongRemoved += async (song, index) => mp.SongRemoved += async (song, index) =>
{ {
try try
@ -892,7 +908,7 @@ namespace NadekoBot.Modules.Music
.WithFooter(ef => ef.WithText(song.PrettyInfo)) .WithFooter(ef => ef.WithText(song.PrettyInfo))
.WithErrorColor(); .WithErrorColor();
await textCh.EmbedAsync(embed).ConfigureAwait(false); await mp.OutputTextChannel.EmbedAsync(embed).ConfigureAwait(false);
} }
catch { } catch { }

View File

@ -6782,6 +6782,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to setmusicchannel smch.
/// </summary>
public static string setmusicchannel_cmd {
get {
return ResourceManager.GetString("setmusicchannel_cmd", resourceCulture);
}
}
/// <summary>
/// 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..
/// </summary>
public static string setmusicchannel_desc {
get {
return ResourceManager.GetString("setmusicchannel_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}smch`.
/// </summary>
public static string setmusicchannel_usage {
get {
return ResourceManager.GetString("setmusicchannel_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to setmuterole. /// Looks up a localized string similar to setmuterole.
/// </summary> /// </summary>

View File

@ -3033,4 +3033,13 @@
<data name="mal_usage" xml:space="preserve"> <data name="mal_usage" xml:space="preserve">
<value>`{0}mal straysocks`</value> <value>`{0}mal straysocks`</value>
</data> </data>
<data name="setmusicchannel_cmd" xml:space="preserve">
<value>setmusicchannel smch</value>
</data>
<data name="setmusicchannel_desc" xml:space="preserve">
<value>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.</value>
</data>
<data name="setmusicchannel_usage" xml:space="preserve">
<value>`{0}smch`</value>
</data>
</root> </root>