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

View File

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

View File

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