More logs

This commit is contained in:
Master Kwoth 2017-07-05 18:39:54 +02:00
parent 42923c5272
commit fbedf5878b
3 changed files with 64 additions and 48 deletions

View File

@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Music
_db = db; _db = db;
_music = music; _music = music;
_client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated; //_client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
_client.LeftGuild += _client_LeftGuild; _client.LeftGuild += _client_LeftGuild;
} }
@ -47,54 +47,54 @@ namespace NadekoBot.Modules.Music
} }
//todo changing server region is bugged again //todo changing server region is bugged again
private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState) //private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
{ //{
var t = Task.Run(() => // var t = Task.Run(() =>
{ // {
var usr = iusr as SocketGuildUser; // var usr = iusr as SocketGuildUser;
if (usr == null || // if (usr == null ||
oldState.VoiceChannel == newState.VoiceChannel) // oldState.VoiceChannel == newState.VoiceChannel)
return; // return;
var player = _music.GetPlayerOrDefault(usr.Guild.Id); // var player = _music.GetPlayerOrDefault(usr.Guild.Id);
if (player == null) // if (player == null)
return; // return;
try // try
{ // {
//if bot moved // //if bot moved
if ((player.VoiceChannel == oldState.VoiceChannel) && // if ((player.VoiceChannel == oldState.VoiceChannel) &&
usr.Id == _client.CurrentUser.Id) // usr.Id == _client.CurrentUser.Id)
{ // {
//if (player.Paused && newState.VoiceChannel.Users.Count > 1) //unpause if there are people in the new channel // //if (player.Paused && newState.VoiceChannel.Users.Count > 1) //unpause if there are people in the new channel
// player.TogglePause(); // // player.TogglePause();
//else if (!player.Paused && newState.VoiceChannel.Users.Count <= 1) // pause if there are no users in the new channel // //else if (!player.Paused && newState.VoiceChannel.Users.Count <= 1) // pause if there are no users in the new channel
// player.TogglePause(); // // player.TogglePause();
// player.SetVoiceChannel(newState.VoiceChannel); // // player.SetVoiceChannel(newState.VoiceChannel);
return; // return;
} // }
////if some other user moved // ////if some other user moved
//if ((player.VoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause // //if ((player.VoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause
// player.Paused && // // player.Paused &&
// newState.VoiceChannel.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.VoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause // // (player.VoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause
// !player.Paused && // // !player.Paused &&
// oldState.VoiceChannel.Users.Count == 1)) // // oldState.VoiceChannel.Users.Count == 1))
//{ // //{
// player.TogglePause(); // // player.TogglePause();
// return; // // return;
//} // //}
} // }
catch // catch
{ // {
// ignored // // ignored
} // }
}); // });
return Task.CompletedTask; // return Task.CompletedTask;
} //}
private async Task InternalQueue(MusicPlayer mp, SongInfo songInfo, bool silent) private async Task InternalQueue(MusicPlayer mp, SongInfo songInfo, bool silent)
{ {

View File

@ -136,6 +136,8 @@ namespace NadekoBot.Services.Music
this._musicService = musicService; this._musicService = musicService;
this._google = google; this._google = google;
_log.Info("Initialized");
_player = Task.Run(async () => _player = Task.Run(async () =>
{ {
while (!Exited) while (!Exited)
@ -193,7 +195,6 @@ namespace NadekoBot.Services.Music
while ((bytesRead = b.Read(buffer, 0, buffer.Length)) > 0 while ((bytesRead = b.Read(buffer, 0, buffer.Length)) > 0
&& (MaxPlaytimeSeconds <= 0 || MaxPlaytimeSeconds >= CurrentTime.TotalSeconds)) && (MaxPlaytimeSeconds <= 0 || MaxPlaytimeSeconds >= CurrentTime.TotalSeconds))
{ {
_log.Info("Sending stuff");
AdjustVolume(buffer, Volume); AdjustVolume(buffer, Volume);
await pcm.WriteAsync(buffer, 0, bytesRead, cancelToken).ConfigureAwait(false); await pcm.WriteAsync(buffer, 0, bytesRead, cancelToken).ConfigureAwait(false);
unchecked { _bytesSent += bytesRead; } unchecked { _bytesSent += bytesRead; }
@ -313,8 +314,8 @@ namespace NadekoBot.Services.Music
} }
do do
{ {
await Task.Delay(500);
_log.Info("Waiting for something to happen"); _log.Info("Waiting for something to happen");
await Task.Delay(500);
} }
while ((Queue.Count == 0 || Stopped) && !Exited); while ((Queue.Count == 0 || Stopped) && !Exited);
} }
@ -346,7 +347,11 @@ namespace NadekoBot.Services.Music
var t = _audioClient?.StopAsync(); var t = _audioClient?.StopAsync();
if (t != null) if (t != null)
{ {
_log.Info("Stopping audio client");
await t; await t;
_log.Info("Disposing audio client");
_audioClient.Dispose(); _audioClient.Dispose();
} }
} }
@ -354,13 +359,19 @@ namespace NadekoBot.Services.Music
{ {
} }
newVoiceChannel = false; newVoiceChannel = false;
_log.Info("Get current user");
var curUser = await VoiceChannel.Guild.GetCurrentUserAsync(); var curUser = await VoiceChannel.Guild.GetCurrentUserAsync();
if (curUser.VoiceChannel != null) if (curUser.VoiceChannel != null)
{ {
_log.Info("Connecting");
var ac = await VoiceChannel.ConnectAsync(); var ac = await VoiceChannel.ConnectAsync();
_log.Info("Connected, stopping");
await ac.StopAsync(); await ac.StopAsync();
_log.Info("Disconnected");
await Task.Delay(1000); await Task.Delay(1000);
} }
_log.Info("Connecting");
_audioClient = await VoiceChannel.ConnectAsync(); _audioClient = await VoiceChannel.ConnectAsync();
} }
catch catch

