!!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 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<Song, int> 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;

View File

@ -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,21 +883,20 @@ 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) =>
{
@ -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 { }

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>
/// Looks up a localized string similar to setmuterole.
/// </summary>

View File

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