so fucking tired of this exception in the built-in IsBot check

This commit is contained in:
13xforever
2019-03-20 17:08:47 +05:00
parent 36de688880
commit 261fc77fe2
8 changed files with 43 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ using CompatApiClient.Utils;
using CompatBot.Commands;
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
@@ -24,7 +25,7 @@ namespace CompatBot.EventHandlers
public static async Task OnReaction(MessageReactionAddEventArgs e)
{
if (e.User.IsBot)
if (e.User.IsBotSafeCheck())
return;
var emoji = e.Client.GetEmoji(":piratethink:", Config.Reactions.PiracyCheck);
@@ -40,7 +41,7 @@ namespace CompatBot.EventHandlers
if (message.Channel.IsPrivate)
return true;
if (message.Author.IsBot)
if (message.Author.IsBotSafeCheck())
return true;
#if !DEBUG

View File

@@ -9,6 +9,7 @@ using CompatApiClient.Compression;
using CompatBot.Commands;
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
@@ -62,7 +63,7 @@ namespace CompatBot.EventHandlers
if (message.Channel.IsPrivate)
return true;
if (message.Author.IsBot)
if (message.Author.IsBotSafeCheck())
return true;
#if !DEBUG

View File

@@ -17,6 +17,7 @@ using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using CompatBot.EventHandlers.LogParsing.SourceHandlers;
using CompatBot.Utils.Extensions;
namespace CompatBot.EventHandlers
{
@@ -51,7 +52,7 @@ namespace CompatBot.EventHandlers
public static Task OnMessageCreated(MessageCreateEventArgs args)
{
var message = args.Message;
if (message.Author.IsBot)
if (message.Author.IsBotSafeCheck())
return Task.CompletedTask;
if (!string.IsNullOrEmpty(message.Content)

View File

@@ -2,6 +2,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CompatBot.Commands;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.EventArgs;
@@ -17,7 +18,7 @@ namespace CompatBot.EventHandlers
public static Task OnMessageCreated(MessageCreateEventArgs args)
{
if (args.Author.IsBot
if (args.Author.IsBotSafeCheck()
&& !args.Author.IsCurrent
&& "github".Equals(args.Channel.Name, StringComparison.InvariantCultureIgnoreCase)
&& !string.IsNullOrEmpty(args.Message.Content)

View File

@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
@@ -57,7 +57,7 @@ namespace CompatBot.EventHandlers
{
try
{
if (user.IsBot || channel.IsPrivate)
if (user.IsBotSafeCheck() || channel.IsPrivate)
return;
// in case it's not in cache and doesn't contain any info, including Author
@@ -127,7 +127,7 @@ namespace CompatBot.EventHandlers
.Select(r => r.Emoji)
.ToList();
var hit = false;
for (var i =0; i< reactionMsg.Count - 2; i++)
for (var i = 0; i < reactionMsg.Count - 2; i++)
if ((reactionMsg[i] == RidM || reactionMsg[i] == M)
&& reactionMsg[i + 1] == RidG
&& reactionMsg[i + 2] == RidS)
@@ -142,6 +142,5 @@ namespace CompatBot.EventHandlers
await message.ReactWithAsync(client, RidO).ConfigureAwait(false);
}
}
}
}

View File

@@ -4,6 +4,7 @@ using CompatApiClient.Utils;
using CompatBot.Commands;
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using CompatBot.Utils.ResultFormatters;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Exceptions;
@@ -15,7 +16,7 @@ namespace CompatBot.EventHandlers
{
public static async Task OnError(CommandErrorEventArgs e)
{
if (e.Context.User.IsBot)
if (e.Context.User.IsBotSafeCheck())
return;
if (!(e.Exception is CommandNotFoundException cnfe))

View File

@@ -1,4 +1,5 @@
using DSharpPlus.Entities;
using CompatBot.Utils.Extensions;
using DSharpPlus.Entities;
namespace CompatBot.Utils
{
@@ -6,7 +7,7 @@ namespace CompatBot.Utils
{
internal static bool IsFluff(DiscordMessage message)
{
if (message.Author.IsBot)
if (message.Author.IsBotSafeCheck())
return true;
if (string.IsNullOrEmpty(message.Content)

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using DSharpPlus.Entities;
namespace CompatBot.Utils.Extensions
{
public static class DiscordUserExtensions
{
public static bool IsBotSafeCheck(this DiscordUser user)
{
try
{
return user.IsBot;
}
catch (KeyNotFoundException)
{
return false;
}
catch (Exception e)
{
Config.Log.Warn(e);
return false;
}
}
}
}