tweak discord reconnect to reattach to the SL client if discord dies but SL lives
This commit is contained in:
parent
7a31a40e92
commit
0afffb9adc
2 changed files with 26 additions and 8 deletions
|
|
@ -19,6 +19,16 @@ namespace SecondBotEvents.Services
|
||||||
LogoutExpected = true;
|
LogoutExpected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsConnected()
|
||||||
|
{
|
||||||
|
if (client == null) { return false; }
|
||||||
|
else if (client.Network == null) { return false; }
|
||||||
|
else if (client.Network.Connected == false) { return false; }
|
||||||
|
else if (client.Network.CurrentSim == null) { return false; }
|
||||||
|
else if (client.Network.CurrentSim.Connected == false) { return false; }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected bool ExitBot = false;
|
protected bool ExitBot = false;
|
||||||
|
|
||||||
protected Timer AutoRestartLoginTimer;
|
protected Timer AutoRestartLoginTimer;
|
||||||
|
|
|
||||||
|
|
@ -561,6 +561,11 @@ namespace SecondBotEvents.Services
|
||||||
LogFormater.Info("Discord service [Starting]");
|
LogFormater.Info("Discord service [Starting]");
|
||||||
master.SystemStatusMessagesEvent += SystemStatusEvent;
|
master.SystemStatusMessagesEvent += SystemStatusEvent;
|
||||||
master.BotClientNoticeEvent += BotClientRestart;
|
master.BotClientNoticeEvent += BotClientRestart;
|
||||||
|
if(master.BotClient.IsConnected() == true)
|
||||||
|
{
|
||||||
|
BotLoggedIn(this, new SimConnectedEventArgs(GetClient().Network.CurrentSim));
|
||||||
|
}
|
||||||
|
|
||||||
var config = new DiscordSocketConfig()
|
var config = new DiscordSocketConfig()
|
||||||
{
|
{
|
||||||
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildIntegrations | GatewayIntents.MessageContent
|
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildIntegrations | GatewayIntents.MessageContent
|
||||||
|
|
@ -595,10 +600,10 @@ namespace SecondBotEvents.Services
|
||||||
LogFormater.Info("Discord service [Stopping]");
|
LogFormater.Info("Discord service [Stopping]");
|
||||||
}
|
}
|
||||||
running = false;
|
running = false;
|
||||||
|
|
||||||
master.BotClientNoticeEvent -= BotClientRestart;
|
master.BotClientNoticeEvent -= BotClientRestart;
|
||||||
master.SystemStatusMessagesEvent -= SystemStatusEvent;
|
master.SystemStatusMessagesEvent -= SystemStatusEvent;
|
||||||
AcceptEventsFromSL = false;
|
AcceptEventsFromSL = false;
|
||||||
|
BotLoggedOut(this, new LoggedOutEventArgs(new List<UUID>());
|
||||||
if (DiscordClient != null)
|
if (DiscordClient != null)
|
||||||
{
|
{
|
||||||
DiscordClient.Dispose();
|
DiscordClient.Dispose();
|
||||||
|
|
@ -631,7 +636,7 @@ namespace SecondBotEvents.Services
|
||||||
{
|
{
|
||||||
if (e.isRestart == false)
|
if (e.isRestart == false)
|
||||||
{
|
{
|
||||||
LogFormater.Info("Discord service [Avi link]");
|
LogFormater.Info("Discord service [Avi link - waiting]");
|
||||||
AcceptEventsFromSL = false;
|
AcceptEventsFromSL = false;
|
||||||
LoginEventsAttached = false;
|
LoginEventsAttached = false;
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
|
|
@ -646,12 +651,15 @@ namespace SecondBotEvents.Services
|
||||||
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
|
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
|
||||||
{
|
{
|
||||||
LoginEventsAttached = false;
|
LoginEventsAttached = false;
|
||||||
|
if (GetClient() != null)
|
||||||
|
{
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
GetClient().Self.ChatFromSimulator -= LocalChat;
|
GetClient().Self.ChatFromSimulator -= LocalChat;
|
||||||
GetClient().Self.IM -= BotImMessage;
|
GetClient().Self.IM -= BotImMessage;
|
||||||
GetClient().Groups.CurrentGroups -= GroupCurrent;
|
GetClient().Groups.CurrentGroups -= GroupCurrent;
|
||||||
|
}
|
||||||
AcceptEventsFromSL = false;
|
AcceptEventsFromSL = false;
|
||||||
LogFormater.Info("Discord service [Avi link - standby]");
|
LogFormater.Info("Discord service [Avi link - lost connection to SL]");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BotImMessage(object o, InstantMessageEventArgs e)
|
protected void BotImMessage(object o, InstantMessageEventArgs e)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue