mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-11-23 10:19:39 +00:00
pass restart info through database to workaround docker lifecycle management
This commit is contained in:
parent
34439d1ee2
commit
eb9a34b9e9
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -175,6 +176,22 @@ namespace CompatBot.Commands
|
||||
|
||||
internal static void Restart(ulong channelId)
|
||||
{
|
||||
if (SandboxDetector.Detect() == SandboxType.Docker)
|
||||
{
|
||||
Config.Log.Info($"Saving channelId {channelId} into settings...");
|
||||
using (var db = new BotDb())
|
||||
{
|
||||
var ch = db.BotState.FirstOrDefault(k => k.Key == "bot-restart-channel");
|
||||
if (ch is null)
|
||||
{
|
||||
ch = new BotState {Key = "bot-restart-channel", Value = channelId.ToString()};
|
||||
db.BotState.Add(ch);
|
||||
}
|
||||
else
|
||||
ch.Value = channelId.ToString();
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
Config.Log.Info("Restarting...");
|
||||
using (var self = new Process
|
||||
{
|
||||
|
@ -253,9 +253,27 @@ namespace CompatBot
|
||||
throw;
|
||||
}
|
||||
|
||||
if (args.LastOrDefault() is string strCh && ulong.TryParse(strCh, out var channelId))
|
||||
ulong? channelId = null;
|
||||
if (SandboxDetector.Detect() == SandboxType.Docker)
|
||||
{
|
||||
Config.Log.Info($"Found channelId: {strCh} (parsed as {channelId})");
|
||||
using (var db = new BotDb())
|
||||
{
|
||||
var chState = db.BotState.FirstOrDefault(k => k.Key == "bot-restart-channel");
|
||||
if (chState != null)
|
||||
{
|
||||
if (ulong.TryParse(chState.Value, out var ch))
|
||||
channelId = ch;
|
||||
db.BotState.Remove(chState);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.LastOrDefault() is string strCh && ulong.TryParse(strCh, out var chId))
|
||||
channelId = chId;
|
||||
|
||||
if (channelId.HasValue)
|
||||
{
|
||||
Config.Log.Info($"Found channelId {channelId}");
|
||||
DiscordChannel channel;
|
||||
if (channelId == InvalidChannelId)
|
||||
{
|
||||
@ -264,7 +282,7 @@ namespace CompatBot
|
||||
}
|
||||
else
|
||||
{
|
||||
channel = await client.GetChannelAsync(channelId).ConfigureAwait(false);
|
||||
channel = await client.GetChannelAsync(channelId.Value).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync("Bot is up and running").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user