mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-03-09 04:12:05 +00:00
Merge pull request #126 from 13xforever/vnext
Attempt to restart the bot on catastrophic failures
This commit is contained in:
commit
bff94b07ee
@ -67,19 +67,7 @@ namespace CompatBot.Commands
|
||||
await ctx.SendAutosplitMessageAsync("```" + stdout + "```").ConfigureAwait(false);
|
||||
}
|
||||
await ctx.RespondAsync("Restarting...").ConfigureAwait(false);
|
||||
using (var self = new Process
|
||||
{
|
||||
#if DEBUG
|
||||
StartInfo = new ProcessStartInfo("dotnet", $"run -- {Config.Token} {ctx.Channel.Id}")
|
||||
#else
|
||||
StartInfo = new ProcessStartInfo("dotnet", $"run -c Release -- {Config.Token} {ctx.Channel.Id}")
|
||||
#endif
|
||||
})
|
||||
{
|
||||
self.Start();
|
||||
Config.Cts.Cancel();
|
||||
return;
|
||||
}
|
||||
Restart(ctx.Channel.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -105,6 +93,23 @@ namespace CompatBot.Commands
|
||||
Config.Cts.Cancel();
|
||||
}
|
||||
|
||||
|
||||
internal static void Restart(ulong channelId)
|
||||
{
|
||||
using (var self = new Process
|
||||
{
|
||||
#if DEBUG
|
||||
StartInfo = new ProcessStartInfo("dotnet", $"run -- {Config.Token} {channelId}")
|
||||
#else
|
||||
StartInfo = new ProcessStartInfo("dotnet", $"run -c Release -- {Config.Token} {channelId}")
|
||||
#endif
|
||||
})
|
||||
{
|
||||
self.Start();
|
||||
Config.Cts.Cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,13 @@ namespace CompatBot.EventHandlers
|
||||
{
|
||||
private static readonly Regex BuildResult = new Regex("build (succeed|pass)ed", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
||||
|
||||
public static async Task OnMessageCreated(MessageCreateEventArgs args)
|
||||
public static Task OnMessageCreated(MessageCreateEventArgs args)
|
||||
{
|
||||
OnMessageCreatedInternal(args);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public static async void OnMessageCreatedInternal(MessageCreateEventArgs args)
|
||||
{
|
||||
if (!args.Author.IsBot)
|
||||
return;
|
||||
@ -21,10 +27,11 @@ namespace CompatBot.EventHandlers
|
||||
if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
|
||||
return;
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(false);
|
||||
if (BuildResult.IsMatch(args.Message.Content))
|
||||
if (!await CompatList.UpdatesCheck.CheckForRpcs3Updates(args.Client, null).ConfigureAwait(false))
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);
|
||||
await Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(false);
|
||||
await CompatList.UpdatesCheck.CheckForRpcs3Updates(args.Client, null).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using CompatBot.EventHandlers;
|
||||
using CompatBot.ThumbScrapper;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace CompatBot
|
||||
@ -18,6 +19,7 @@ namespace CompatBot
|
||||
{
|
||||
private static readonly SemaphoreSlim InstanceCheck = new SemaphoreSlim(0, 1);
|
||||
private static readonly SemaphoreSlim ShutdownCheck = new SemaphoreSlim(0, 1);
|
||||
private const ulong InvalidChannelId = 13;
|
||||
|
||||
internal static async Task Main(string[] args)
|
||||
{
|
||||
@ -208,8 +210,17 @@ namespace CompatBot
|
||||
if (args.Length > 1 && ulong.TryParse(args[1], out var channelId))
|
||||
{
|
||||
Config.Log.Info($"Found channelId: {args[1]}");
|
||||
var channel = await client.GetChannelAsync(channelId).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync("Bot is up and running").ConfigureAwait(false);
|
||||
DiscordChannel channel;
|
||||
if (channelId == InvalidChannelId)
|
||||
{
|
||||
channel = await client.GetChannelAsync(Config.ThumbnailSpamId).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync("Bot has suffered some catastrophic failure and was restarted").ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
channel = await client.GetChannelAsync(channelId).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync("Bot is up and running").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Config.Log.Debug("Running RPC3 update check thread");
|
||||
@ -232,7 +243,8 @@ namespace CompatBot
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Config.Log.Fatal(e);
|
||||
Config.Log.Fatal(e, $"Experienced catastrofic failure, attempting to restart...");
|
||||
Sudo.Bot.Restart(InvalidChannelId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user