mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
feat: add abuse handling
This commit is contained in:
parent
4bf60a47d7
commit
2dfb851246
17 changed files with 405 additions and 16 deletions
|
|
@ -114,6 +114,11 @@ public class MessageCreated: IEventHandler<MessageCreateEvent>
|
|||
if (!HasCommandPrefix(content, _config.ClientId, out var cmdStart) || cmdStart == content.Length)
|
||||
return false;
|
||||
|
||||
// if the command message was sent by a user account with bot usage disallowed, ignore it
|
||||
var abuse_log = await _repo.GetAbuseLogByAccount(evt.Author.Id);
|
||||
if (abuse_log != null && abuse_log.DenyBotUsage)
|
||||
return false;
|
||||
|
||||
// Trim leading whitespace from command without actually modifying the string
|
||||
// This just moves the argPos pointer by however much whitespace is at the start of the post-argPos string
|
||||
var trimStartLengthDiff =
|
||||
|
|
@ -162,6 +167,9 @@ public class MessageCreated: IEventHandler<MessageCreateEvent>
|
|||
using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
|
||||
ctx = await _repo.GetMessageContext(evt.Author.Id, evt.GuildId ?? default, rootChannel, channel.Id != rootChannel ? channel.Id : default);
|
||||
|
||||
if (ctx.DenyBotUsage)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
return await _proxy.HandleIncomingMessage(evt, ctx, guild, channel, true, botPermissions);
|
||||
|
|
|
|||
|
|
@ -69,6 +69,8 @@ public class MessageEdited: IEventHandler<MessageUpdateEvent>
|
|||
MessageContext ctx;
|
||||
using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
|
||||
ctx = await _repo.GetMessageContext(evt.Author.Value!.Id, channel.GuildId!.Value, rootChannel.Id, evt.ChannelId);
|
||||
if (ctx.DenyBotUsage)
|
||||
return;
|
||||
|
||||
var equivalentEvt = await GetMessageCreateEvent(evt, lastMessage, channel);
|
||||
var botPermissions = await _cache.BotPermissionsIn(guildIdMaybe, channel.Id);
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ public class ReactionAdded: IEventHandler<MessageReactionAddEvent>
|
|||
|
||||
// Proxied messages only exist in guild text channels, so skip checking if we're elsewhere
|
||||
if (!DiscordUtils.IsValidGuildChannel(channel)) return;
|
||||
var abuse_log = await _repo.GetAbuseLogByAccount(evt.Member!.User!.Id);
|
||||
|
||||
switch (evt.Emoji.Name.Split("\U0000fe0f", 2)[0])
|
||||
{
|
||||
|
|
@ -113,6 +114,7 @@ public class ReactionAdded: IEventHandler<MessageReactionAddEvent>
|
|||
case "\u23F0": // Alarm clock
|
||||
case "\u2757": // Exclamation mark
|
||||
{
|
||||
if (abuse_log != null && abuse_log.DenyBotUsage) break;
|
||||
var msg = await _repo.GetFullMessage(evt.MessageId);
|
||||
if (msg != null)
|
||||
await HandlePingReaction(evt, msg);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue