refactor(bot): remove saving own user ID from ready event, rely on ID in config
This commit is contained in:
@@ -59,7 +59,7 @@ public class MessageCreated: IEventHandler<MessageCreateEvent>
|
||||
|
||||
public async Task Handle(int shardId, MessageCreateEvent evt)
|
||||
{
|
||||
if (evt.Author.Id == await _cache.GetOwnUser()) return;
|
||||
if (evt.Author.Id == _config.ClientId) return;
|
||||
if (evt.Type != Message.MessageType.Default && evt.Type != Message.MessageType.Reply) return;
|
||||
if (IsDuplicateMessage(evt)) return;
|
||||
|
||||
@@ -109,10 +109,8 @@ public class MessageCreated: IEventHandler<MessageCreateEvent>
|
||||
var content = evt.Content;
|
||||
if (content == null) return false;
|
||||
|
||||
var ourUserId = await _cache.GetOwnUser();
|
||||
|
||||
// Check for command prefix
|
||||
if (!HasCommandPrefix(content, ourUserId, out var cmdStart) || cmdStart == content.Length)
|
||||
if (!HasCommandPrefix(content, _config.ClientId, out var cmdStart) || cmdStart == content.Length)
|
||||
return false;
|
||||
|
||||
// Trim leading whitespace from command without actually modifying the string
|
||||
|
@@ -15,6 +15,7 @@ namespace PluralKit.Bot;
|
||||
public class MessageEdited: IEventHandler<MessageUpdateEvent>
|
||||
{
|
||||
private readonly Bot _bot;
|
||||
private readonly BotConfig _config;
|
||||
private readonly IDiscordCache _cache;
|
||||
private readonly Cluster _client;
|
||||
private readonly IDatabase _db;
|
||||
@@ -27,7 +28,7 @@ public class MessageEdited: IEventHandler<MessageUpdateEvent>
|
||||
|
||||
public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db,
|
||||
IMetrics metrics, ModelRepository repo, Cluster client, IDiscordCache cache, Bot bot,
|
||||
DiscordApiClient rest, ILogger logger)
|
||||
BotConfig config, DiscordApiClient rest, ILogger logger)
|
||||
{
|
||||
_lastMessageCache = lastMessageCache;
|
||||
_proxy = proxy;
|
||||
@@ -37,13 +38,14 @@ public class MessageEdited: IEventHandler<MessageUpdateEvent>
|
||||
_client = client;
|
||||
_cache = cache;
|
||||
_bot = bot;
|
||||
_config = config;
|
||||
_rest = rest;
|
||||
_logger = logger.ForContext<MessageEdited>();
|
||||
}
|
||||
|
||||
public async Task Handle(int shardId, MessageUpdateEvent evt)
|
||||
{
|
||||
if (evt.Author.Value?.Id == await _cache.GetOwnUser()) return;
|
||||
if (evt.Author.Value?.Id == _config.ClientId) 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)
|
||||
|
@@ -18,6 +18,7 @@ namespace PluralKit.Bot;
|
||||
public class ReactionAdded: IEventHandler<MessageReactionAddEvent>
|
||||
{
|
||||
private readonly Bot _bot;
|
||||
private readonly BotConfig _config;
|
||||
private readonly IDiscordCache _cache;
|
||||
private readonly Cluster _cluster;
|
||||
private readonly CommandMessageService _commandMessageService;
|
||||
@@ -30,13 +31,14 @@ public class ReactionAdded: IEventHandler<MessageReactionAddEvent>
|
||||
|
||||
public ReactionAdded(ILogger logger, IDatabase db, ModelRepository repo,
|
||||
CommandMessageService commandMessageService, IDiscordCache cache, Bot bot, Cluster cluster,
|
||||
DiscordApiClient rest, EmbedService embeds, PrivateChannelService dmCache)
|
||||
BotConfig config, DiscordApiClient rest, EmbedService embeds, PrivateChannelService dmCache)
|
||||
{
|
||||
_db = db;
|
||||
_repo = repo;
|
||||
_commandMessageService = commandMessageService;
|
||||
_cache = cache;
|
||||
_bot = bot;
|
||||
_config = config;
|
||||
_cluster = cluster;
|
||||
_rest = rest;
|
||||
_embeds = embeds;
|
||||
@@ -52,7 +54,7 @@ public class ReactionAdded: IEventHandler<MessageReactionAddEvent>
|
||||
private async ValueTask TryHandleProxyMessageReactions(MessageReactionAddEvent evt)
|
||||
{
|
||||
// ignore any reactions added by *us*
|
||||
if (evt.UserId == await _cache.GetOwnUser())
|
||||
if (evt.UserId == _config.ClientId)
|
||||
return;
|
||||
|
||||
// Ignore reactions from bots (we can't DM them anyway)
|
||||
|
Reference in New Issue
Block a user