Skip to content
Permalink
Browse files

Fixes #583

  • Loading branch information...
Splamy committed Jun 22, 2019
1 parent 8d7e128 commit e024a1cc924fbcfd7eacca98aaa74d8d2afbaa0d
Showing with 21 additions and 26 deletions.
  1. +19 −24 TS3AudioBot/Bot.cs
  2. +2 −2 TS3AudioBot/Helper/Util.cs
@@ -79,7 +79,7 @@ public E<string> InitializeBot()
};
config.Events.IdleTime.Changed += (s, e) => EnableIdleTickWorker();
config.Events.OnIdle.Changed += (s, e) => EnableIdleTickWorker();

var builder = new DependencyBuilder(Injector);
builder.AddModule(this);
builder.AddModule(config);
@@ -180,7 +180,7 @@ private void OnBotDisconnect(object sender, DisconnectEventArgs e)

private void OnMessageReceived(object sender, TextMessage textMessage)
{
if(textMessage == null || textMessage.Message == null)
if (textMessage?.Message == null)
{
Log.Warn("Invalid TextMessage: {@textMessage}", textMessage);
return;
@@ -263,36 +263,31 @@ private void LoggedUpdateBotStatus(object sender, EventArgs e)
{
if (IsDisposed)
return;
var result = UpdateBotStatus();
if (!result)
Log.Warn(result.Error.Str);
UpdateBotStatus().UnwrapToLog(Log);
}

public E<LocalStr> UpdateBotStatus(string overrideStr = null)
{
if (!config.SetStatusDescription)
return R.Ok;

lock (SyncRoot)
string setString;
if (overrideStr != null)
{
string setString;
if (overrideStr != null)
{
setString = overrideStr;
}
else if (playManager.IsPlaying)
{
setString = QuizMode
? strings.info_botstatus_quiztime
: (playManager.CurrentPlayData.ResourceData.ResourceTitle);
}
else
{
setString = strings.info_botstatus_sleeping;
}

return clientConnection.ChangeDescription(setString ?? "");
setString = overrideStr;
}
else if (playManager.IsPlaying)
{
setString = QuizMode
? strings.info_botstatus_quiztime
: playManager.CurrentPlayData?.ResourceData?.ResourceTitle;
}
else
{
setString = strings.info_botstatus_sleeping;
}

return clientConnection.ChangeDescription(setString ?? "");
}

private void GenerateStatusImage(object sender, EventArgs e)
@@ -396,7 +391,7 @@ private void CallScript(ExecutionInformation info, string command, bool answer,
private ExecutionInformation CreateExecInfo(InvokerData invoker = null, UserSession session = null)
{
var info = new ExecutionInformation(Injector);
if(invoker is ClientCall ci)
if (invoker is ClientCall ci)
info.AddModule(ci);
info.AddModule(invoker ?? InvokerData.Anonymous);
info.AddModule(session ?? new AnonymousSession());
@@ -117,10 +117,10 @@ public static T UnwrapThrow<T>(this R<T, LocalStr> r)
throw new CommandException(r.Error.Str, CommandExceptionReason.CommandError);
}

public static bool UnwrapToLog(this E<LocalStr> r, NLog.Logger logger)
public static bool UnwrapToLog(this E<LocalStr> r, NLog.Logger logger, NLog.LogLevel level = null)
{
if (!r.Ok)
logger.Warn("Action errored: {0}", r.Error.Str);
logger.Log(level ?? NLog.LogLevel.Warn, r.Error.Str);
return r.Ok;
}

0 comments on commit e024a1c

Please sign in to comment.
You can’t perform that action at this time.