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)
|
//public async Task MoveToVoiceChannel(IVoiceChannel voiceChannel)
|
||||||
{
|
//{
|
||||||
if (audioClient?.ConnectionState != ConnectionState.Connected)
|
// if (audioClient?.ConnectionState != ConnectionState.Connected)
|
||||||
throw new InvalidOperationException("Can't move while bot is not connected to voice channel.");
|
// throw new InvalidOperationException("Can't move while bot is not connected to voice channel.");
|
||||||
PlaybackVoiceChannel = voiceChannel;
|
// PlaybackVoiceChannel = voiceChannel;
|
||||||
return PlaybackVoiceChannel.ConnectAsync();
|
// audioClient = await voiceChannel.ConnectAsync().ConfigureAwait(false);
|
||||||
}
|
//}
|
||||||
|
|
||||||
public bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong;
|
public bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong;
|
||||||
|
|
||||||
|
@ -47,18 +47,36 @@ namespace NadekoBot.Modules.Music
|
|||||||
MusicPlayer player;
|
MusicPlayer player;
|
||||||
if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player))
|
if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
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
|
if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause
|
||||||
player.Paused &&
|
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.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause
|
||||||
!player.Paused &&
|
!player.Paused &&
|
||||||
users.Count() == 1))
|
oldState.VoiceChannel.Users.Count == 1))
|
||||||
{
|
{
|
||||||
player.TogglePause();
|
player.TogglePause();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
@ -448,17 +466,17 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
//[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
//[RequireContext(ContextType.Guild)]
|
||||||
public async Task Move()
|
//public async Task Move()
|
||||||
{
|
//{
|
||||||
|
|
||||||
MusicPlayer musicPlayer;
|
// MusicPlayer musicPlayer;
|
||||||
var voiceChannel = ((IGuildUser)Context.User).VoiceChannel;
|
// var voiceChannel = ((IGuildUser)Context.User).VoiceChannel;
|
||||||
if (voiceChannel == null || voiceChannel.Guild != Context.Guild || !MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
|
// if (voiceChannel == null || voiceChannel.Guild != Context.Guild || !MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
|
||||||
return;
|
// return;
|
||||||
await musicPlayer.MoveToVoiceChannel(voiceChannel);
|
// await musicPlayer.MoveToVoiceChannel(voiceChannel);
|
||||||
}
|
//}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
|
@ -118,7 +118,7 @@ namespace NadekoBot
|
|||||||
|
|
||||||
private Task Client_Log(LogMessage arg)
|
private Task Client_Log(LogMessage arg)
|
||||||
{
|
{
|
||||||
_log.Warn(arg.Message);
|
_log.Warn(arg.Source + " | " + arg.Message);
|
||||||
if (arg.Exception != null)
|
if (arg.Exception != null)
|
||||||
_log.Warn(arg.Exception);
|
_log.Warn(arg.Exception);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user