Music with Embeds and cool Avatars

This commit is contained in:
samvaio 2016-12-15 01:18:44 +05:30 committed by GitHub
parent 8b5b49bf3c
commit 3674512073

View File

@ -30,9 +30,34 @@ namespace NadekoBot.Modules.Music
//it can fail if its currenctly opened or doesn't exist. Either way i don't care //it can fail if its currenctly opened or doesn't exist. Either way i don't care
try { Directory.Delete(MusicDataPath, true); } catch { } try { Directory.Delete(MusicDataPath, true); } catch { }
NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
Directory.CreateDirectory(MusicDataPath); Directory.CreateDirectory(MusicDataPath);
} }
private Task Client_UserVoiceStateUpdated(IUser iusr, IVoiceState oldState, IVoiceState newState)
{
var usr = iusr as IGuildUser;
if (usr == null ||
oldState.VoiceChannel == newState.VoiceChannel)
return Task.CompletedTask;
MusicPlayer player;
if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player))
return Task.CompletedTask;
if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause
player.Paused &&
player.PlaybackVoiceChannel.GetUsers().Count == 2) || // keep in mind bot is in the channel (+1)
(player.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause
!player.Paused &&
player.PlaybackVoiceChannel.GetUsers().Count == 1))
{
player.TogglePause();
}
return Task.CompletedTask;
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public Task Next(IUserMessage umsg, int skipCount = 1) public Task Next(IUserMessage umsg, int skipCount = 1)
@ -96,10 +121,7 @@ namespace NadekoBot.Modules.Music
if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel) if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return; return;
musicPlayer.TogglePause(); musicPlayer.TogglePause();
if (musicPlayer.Paused)
await channel.SendConfirmAsync("🎵 Music Player **paused**.").ConfigureAwait(false);
else
await channel.SendConfirmAsync("🎵 Music Player **unpaused**.").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -803,10 +825,21 @@ namespace NadekoBot.Modules.Music
if (sender == null) if (sender == null)
return; return;
var msgTxt = $"🎵 Playing {song.PrettyName}\t `Volume: {(int)(sender.Volume * 100)}%`"; var msgTxt = $"🎵 Playing {song.PrettyName}\t `Vol: {(int)(sender.Volume * 100)}%`";
try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { } try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { }
} }
}; };
mp.OnPauseChanged += async (paused) =>
{
try
{
if (paused)
await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false);
else
await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
}
catch { }
};
return mp; return mp;
}); });
Song resolvedSong; Song resolvedSong;