mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Fixed an incredibly silly bug where the bot would attempt to update the session token when the client hadn't yet been initialized, which would cause it to catch a null and get caught in a loop. This error was silent when caused by a reconnect event :(
This commit is contained in:
@@ -40,10 +40,6 @@ public class ChatBot
|
||||
|
||||
_kfTokenService = new KfTokenService(settings[BuiltIn.Keys.KiwiFarmsDomain].Value!,
|
||||
settings[BuiltIn.Keys.Proxy].Value, _cancellationToken);
|
||||
if (_kfTokenService.GetXfSessionCookie() == null)
|
||||
{
|
||||
RefreshXfToken().Wait(_cancellationToken);
|
||||
}
|
||||
|
||||
KfClient = new ChatClient(new ChatClientConfigModel
|
||||
{
|
||||
@@ -53,6 +49,11 @@ public class ChatBot
|
||||
Proxy = settings[BuiltIn.Keys.Proxy].Value,
|
||||
ReconnectTimeout = settings[BuiltIn.Keys.KiwiFarmsWsReconnectTimeout].ToType<int>()
|
||||
});
|
||||
|
||||
if (_kfTokenService.GetXfSessionCookie() == null)
|
||||
{
|
||||
RefreshXfToken().Wait(_cancellationToken);
|
||||
}
|
||||
|
||||
_logger.Debug("Creating bot command instance");
|
||||
_botCommands = new BotCommands(this, _cancellationToken);
|
||||
@@ -127,7 +128,15 @@ public class ChatBot
|
||||
await Helpers.GetMultipleValues([BuiltIn.Keys.KiwiFarmsUsername, BuiltIn.Keys.KiwiFarmsPassword]);
|
||||
await _kfTokenService.PerformLogin(settings[BuiltIn.Keys.KiwiFarmsUsername].Value!,
|
||||
settings[BuiltIn.Keys.KiwiFarmsPassword].Value!);
|
||||
KfClient.UpdateToken(_kfTokenService.GetXfSessionCookie()!);
|
||||
var newCookie = _kfTokenService.GetXfSessionCookie();
|
||||
_logger.Debug($"GetXfSessionCookie returned => {newCookie}");
|
||||
if (newCookie == null)
|
||||
{
|
||||
// The bot will re-run this method continually in the event of a login issue
|
||||
_logger.Error("Failed to retrieve new session cookie");
|
||||
return;
|
||||
}
|
||||
KfClient.UpdateToken(newCookie);
|
||||
await _kfTokenService.SaveCookies();
|
||||
_logger.Info("Successfully logged in");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user