Auto pause/unpause fixes. !!mv disabled as it breaks music. Better logs
This commit is contained in:
parent
2715f36aa9
commit
c04ff7ff94
@ -342,13 +342,13 @@ namespace NadekoBot.Modules.Music.Classes
|
||||
});
|
||||
}
|
||||
|
||||
public Task MoveToVoiceChannel(IVoiceChannel voiceChannel)
|
||||
{
|
||||
if (audioClient?.ConnectionState != ConnectionState.Connected)
|
||||
throw new InvalidOperationException("Can't move while bot is not connected to voice channel.");
|
||||
PlaybackVoiceChannel = voiceChannel;
|
||||
return PlaybackVoiceChannel.ConnectAsync();
|
||||
}
|
||||
//public async Task MoveToVoiceChannel(IVoiceChannel voiceChannel)
|
||||
//{
|
||||
// if (audioClient?.ConnectionState != ConnectionState.Connected)
|
||||
// throw new InvalidOperationException("Can't move while bot is not connected to voice channel.");
|
||||
// PlaybackVoiceChannel = voiceChannel;
|
||||
// audioClient = await voiceChannel.ConnectAsync().ConfigureAwait(false);
|
||||
//}
|
||||
|
||||
public bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong;
|
||||
|
||||
|
@ -47,18 +47,36 @@ namespace NadekoBot.Modules.Music
|
||||
MusicPlayer player;
|
||||
if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var users = await player.PlaybackVoiceChannel.GetUsersAsync().Flatten().ConfigureAwait(false);
|
||||
|
||||
|
||||
//if bot moved
|
||||
if ((player.PlaybackVoiceChannel == oldState.VoiceChannel) &&
|
||||
usr.Id == NadekoBot.Client.CurrentUser.Id)
|
||||
{
|
||||
if (player.Paused && newState.VoiceChannel.Users.Count > 1) //unpause if there are people in the new channel
|
||||
player.TogglePause();
|
||||
else if (!player.Paused && newState.VoiceChannel.Users.Count <= 1) // pause if there are no users in the new channel
|
||||
player.TogglePause();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//if some other user moved
|
||||
if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause
|
||||
player.Paused &&
|
||||
users.Count() == 2) || // keep in mind bot is in the channel (+1)
|
||||
newState.VoiceChannel.Users.Count == 2) || // keep in mind bot is in the channel (+1)
|
||||
(player.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause
|
||||
!player.Paused &&
|
||||
users.Count() == 1))
|
||||
oldState.VoiceChannel.Users.Count == 1))
|
||||
{
|
||||
player.TogglePause();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@ -448,17 +466,17 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Move()
|
||||
{
|
||||
//[NadekoCommand, Usage, Description, Aliases]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Move()
|
||||
//{
|
||||
|
||||
MusicPlayer musicPlayer;
|
||||
var voiceChannel = ((IGuildUser)Context.User).VoiceChannel;
|
||||
if (voiceChannel == null || voiceChannel.Guild != Context.Guild || !MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
|
||||
return;
|
||||
await musicPlayer.MoveToVoiceChannel(voiceChannel);
|
||||
}
|
||||
// MusicPlayer musicPlayer;
|
||||
// var voiceChannel = ((IGuildUser)Context.User).VoiceChannel;
|
||||
// if (voiceChannel == null || voiceChannel.Guild != Context.Guild || !MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
|
||||
// return;
|
||||
// await musicPlayer.MoveToVoiceChannel(voiceChannel);
|
||||
//}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
@ -118,7 +118,7 @@ namespace NadekoBot
|
||||
|
||||
private Task Client_Log(LogMessage arg)
|
||||
{
|
||||
_log.Warn(arg.Message);
|
||||
_log.Warn(arg.Source + " | " + arg.Message);
|
||||
if (arg.Exception != null)
|
||||
_log.Warn(arg.Exception);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user