if server is unknown, leave it

This commit is contained in:
13xforever 2018-09-08 20:41:56 +05:00 committed by Roberto Anić Banić
parent 90c0314bca
commit 7930121134
2 changed files with 20 additions and 2 deletions

View File

@ -9,6 +9,7 @@ namespace CompatBot
internal static class Config
{
public static readonly string CommandPrefix = "!";
public static readonly ulong BotGuildId = 272035812277878785;
public static readonly ulong BotChannelId = 291679908067803136;
public static readonly ulong BotSpamId = 319224795785068545;
public static readonly ulong BotLogId = 436972161572536329;

View File

@ -40,7 +40,13 @@ namespace CompatBot
{
while (!Config.Cts.IsCancellationRequested)
{
CompatList.CheckForRpcs3Updates((DiscordClient)client, null).ConfigureAwait(false).GetAwaiter().GetResult();
try
{
CompatList.CheckForRpcs3Updates((DiscordClient)client, null).ConfigureAwait(false).GetAwaiter().GetResult();
}
catch
{
}
Task.Delay(TimeSpan.FromMinutes(1), Config.Cts.Token).ConfigureAwait(false).GetAwaiter().GetResult();
}
});
@ -108,6 +114,17 @@ namespace CompatBot
};
client.GuildAvailable += async gaArgs =>
{
if (gaArgs.Guild.Id != Config.BotGuildId)
{
#if DEBUG
gaArgs.Client.DebugLogger.LogMessage(LogLevel.Warning, "", $"Unknown discord server {gaArgs.Guild.Id} ({gaArgs.Guild.Name})", DateTime.Now);
#else
gaArgs.Client.DebugLogger.LogMessage(LogLevel.Warning, "", $"Unknown discord server {gaArgs.Guild.Id} ({gaArgs.Guild.Name}), leaving...", DateTime.Now);
await gaArgs.Guild.LeaveAsync().ConfigureAwait(false);
#endif
return;
}
gaArgs.Client.DebugLogger.LogMessage(LogLevel.Info, "", $"Server {gaArgs.Guild.Name} is available now", DateTime.Now);
gaArgs.Client.DebugLogger.LogMessage(LogLevel.Info, "", $"Checking moderation backlogs in {gaArgs.Guild.Name}...", DateTime.Now);
try
@ -119,7 +136,7 @@ namespace CompatBot
}
catch (Exception e)
{
client.DebugLogger.LogMessage(LogLevel.Warning, "", e.ToString(), DateTime.Now);
gaArgs.Client.DebugLogger.LogMessage(LogLevel.Warning, "", e.ToString(), DateTime.Now);
}
Console.WriteLine($"All moderation backlogs checked in {gaArgs.Guild.Name}.");
};