View File

@ -76,6 +76,7 @@ namespace NadekoBot.Services.Music
string GetText(string text, params object[] replacements) => string GetText(string text, params object[] replacements) =>
_strings.GetText(text, _localization.GetCultureInfo(textCh.Guild), "Music".ToLowerInvariant(), replacements); _strings.GetText(text, _localization.GetCultureInfo(textCh.Guild), "Music".ToLowerInvariant(), replacements);
_log.Info("Checks");
if (voiceCh == null || voiceCh.Guild != textCh.Guild) if (voiceCh == null || voiceCh.Guild != textCh.Guild)
{ {
if (textCh != null) if (textCh != null)
@ -84,14 +85,18 @@ namespace NadekoBot.Services.Music
} }
throw new ArgumentException(nameof(voiceCh)); throw new ArgumentException(nameof(voiceCh));
} }
_log.Info("Get or add");
return MusicPlayers.GetOrAdd(guildId, _ => return MusicPlayers.GetOrAdd(guildId, _ =>
{ {
_log.Info("Getting default volume");
var vol = GetDefaultVolume(guildId); var vol = GetDefaultVolume(guildId);
_log.Info("Creating musicplayer instance");
var mp = new MusicPlayer(this, _google, voiceCh, textCh, vol); var mp = new MusicPlayer(this, _google, voiceCh, textCh, vol);
IUserMessage playingMessage = null; IUserMessage playingMessage = null;
IUserMessage lastFinishedMessage = null; IUserMessage lastFinishedMessage = null;
_log.Info("Subscribing");
mp.OnCompleted += async (s, song) => mp.OnCompleted += async (s, song) =>
{ {
try try
@ -158,7 +163,7 @@ namespace NadekoBot.Services.Music
// ignored // ignored
} }
}; };
_log.Info("Done creating");
return mp; return mp;
}); });
} }