run dotnet format
This commit is contained in:
@@ -4,7 +4,7 @@ using Myriad.Gateway;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
{
|
||||
public interface IEventHandler<in T> where T: IGatewayEvent
|
||||
public interface IEventHandler<in T> where T : IGatewayEvent
|
||||
{
|
||||
Task Handle(Shard shard, T evt);
|
||||
|
||||
|
@@ -11,7 +11,7 @@ namespace PluralKit.Bot
|
||||
{
|
||||
private readonly InteractionDispatchService _interactionDispatch;
|
||||
private readonly ILifetimeScope _services;
|
||||
|
||||
|
||||
public InteractionCreated(InteractionDispatchService interactionDispatch, ILifetimeScope services)
|
||||
{
|
||||
_interactionDispatch = interactionDispatch;
|
||||
|
@@ -64,25 +64,25 @@ namespace PluralKit.Bot
|
||||
var guild = evt.GuildId != null ? _cache.GetGuild(evt.GuildId.Value) : null;
|
||||
var channel = _cache.GetChannel(evt.ChannelId);
|
||||
var rootChannel = _cache.GetRootChannel(evt.ChannelId);
|
||||
|
||||
|
||||
// Log metrics and message info
|
||||
_metrics.Measure.Meter.Mark(BotMetrics.MessagesReceived);
|
||||
_lastMessageCache.AddMessage(evt);
|
||||
|
||||
|
||||
// Get message context from DB (tracking w/ metrics)
|
||||
MessageContext ctx;
|
||||
await using (var conn = await _db.Obtain())
|
||||
using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
|
||||
ctx = await _repo.GetMessageContext(conn, evt.Author.Id, evt.GuildId ?? default, rootChannel.Id);
|
||||
|
||||
|
||||
// Try each handler until we find one that succeeds
|
||||
if (await TryHandleLogClean(evt, ctx))
|
||||
if (await TryHandleLogClean(evt, ctx))
|
||||
return;
|
||||
|
||||
|
||||
// Only do command/proxy handling if it's a user account
|
||||
if (evt.Author.Bot || evt.WebhookId != null || evt.Author.System == true)
|
||||
if (evt.Author.Bot || evt.WebhookId != null || evt.Author.System == true)
|
||||
return;
|
||||
|
||||
|
||||
if (await TryHandleCommand(shard, evt, guild, channel, ctx))
|
||||
return;
|
||||
await TryHandleProxy(shard, evt, guild, channel, ctx);
|
||||
@@ -133,11 +133,11 @@ namespace PluralKit.Bot
|
||||
foreach (var prefix in prefixes)
|
||||
{
|
||||
if (!message.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)) continue;
|
||||
|
||||
|
||||
argPos = prefix.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Then, check mention prefix (must be the bot user, ofc)
|
||||
argPos = -1;
|
||||
if (DiscordUtils.HasMentionPrefix(message, ref argPos, out var id))
|
||||
@@ -156,7 +156,7 @@ namespace PluralKit.Bot
|
||||
}
|
||||
|
||||
// Catch any failed proxy checks so they get ignored in the global error handler
|
||||
catch (ProxyService.ProxyChecksFailedException) {}
|
||||
catch (ProxyService.ProxyChecksFailedException) { }
|
||||
|
||||
catch (PKError e)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ namespace PluralKit.Bot
|
||||
if (botPermissions.HasFlag(PermissionSet.SendMessages))
|
||||
{
|
||||
await _rest.CreateMessage(evt.ChannelId,
|
||||
new MessageRequest {Content = $"{Emojis.Error} {e.Message}"});
|
||||
new MessageRequest { Content = $"{Emojis.Error} {e.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ namespace PluralKit.Bot
|
||||
public class MessageDeleted: IEventHandler<MessageDeleteEvent>, IEventHandler<MessageDeleteBulkEvent>
|
||||
{
|
||||
private static readonly TimeSpan MessageDeleteDelay = TimeSpan.FromSeconds(15);
|
||||
|
||||
|
||||
private readonly IDatabase _db;
|
||||
private readonly ModelRepository _repo;
|
||||
private readonly ILogger _logger;
|
||||
@@ -27,7 +27,7 @@ namespace PluralKit.Bot
|
||||
_lastMessage = lastMessage;
|
||||
_logger = logger.ForContext<MessageDeleted>();
|
||||
}
|
||||
|
||||
|
||||
public Task Handle(Shard shard, MessageDeleteEvent evt)
|
||||
{
|
||||
// Delete deleted webhook messages from the data store
|
||||
@@ -54,11 +54,11 @@ namespace PluralKit.Bot
|
||||
{
|
||||
await Task.Delay(MessageDeleteDelay);
|
||||
|
||||
_logger.Information("Bulk deleting {Count} messages in channel {Channel}",
|
||||
_logger.Information("Bulk deleting {Count} messages in channel {Channel}",
|
||||
evt.Ids.Length, evt.ChannelId);
|
||||
await _db.Execute(c => _repo.DeleteMessagesBulk(c, evt.Ids));
|
||||
}
|
||||
|
||||
|
||||
_lastMessage.HandleMessageDeletion(evt.ChannelId, evt.Ids.ToList());
|
||||
_ = Inner();
|
||||
return Task.CompletedTask;
|
||||
|
@@ -28,7 +28,7 @@ namespace PluralKit.Bot
|
||||
private readonly Bot _bot;
|
||||
private readonly DiscordApiClient _rest;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
|
||||
public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db, IMetrics metrics, ModelRepository repo, Cluster client, IDiscordCache cache, Bot bot, DiscordApiClient rest, ILogger logger)
|
||||
{
|
||||
_lastMessageCache = lastMessageCache;
|
||||
@@ -46,11 +46,11 @@ namespace PluralKit.Bot
|
||||
public async Task Handle(Shard shard, MessageUpdateEvent evt)
|
||||
{
|
||||
if (evt.Author.Value?.Id == _client.User?.Id) return;
|
||||
|
||||
|
||||
// Edit message events sometimes arrive with missing data; double-check it's all there
|
||||
if (!evt.Content.HasValue || !evt.Author.HasValue || !evt.Member.HasValue)
|
||||
if (!evt.Content.HasValue || !evt.Author.HasValue || !evt.Member.HasValue)
|
||||
return;
|
||||
|
||||
|
||||
var channel = _cache.GetChannel(evt.ChannelId);
|
||||
if (!DiscordUtils.IsValidGuildChannel(channel))
|
||||
return;
|
||||
@@ -60,7 +60,7 @@ namespace PluralKit.Bot
|
||||
// Only react to the last message in the channel
|
||||
if (lastMessage?.Id != evt.Id)
|
||||
return;
|
||||
|
||||
|
||||
// Just run the normal message handling code, with a flag to disable autoproxying
|
||||
MessageContext ctx;
|
||||
await using (var conn = await _db.Obtain())
|
||||
@@ -76,7 +76,7 @@ namespace PluralKit.Bot
|
||||
channel: channel, botPermissions: botPermissions);
|
||||
}
|
||||
// Catch any failed proxy checks so they get ignored in the global error handler
|
||||
catch (ProxyService.ProxyChecksFailedException) {}
|
||||
catch (ProxyService.ProxyChecksFailedException) { }
|
||||
}
|
||||
|
||||
private async Task<MessageCreateEvent> GetMessageCreateEvent(MessageUpdateEvent evt, CachedMessage lastMessage, Channel channel)
|
||||
@@ -86,11 +86,11 @@ namespace PluralKit.Bot
|
||||
var messageReference = lastMessage.ReferencedMessage != null
|
||||
? new Message.Reference(channel.GuildId, evt.ChannelId, lastMessage.ReferencedMessage.Value)
|
||||
: null;
|
||||
|
||||
var messageType = lastMessage.ReferencedMessage != null
|
||||
? Message.MessageType.Reply
|
||||
|
||||
var messageType = lastMessage.ReferencedMessage != null
|
||||
? Message.MessageType.Reply
|
||||
: Message.MessageType.Default;
|
||||
|
||||
|
||||
// TODO: is this missing anything?
|
||||
var equivalentEvt = new MessageCreateEvent
|
||||
{
|
||||
@@ -112,7 +112,7 @@ namespace PluralKit.Bot
|
||||
{
|
||||
if (referencedMessageId == null)
|
||||
return null;
|
||||
|
||||
|
||||
var botPermissions = _bot.PermissionsIn(channelId);
|
||||
if (!botPermissions.HasFlag(PermissionSet.ReadMessageHistory))
|
||||
{
|
||||
|
@@ -40,7 +40,7 @@ namespace PluralKit.Bot
|
||||
}
|
||||
|
||||
public async Task Handle(Shard shard, MessageReactionAddEvent evt)
|
||||
{
|
||||
{
|
||||
await TryHandleProxyMessageReactions(evt);
|
||||
}
|
||||
|
||||
@@ -71,42 +71,42 @@ namespace PluralKit.Bot
|
||||
|
||||
// Ignore reactions from bots (we can't DM them anyway)
|
||||
if (user.Bot) return;
|
||||
|
||||
|
||||
switch (evt.Emoji.Name)
|
||||
{
|
||||
// Message deletion
|
||||
case "\u274C": // Red X
|
||||
{
|
||||
await using var conn = await _db.Obtain();
|
||||
var msg = await _repo.GetMessage(conn, evt.MessageId);
|
||||
if (msg != null)
|
||||
await HandleProxyDeleteReaction(evt, msg);
|
||||
|
||||
break;
|
||||
}
|
||||
{
|
||||
await using var conn = await _db.Obtain();
|
||||
var msg = await _repo.GetMessage(conn, evt.MessageId);
|
||||
if (msg != null)
|
||||
await HandleProxyDeleteReaction(evt, msg);
|
||||
|
||||
break;
|
||||
}
|
||||
case "\u2753": // Red question mark
|
||||
case "\u2754": // White question mark
|
||||
{
|
||||
await using var conn = await _db.Obtain();
|
||||
var msg = await _repo.GetMessage(conn, evt.MessageId);
|
||||
if (msg != null)
|
||||
await HandleQueryReaction(evt, msg);
|
||||
|
||||
break;
|
||||
}
|
||||
{
|
||||
await using var conn = await _db.Obtain();
|
||||
var msg = await _repo.GetMessage(conn, evt.MessageId);
|
||||
if (msg != null)
|
||||
await HandleQueryReaction(evt, msg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "\U0001F514": // Bell
|
||||
case "\U0001F6CE": // Bellhop bell
|
||||
case "\U0001F3D3": // Ping pong paddle (lol)
|
||||
case "\u23F0": // Alarm clock
|
||||
case "\u2757": // Exclamation mark
|
||||
{
|
||||
await using var conn = await _db.Obtain();
|
||||
var msg = await _repo.GetMessage(conn, evt.MessageId);
|
||||
if (msg != null)
|
||||
await HandlePingReaction(evt, msg);
|
||||
break;
|
||||
}
|
||||
{
|
||||
await using var conn = await _db.Obtain();
|
||||
var msg = await _repo.GetMessage(conn, evt.MessageId);
|
||||
if (msg != null)
|
||||
await HandlePingReaction(evt, msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace PluralKit.Bot
|
||||
{
|
||||
if (!_bot.PermissionsIn(evt.ChannelId).HasFlag(PermissionSet.ManageMessages))
|
||||
return;
|
||||
|
||||
|
||||
using var conn = await _db.Obtain();
|
||||
var system = await _repo.GetSystemByAccount(conn, evt.UserId);
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace PluralKit.Bot
|
||||
private async ValueTask HandleCommandDeleteReaction(MessageReactionAddEvent evt, CommandMessage msg)
|
||||
{
|
||||
// Can only delete your own message
|
||||
if (msg.AuthorId != evt.UserId)
|
||||
if (msg.AuthorId != evt.UserId)
|
||||
return;
|
||||
|
||||
try
|
||||
@@ -154,7 +154,7 @@ namespace PluralKit.Bot
|
||||
private async ValueTask HandleQueryReaction(MessageReactionAddEvent evt, FullMessage msg)
|
||||
{
|
||||
var guild = _cache.GetGuild(evt.GuildId!.Value);
|
||||
|
||||
|
||||
// Try to DM the user info about the message
|
||||
try
|
||||
{
|
||||
@@ -163,14 +163,14 @@ namespace PluralKit.Bot
|
||||
{
|
||||
Embed = await _embeds.CreateMemberEmbed(msg.System, msg.Member, guild, LookupContext.ByNonOwner)
|
||||
});
|
||||
|
||||
|
||||
await _rest.CreateMessage(dm.Id, new MessageRequest
|
||||
{
|
||||
Embed = await _embeds.CreateMessageInfoEmbed(msg)
|
||||
});
|
||||
}
|
||||
catch (ForbiddenException) { } // No permissions to DM, can't check for this :(
|
||||
|
||||
|
||||
await TryRemoveOriginalReaction(evt);
|
||||
}
|
||||
|
||||
@@ -178,20 +178,20 @@ namespace PluralKit.Bot
|
||||
{
|
||||
if (!_bot.PermissionsIn(evt.ChannelId).HasFlag(PermissionSet.ManageMessages))
|
||||
return;
|
||||
|
||||
|
||||
// Check if the "pinger" has permission to send messages in this channel
|
||||
// (if not, PK shouldn't send messages on their behalf)
|
||||
var member = await _rest.GetGuildMember(evt.GuildId!.Value, evt.UserId);
|
||||
var requiredPerms = PermissionSet.ViewChannel | PermissionSet.SendMessages;
|
||||
if (member == null || !_cache.PermissionsFor(evt.ChannelId, member).HasFlag(requiredPerms)) return;
|
||||
|
||||
|
||||
if (msg.System.PingsEnabled)
|
||||
{
|
||||
// If the system has pings enabled, go ahead
|
||||
await _rest.CreateMessage(evt.ChannelId, new()
|
||||
{
|
||||
Content = $"Psst, **{msg.Member.DisplayName()}** (<@{msg.Message.Sender}>), you have been pinged by <@{evt.UserId}>.",
|
||||
Components = new []
|
||||
Components = new[]
|
||||
{
|
||||
new MessageComponent
|
||||
{
|
||||
@@ -208,7 +208,7 @@ namespace PluralKit.Bot
|
||||
}
|
||||
}
|
||||
},
|
||||
AllowedMentions = new AllowedMentions {Users = new[] {msg.Message.Sender}}
|
||||
AllowedMentions = new AllowedMentions { Users = new[] { msg.Message.Sender } }
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -221,7 +221,7 @@ namespace PluralKit.Bot
|
||||
{
|
||||
Content = $"{Emojis.Error} {msg.Member.DisplayName()}'s system has disabled reaction pings. If you want to mention them anyway, you can copy/paste the following message:"
|
||||
});
|
||||
await _rest.CreateMessage(dm.Id, new MessageRequest {Content = $"<@{msg.Message.Sender}>".AsCode()});
|
||||
await _rest.CreateMessage(dm.Id, new MessageRequest { Content = $"<@{msg.Message.Sender}>".AsCode() });
|
||||
}
|
||||
catch (ForbiddenException) { }
|
||||
}
|
||||
|
Reference in New Issue
Block a user