update dependencies

This commit is contained in:
13xforever
2020-10-07 14:20:57 +05:00
parent e7956ce342
commit c6fac43217
24 changed files with 115 additions and 96 deletions

View File

@@ -30,10 +30,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.0.0-nightly-00728" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.0.0-nightly-00728" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.0.0-nightly-00728" />
<PackageReference Include="Google.Apis.Drive.v3" Version="1.49.0.2072" />
<PackageReference Include="DSharpPlus" Version="4.0.0-nightly-00737" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.0.0-nightly-00737" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.0.0-nightly-00737" />
<PackageReference Include="Google.Apis.Drive.v3" Version="1.49.0.2091" />
<PackageReference Include="ksemenenko.ColorThief" Version="1.1.1.4" />
<PackageReference Include="MathParser.org-mXparser" Version="4.4.2" />
<PackageReference Include="MegaApiClient" Version="1.8.2" />
@@ -56,7 +56,7 @@
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.153.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Services.Client" Version="16.153.0" />
<PackageReference Include="Nerdbank.Streams" Version="2.6.78" />
<PackageReference Include="Nerdbank.Streams" Version="2.6.81" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog" Version="4.7.5" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.5" />

View File

@@ -76,7 +76,7 @@ namespace CompatBot.EventHandlers
public static DiscordEmoji RandomNegativeReaction { get { lock (theDoor) return SadReactions[rng.Next(SadReactions.Length)]; } }
public static DiscordEmoji RandomPositiveReaction { get { lock (theDoor) return ThankYouReactions[rng.Next(ThankYouReactions.Length)]; } }
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args.Message))
return;
@@ -181,9 +181,9 @@ namespace CompatBot.EventHandlers
}
await args.Message.ReactWithAsync(emoji, sadMessage).ConfigureAwait(false);
if (args.Author.IsSmartlisted(args.Client, args.Message.Channel.Guild))
if (args.Author.IsSmartlisted(c, args.Message.Channel.Guild))
{
var botMember = args.Guild?.CurrentMember ?? args.Client.GetMember(args.Client.CurrentUser);
var botMember = args.Guild?.CurrentMember ?? c.GetMember(c.CurrentUser);
if (args.Channel.PermissionsFor(botMember).HasPermission(Permissions.ReadMessageHistory))
{
var lastBotMessages = await args.Channel.GetMessagesBeforeAsync(args.Message.Id, 20, DateTime.UtcNow.Add(-Config.ShutupTimeLimitInMin)).ConfigureAwait(false);

View File

@@ -2,33 +2,34 @@
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.EventArgs;
namespace CompatBot.EventHandlers
{
internal static class ContentFilterMonitor
{
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
{
args.Handled = !await ContentFilter.IsClean(args.Client, args.Message).ConfigureAwait(false);
args.Handled = !await ContentFilter.IsClean(c, args.Message).ConfigureAwait(false);
}
public static async Task OnMessageUpdated(MessageUpdateEventArgs args)
public static async Task OnMessageUpdated(DiscordClient c, MessageUpdateEventArgs args)
{
args.Handled = !await ContentFilter.IsClean(args.Client, args.Message).ConfigureAwait(false);
args.Handled = !await ContentFilter.IsClean(c, args.Message).ConfigureAwait(false);
}
public static async Task OnReaction(MessageReactionAddEventArgs e)
public static async Task OnReaction(DiscordClient c, MessageReactionAddEventArgs e)
{
if (e.User.IsBotSafeCheck())
return;
var emoji = e.Client.GetEmoji(":piratethink:", Config.Reactions.PiracyCheck);
var emoji = c.GetEmoji(":piratethink:", Config.Reactions.PiracyCheck);
if (e.Emoji != emoji)
return;
var message = await e.Channel.GetMessageAsync(e.Message.Id).ConfigureAwait(false);
await ContentFilter.IsClean(e.Client, message).ConfigureAwait(false);
await ContentFilter.IsClean(c, message).ConfigureAwait(false);
}
}
}

View File

@@ -6,6 +6,7 @@ using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using CompatBot.Utils.ResultFormatters;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Caching.Memory;
@@ -18,7 +19,7 @@ namespace CompatBot.EventHandlers
public static readonly TimeSpan CacheRetainTime = TimeSpan.FromMinutes(1);
private static readonly SemaphoreSlim postLock = new SemaphoreSlim(1);
public static async Task OnMessageDeleted(MessageDeleteEventArgs e)
public static async Task OnMessageDeleted(DiscordClient c, MessageDeleteEventArgs e)
{
if (e.Channel.IsPrivate)
return;
@@ -33,13 +34,13 @@ namespace CompatBot.EventHandlers
if (RemovedByBotCache.TryGetValue(msg.Id, out _))
return;
var usernameWithNickname = msg.Author.GetUsernameWithNickname(e.Client, e.Guild);
var usernameWithNickname = msg.Author.GetUsernameWithNickname(c, e.Guild);
var logMsg = msg.Content;
if (msg.Attachments.Any())
logMsg += Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, msg.Attachments.Select(a => $"📎 {a.FileName}"));
Config.Log.Info($"Deleted message from {usernameWithNickname} ({msg.JumpLink}):{Environment.NewLine}{logMsg.TrimStart()}");
var logChannel = await e.Client.GetChannelAsync(Config.DeletedMessagesLogChannelId).ConfigureAwait(false);
var logChannel = await c.GetChannelAsync(Config.DeletedMessagesLogChannelId).ConfigureAwait(false);
if (logChannel == null)
return;

View File

@@ -28,14 +28,14 @@ namespace CompatBot.EventHandlers
private static readonly MemoryCache InviteCodeCache = new MemoryCache(new MemoryCacheOptions{ExpirationScanFrequency = TimeSpan.FromHours(1)});
private static readonly TimeSpan CacheDuration = TimeSpan.FromHours(24);
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
{
args.Handled = !await CheckMessageForInvitesAsync(args.Client, args.Message).ConfigureAwait(false);
args.Handled = !await CheckMessageForInvitesAsync(c, args.Message).ConfigureAwait(false);
}
public static async Task OnMessageUpdated(MessageUpdateEventArgs args)
public static async Task OnMessageUpdated(DiscordClient c, MessageUpdateEventArgs args)
{
args.Handled = !await CheckMessageForInvitesAsync(args.Client, args.Message).ConfigureAwait(false);
args.Handled = !await CheckMessageForInvitesAsync(c, args.Message).ConfigureAwait(false);
}
public static async Task CheckBacklogAsync(DiscordClient client, DiscordGuild guild)

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Caching.Memory;
@@ -19,7 +20,7 @@ namespace CompatBot.EventHandlers
private static readonly TimeSpan ThrottleDuration = TimeSpan.FromHours(1);
private static readonly MemoryCache Throttling = new MemoryCache(new MemoryCacheOptions {ExpirationScanFrequency = TimeSpan.FromMinutes(30)});
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient _c, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args.Message))
return;
@@ -65,8 +66,8 @@ namespace CompatBot.EventHandlers
}
}
public static Task OnMessageUpdated(MessageUpdateEventArgs e) => Backtrack(e.Channel, e.MessageBefore, false);
public static Task OnMessageDeleted(MessageDeleteEventArgs e) => Backtrack(e.Channel, e.Message, true);
public static Task OnMessageUpdated(DiscordClient _, MessageUpdateEventArgs e) => Backtrack(e.Channel, e.MessageBefore, false);
public static Task OnMessageDeleted(DiscordClient _, MessageDeleteEventArgs e) => Backtrack(e.Channel, e.Message, true);
private static async Task Backtrack(DiscordChannel channel, DiscordMessage message, bool removeFromQueue)
{

View File

@@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CompatBot.Commands;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.EventArgs;
namespace CompatBot.EventHandlers
@@ -19,7 +20,7 @@ namespace CompatBot.EventHandlers
private static readonly Regex IssueLink = new Regex(@"github.com/RPCS3/rpcs3/issues/(?<number>\d+)", DefaultOptions);
private static readonly GithubClient.Client Client = new GithubClient.Client();
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args.Message))
return;
@@ -59,7 +60,7 @@ namespace CompatBot.EventHandlers
if (GithubClient.Client.RateLimitRemaining - issuesToLookup.Count >= 10)
{
foreach (var issueId in issuesToLookup)
await Pr.LinkIssue(args.Client, args.Message, issueId).ConfigureAwait(false);
await Pr.LinkIssue(c, args.Message, issueId).ConfigureAwait(false);
}
else
{

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.VisualStudio.Services.Common;
@@ -17,7 +18,7 @@ namespace CompatBot.EventHandlers
private static readonly TCache MessageQueue = new TCache();
private static readonly Func<DiscordMessage, ulong> KeyGen = m => m.Id;
public static Task OnMessageCreated(MessageCreateEventArgs args)
public static Task OnMessageCreated(DiscordClient _, MessageCreateEventArgs args)
{
if (args.Channel.IsPrivate)
return Task.CompletedTask;
@@ -37,7 +38,7 @@ namespace CompatBot.EventHandlers
return Task.CompletedTask;
}
public static Task OnMessageDeleted(MessageDeleteEventArgs args)
public static Task OnMessageDeleted(DiscordClient _, MessageDeleteEventArgs args)
{
if (args.Channel.IsPrivate)
return Task.CompletedTask;
@@ -50,7 +51,7 @@ namespace CompatBot.EventHandlers
return Task.CompletedTask;
}
public static Task OnMessagesBulkDeleted(MessageBulkDeleteEventArgs args)
public static Task OnMessagesBulkDeleted(DiscordClient _, MessageBulkDeleteEventArgs args)
{
if (args.Channel.IsPrivate)
return Task.CompletedTask;
@@ -64,7 +65,7 @@ namespace CompatBot.EventHandlers
return Task.CompletedTask;
}
public static Task OnMessageUpdated(MessageUpdateEventArgs args)
public static Task OnMessageUpdated(DiscordClient _, MessageUpdateEventArgs args)
{
if (args.Channel.IsPrivate)
return Task.CompletedTask;

View File

@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using CompatBot.Database;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.EventArgs;
using Microsoft.EntityFrameworkCore;
@@ -8,7 +9,7 @@ namespace CompatBot.EventHandlers
{
internal static class Greeter
{
public static async Task OnMemberAdded(GuildMemberAddEventArgs args)
public static async Task OnMemberAdded(DiscordClient _, GuildMemberAddEventArgs args)
{
using var db = new BotDb();
var explanation = await db.Explanation.FirstOrDefaultAsync(e => e.Keyword == "motd").ConfigureAwait(false);

View File

@@ -10,6 +10,7 @@ using CompatBot.Commands;
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.ResultFormatters;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Caching.Memory;
@@ -29,7 +30,7 @@ namespace CompatBot.EventHandlers
private static readonly TimeSpan CooldownThreshold = TimeSpan.FromSeconds(5);
private static readonly Client Client = new Client();
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args?.Message))
return;
@@ -43,7 +44,7 @@ namespace CompatBot.EventHandlers
&& DateTime.UtcNow - lastCheck < CooldownThreshold)
return;
if (args.Author.IsSmartlisted(args.Client, args.Guild))
if (args.Author.IsSmartlisted(c, args.Guild))
return;
#endif
@@ -73,7 +74,7 @@ namespace CompatBot.EventHandlers
if (string.IsNullOrEmpty(gameTitle))
return;
var botSpamChannel = await args.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
var botSpamChannel = await c.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
var status = info.Status.ToLowerInvariant();
string msg;
if (status == "unknown")

View File

@@ -3,6 +3,7 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
@@ -12,7 +13,7 @@ namespace CompatBot.EventHandlers
{
private static readonly Regex LogLine = new Regex(@"^[`""]?(·|(\w|!)) ({(rsx|PPU|SPU)|LDR:)|E LDR:", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline);
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient _, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

View File

@@ -56,7 +56,7 @@ namespace CompatBot.EventHandlers
OnNewLog += EnqueueLogProcessing;
}
public static Task OnMessageCreated(MessageCreateEventArgs args)
public static Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
{
var message = args.Message;
if (message.Author.IsBotSafeCheck())
@@ -69,7 +69,7 @@ namespace CompatBot.EventHandlers
var checkExternalLinks = "help".Equals(args.Channel.Name, StringComparison.InvariantCultureIgnoreCase)
|| LimitedToSpamChannel.IsSpamChannel(args.Channel);
OnNewLog(args.Client, args.Channel, args.Message, checkExternalLinks: checkExternalLinks);
OnNewLog(c, args.Channel, args.Message, checkExternalLinks: checkExternalLinks);
return Task.CompletedTask;
}

View File

@@ -11,6 +11,7 @@ using CompatBot.Database;
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.EventArgs;
using DSharpPlus.Interactivity;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
@@ -20,12 +21,18 @@ namespace CompatBot.EventHandlers
{
internal sealed class MediaScreenshotMonitor
{
private static readonly ComputerVisionClient client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(Config.AzureComputerVisionKey)) {Endpoint = Config.AzureComputerVisionEndpoint};
private static readonly SemaphoreSlim workSemaphore = new SemaphoreSlim(0);
private static readonly ConcurrentQueue<(MessageCreateEventArgs evt, string readOperationId)> workQueue = new ConcurrentQueue<(MessageCreateEventArgs args, string readOperationId)>();
public static int MaxQueueLength = 0;
private readonly DiscordClient client;
private readonly ComputerVisionClient cvClient = new ComputerVisionClient(new ApiKeyServiceClientCredentials(Config.AzureComputerVisionKey)) {Endpoint = Config.AzureComputerVisionEndpoint};
private readonly SemaphoreSlim workSemaphore = new SemaphoreSlim(0);
private readonly ConcurrentQueue<(MessageCreateEventArgs evt, string readOperationId)> workQueue = new ConcurrentQueue<(MessageCreateEventArgs args, string readOperationId)>();
public static int MaxQueueLength { get; private set; } = 0;
public static async Task OnMessageCreated(MessageCreateEventArgs evt)
internal MediaScreenshotMonitor(DiscordClient client)
{
this.client = client;
}
public async Task OnMessageCreated(DiscordClient _, MessageCreateEventArgs evt)
{
var message = evt.Message;
if (message == null)
@@ -38,7 +45,7 @@ namespace CompatBot.EventHandlers
if (message.Author.IsBotSafeCheck())
return;
if (message.Author.IsSmartlisted(evt.Client))
if (message.Author.IsSmartlisted(client))
return;
#endif
@@ -48,7 +55,7 @@ namespace CompatBot.EventHandlers
var images = Vision.GetImageAttachment(message).ToList();
var tasks = new List<Task<BatchReadFileHeaders>>(images.Count);
foreach (var img in images)
tasks.Add(client.BatchReadFileAsync(img.Url, Config.Cts.Token));
tasks.Add(cvClient.BatchReadFileAsync(img.Url, Config.Cts.Token));
foreach (var t in tasks)
{
try
@@ -64,7 +71,7 @@ namespace CompatBot.EventHandlers
}
}
public static async Task ProcessWorkQueue()
public async Task ProcessWorkQueue()
{
if (string.IsNullOrEmpty(Config.AzureComputerVisionKey))
return;
@@ -90,7 +97,7 @@ namespace CompatBot.EventHandlers
try
{
var result = await client.GetReadOperationResultAsync(item.readOperationId, Config.Cts.Token).ConfigureAwait(false);
var result = await cvClient.GetReadOperationResultAsync(item.readOperationId, Config.Cts.Token).ConfigureAwait(false);
if (result.Status == TextOperationStatusCodes.Succeeded)
{
if (result.RecognitionResults.SelectMany(r => r.Lines).Any())
@@ -113,7 +120,7 @@ namespace CompatBot.EventHandlers
if ("media".Equals(item.evt.Channel.Name))
suppressFlags = FilterAction.SendMessage | FilterAction.ShowExplain;
await ContentFilter.PerformFilterActions(
item.evt.Client,
client,
item.evt.Message,
hit,
suppressFlags,
@@ -127,7 +134,7 @@ namespace CompatBot.EventHandlers
if (!cnt)
try
{
var botSpamCh = await item.evt.Client.GetChannelAsync(Config.ThumbnailSpamId).ConfigureAwait(false);
var botSpamCh = await client.GetChannelAsync(Config.ThumbnailSpamId).ConfigureAwait(false);
await botSpamCh.SendAutosplitMessageAsync(ocrText, blockStart: "", blockEnd: "").ConfigureAwait(false);
}
catch (Exception ex)

View File

@@ -19,7 +19,7 @@ namespace CompatBot.EventHandlers
private static readonly TimeSpan ActiveCheckResetThreshold = TimeSpan.FromMinutes(10);
private static readonly ConcurrentQueue<(DateTime start, DateTime end)> ExpectedNewBuildTimeFrames = new ConcurrentQueue<(DateTime start, DateTime end)>();
public static Task OnMessageCreated(MessageCreateEventArgs args)
public static Task OnMessageCreated(DiscordClient _, MessageCreateEventArgs args)
{
if (args.Author.IsBotSafeCheck()
&& !args.Author.IsCurrent

View File

@@ -5,6 +5,7 @@ using System.Threading;
using System.Threading.Tasks;
using CompatBot.Database;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.EventArgs;
using Microsoft.EntityFrameworkCore;
@@ -23,7 +24,7 @@ namespace CompatBot.EventHandlers
};
private static DateTime lastMention = DateTime.UtcNow.AddHours(-1);
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient _, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args?.Message))
return;

View File

@@ -21,7 +21,7 @@ namespace CompatBot.EventHandlers
public static readonly Regex ProductCode = new Regex(@"(?<letters>(?:[BPSUVX][CL]|P[ETU]|NP)[AEHJKPUIX][ABJKLMPQRS]|MRTC)[ \-]?(?<numbers>\d{5})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Client CompatClient = new Client();
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args.Message))
return;
@@ -54,7 +54,7 @@ namespace CompatBot.EventHandlers
if (codesToLookup.Count == 0)
return;
await LookupAndPostProductCodeEmbedAsync(args.Client, args.Message, codesToLookup).ConfigureAwait(false);
await LookupAndPostProductCodeEmbedAsync(c, args.Message, codesToLookup).ConfigureAwait(false);
}
public static async Task LookupAndPostProductCodeEmbedAsync(DiscordClient client, DiscordMessage message, List<string> codesToLookup)

View File

@@ -84,9 +84,9 @@ namespace CompatBot.EventHandlers
[DiscordEmoji.FromUnicode("〰")] = "W",
};
public static Task Handler(MessageReactionAddEventArgs args)
public static Task Handler(DiscordClient c, MessageReactionAddEventArgs args)
{
return CheckMessageAsync(args.Client, args.Channel, args.User, args.Message, args.Emoji, false);
return CheckMessageAsync(c, args.Channel, args.User, args.Message, args.Emoji, false);
}
public static async Task CheckBacklogAsync(DiscordClient client, DiscordGuild guild)

View File

@@ -2,6 +2,7 @@
using System.Threading.Tasks;
using CompatApiClient.Utils;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
@@ -11,7 +12,7 @@ namespace CompatBot.EventHandlers
{
private static readonly char[] OpenParen = {'(', '', 'ʕ'};
public static async Task OnMessageCreated(MessageCreateEventArgs args)
public static async Task OnMessageCreated(DiscordClient _, MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args.Message))
return;

View File

@@ -1,13 +1,14 @@
using System.Linq;
using System.Threading.Tasks;
using CompatBot.Database;
using DSharpPlus;
using DSharpPlus.EventArgs;
namespace CompatBot.EventHandlers
{
internal static class ThumbnailCacheMonitor
{
public static async Task OnMessageDeleted(MessageDeleteEventArgs args)
public static async Task OnMessageDeleted(DiscordClient _, MessageDeleteEventArgs args)
{
if (args.Channel.Id != Config.ThumbnailSpamId)
return;

View File

@@ -16,7 +16,7 @@ namespace CompatBot.EventHandlers
{
internal static class UnknownCommandHandler
{
public static async Task OnError(CommandErrorEventArgs e)
public static async Task OnError(CommandsNextExtension _, CommandErrorEventArgs e)
{
if (e.Context.User.IsBotSafeCheck())
return;

View File

@@ -21,20 +21,20 @@ namespace CompatBot.EventHandlers
private static readonly MemoryCache SpoofingReportThrottlingCache = new MemoryCache(new MemoryCacheOptions{ ExpirationScanFrequency = TimeSpan.FromMinutes(10) });
private static readonly TimeSpan SnoozeDuration = TimeSpan.FromHours(1);
public static async Task OnUserUpdated(UserUpdateEventArgs args)
public static async Task OnUserUpdated(DiscordClient c, UserUpdateEventArgs args)
{
if (args.UserBefore.Username == args.UserAfter.Username)
return;
var potentialTargets = GetPotentialVictims(args.Client, args.Client.GetMember(args.UserAfter), true, false);
var potentialTargets = GetPotentialVictims(c, c.GetMember(args.UserAfter), true, false);
if (!potentialTargets.Any())
return;
if (await IsFlashmobAsync(args.Client, potentialTargets).ConfigureAwait(false))
if (await IsFlashmobAsync(c, potentialTargets).ConfigureAwait(false))
return;
var m = args.Client.GetMember(args.UserAfter);
await args.Client.ReportAsync("🕵️ Potential user impersonation",
var m = c.GetMember(args.UserAfter);
await c.ReportAsync("🕵️ Potential user impersonation",
$"User {m.GetMentionWithNickname()} has changed their __username__ from " +
$"**{args.UserBefore.Username.Sanitize()}#{args.UserBefore.Discriminator}** to " +
$"**{args.UserAfter.Username.Sanitize()}#{args.UserAfter.Discriminator}**",
@@ -42,19 +42,19 @@ namespace CompatBot.EventHandlers
ReportSeverity.Medium);
}
public static async Task OnMemberUpdated(GuildMemberUpdateEventArgs args)
public static async Task OnMemberUpdated(DiscordClient c, GuildMemberUpdateEventArgs args)
{
if (args.NicknameBefore == args.NicknameAfter)
return;
var potentialTargets = GetPotentialVictims(args.Client, args.Member, false, true);
var potentialTargets = GetPotentialVictims(c, args.Member, false, true);
if (!potentialTargets.Any())
return;
if (await IsFlashmobAsync(args.Client, potentialTargets).ConfigureAwait(false))
if (await IsFlashmobAsync(c, potentialTargets).ConfigureAwait(false))
return;
await args.Client.ReportAsync("🕵️ Potential user impersonation",
await c.ReportAsync("🕵️ Potential user impersonation",
$"Member {args.Member.GetMentionWithNickname()} has changed their __display name__ from " +
$"**{(args.NicknameBefore ?? args.Member.Username).Sanitize()}** to " +
$"**{args.Member.DisplayName.Sanitize()}**",
@@ -62,16 +62,16 @@ namespace CompatBot.EventHandlers
ReportSeverity.Medium);
}
public static async Task OnMemberAdded(GuildMemberAddEventArgs args)
public static async Task OnMemberAdded(DiscordClient c, GuildMemberAddEventArgs args)
{
var potentialTargets = GetPotentialVictims(args.Client, args.Member, true, true);
var potentialTargets = GetPotentialVictims(c, args.Member, true, true);
if (!potentialTargets.Any())
return;
if (await IsFlashmobAsync(args.Client, potentialTargets).ConfigureAwait(false))
if (await IsFlashmobAsync(c, potentialTargets).ConfigureAwait(false))
return;
await args.Client.ReportAsync("🕵️ Potential user impersonation",
await c.ReportAsync("🕵️ Potential user impersonation",
$"New member joined the server: {args.Member.GetMentionWithNickname()}",
potentialTargets,
ReportSeverity.Medium);

View File

@@ -14,8 +14,8 @@ namespace CompatBot.EventHandlers
{
public static class UsernameValidationMonitor
{
public static Task OnMemberUpdated(GuildMemberUpdateEventArgs args) => UpdateDisplayName(args.Guild, args.Member);
public static Task OnMemberAdded(GuildMemberAddEventArgs args) => UpdateDisplayName(args.Guild, args.Member);
public static Task OnMemberUpdated(DiscordClient _, GuildMemberUpdateEventArgs args) => UpdateDisplayName(args.Guild, args.Member);
public static Task OnMemberAdded(DiscordClient _, GuildMemberAddEventArgs args) => UpdateDisplayName(args.Guild, args.Member);
private static async Task UpdateDisplayName(DiscordGuild guild, DiscordMember guildMember)
{

View File

@@ -18,19 +18,19 @@ namespace CompatBot.EventHandlers
'꧁', '꧂', '⎝', '⎠', '', '', '⎛', '⎞',
};
public static async Task OnUserUpdated(UserUpdateEventArgs args)
public static async Task OnUserUpdated(DiscordClient c, UserUpdateEventArgs args)
{
try
{
var m = args.Client.GetMember(args.UserAfter);
var m = c.GetMember(args.UserAfter);
if (NeedsRename(m.DisplayName))
{
var suggestedName = StripZalgo(m.DisplayName, m.Id).Sanitize();
await args.Client.ReportAsync("🔣 Potential display name issue",
await c.ReportAsync("🔣 Potential display name issue",
$"User {m.GetMentionWithNickname()} has changed their __username__ and is now shown as **{m.DisplayName.Sanitize()}**\nAutomatically renamed to: **{suggestedName}**",
null,
ReportSeverity.Medium);
await DmAndRenameUserAsync(args.Client, args.Client.GetMember(args.UserAfter), suggestedName).ConfigureAwait(false);
await DmAndRenameUserAsync(c, c.GetMember(args.UserAfter), suggestedName).ConfigureAwait(false);
}
}
catch (Exception e)
@@ -39,7 +39,7 @@ namespace CompatBot.EventHandlers
}
}
public static async Task OnMemberUpdated(GuildMemberUpdateEventArgs args)
public static async Task OnMemberUpdated(DiscordClient c, GuildMemberUpdateEventArgs args)
{
try
{
@@ -49,11 +49,11 @@ namespace CompatBot.EventHandlers
if (NeedsRename(name))
{
var suggestedName = StripZalgo(name, args.Member.Id).Sanitize();
await args.Client.ReportAsync("🔣 Potential display name issue",
await c.ReportAsync("🔣 Potential display name issue",
$"Member {member.GetMentionWithNickname()} has changed their __display name__ and is now shown as **{name.Sanitize()}**\nAutomatically renamed to: **{suggestedName}**",
null,
ReportSeverity.Medium);
await DmAndRenameUserAsync(args.Client, member, suggestedName).ConfigureAwait(false);
await DmAndRenameUserAsync(c, member, suggestedName).ConfigureAwait(false);
}
}
catch (Exception e)
@@ -62,7 +62,7 @@ namespace CompatBot.EventHandlers
}
}
public static async Task OnMemberAdded(GuildMemberAddEventArgs args)
public static async Task OnMemberAdded(DiscordClient c, GuildMemberAddEventArgs args)
{
try
{
@@ -70,11 +70,11 @@ namespace CompatBot.EventHandlers
if (NeedsRename(name))
{
var suggestedName = StripZalgo(name, args.Member.Id).Sanitize();
await args.Client.ReportAsync("🔣 Potential display name issue",
await c.ReportAsync("🔣 Potential display name issue",
$"New member joined the server: {args.Member.GetMentionWithNickname()} and is shown as **{name.Sanitize()}**\nAutomatically renamed to: **{suggestedName}**",
null,
ReportSeverity.Medium);
await DmAndRenameUserAsync(args.Client, args.Member, suggestedName).ConfigureAwait(false);
await DmAndRenameUserAsync(c, args.Member, suggestedName).ConfigureAwait(false);
}
}
catch (Exception e)

View File

@@ -114,7 +114,6 @@ namespace CompatBot
GameTdbScraper.RunAsync(Config.Cts.Token),
#endif
StatsStorage.BackgroundSaveAsync(),
MediaScreenshotMonitor.ProcessWorkQueue(),
CompatList.ImportCompatListAsync()
);
@@ -171,18 +170,18 @@ namespace CompatBot
client.UseInteractivity(new InteractivityConfiguration());
client.Ready += async r =>
client.Ready += async (c, _) =>
{
var admin = await r.Client.GetUserAsync(Config.BotAdminId).ConfigureAwait(false);
var admin = await c.GetUserAsync(Config.BotAdminId).ConfigureAwait(false);
Config.Log.Info("Bot is ready to serve!");
Config.Log.Info("");
Config.Log.Info($"Bot user id : {r.Client.CurrentUser.Id} ({r.Client.CurrentUser.Username})");
Config.Log.Info($"Bot user id : {c.CurrentUser.Id} ({c.CurrentUser.Username})");
Config.Log.Info($"Bot admin id : {Config.BotAdminId} ({admin.Username ?? "???"}#{admin.Discriminator ?? "????"})");
Config.Log.Info("");
};
client.GuildAvailable += async gaArgs =>
client.GuildAvailable += async (c, gaArgs) =>
{
await BotStatusMonitor.RefreshAsync(gaArgs.Client).ConfigureAwait(false);
await BotStatusMonitor.RefreshAsync(c).ConfigureAwait(false);
Watchdog.DisconnectTimestamps.Clear();
Watchdog.TimeSinceLastIncomingMessage.Restart();
if (gaArgs.Guild.Id != Config.BotGuildId)
@@ -201,8 +200,8 @@ namespace CompatBot
try
{
await Task.WhenAll(
Starbucks.CheckBacklogAsync(gaArgs.Client, gaArgs.Guild).ContinueWith(_ => Config.Log.Info($"Starbucks backlog checked in {gaArgs.Guild.Name}."), TaskScheduler.Default),
DiscordInviteFilter.CheckBacklogAsync(gaArgs.Client, gaArgs.Guild).ContinueWith(_ => Config.Log.Info($"Discord invites backlog checked in {gaArgs.Guild.Name}."), TaskScheduler.Default)
Starbucks.CheckBacklogAsync(c, gaArgs.Guild).ContinueWith(_ => Config.Log.Info($"Starbucks backlog checked in {gaArgs.Guild.Name}."), TaskScheduler.Default),
DiscordInviteFilter.CheckBacklogAsync(c, gaArgs.Guild).ContinueWith(_ => Config.Log.Info($"Discord invites backlog checked in {gaArgs.Guild.Name}."), TaskScheduler.Default)
).ConfigureAwait(false);
}
catch (Exception e)
@@ -211,8 +210,8 @@ namespace CompatBot
}
Config.Log.Info($"All moderation backlogs checked in {gaArgs.Guild.Name}.");
};
client.GuildAvailable += gaArgs => UsernameValidationMonitor.MonitorAsync(gaArgs.Client, true);
client.GuildUnavailable += guArgs =>
client.GuildAvailable += (c, _) => UsernameValidationMonitor.MonitorAsync(c, true);
client.GuildUnavailable += (_, guArgs) =>
{
Config.Log.Warn($"{guArgs.Guild.Name} is unavailable");
return Task.CompletedTask;
@@ -229,11 +228,12 @@ namespace CompatBot
client.MessageReactionAdded += Starbucks.Handler;
client.MessageReactionAdded += ContentFilterMonitor.OnReaction;
client.MessageCreated += _ => { Watchdog.TimeSinceLastIncomingMessage.Restart(); return Task.CompletedTask;};
client.MessageCreated += (_, __) => { Watchdog.TimeSinceLastIncomingMessage.Restart(); return Task.CompletedTask;};
client.MessageCreated += ContentFilterMonitor.OnMessageCreated; // should be first
client.MessageCreated += GlobalMessageCache.OnMessageCreated;
var mediaScreenshotMonitor = new MediaScreenshotMonitor(client);
if (!string.IsNullOrEmpty(Config.AzureComputerVisionKey))
client.MessageCreated += MediaScreenshotMonitor.OnMessageCreated;
client.MessageCreated += mediaScreenshotMonitor.OnMessageCreated;
client.MessageCreated += ProductCodeLookup.OnMessageCreated;
client.MessageCreated += LogParsingHandler.OnMessageCreated;
client.MessageCreated += LogAsTextMonitor.OnMessageCreated;
@@ -336,7 +336,8 @@ namespace CompatBot
UsernameValidationMonitor.MonitorAsync(client),
Psn.Check.MonitorFwUpdates(client, Config.Cts.Token),
Watchdog.SendMetrics(client),
Watchdog.CheckGCStats()
Watchdog.CheckGCStats(),
mediaScreenshotMonitor.ProcessWorkQueue()
);
while (!Config.Cts.IsCancellationRequested)