Ejemplo n.º 1
0
        public async Task Handle(MessageUpdateEventArgs evt)
        {
            if (evt.Author?.Id == _client.CurrentUser?.Id)
            {
                return;
            }

            // Edit message events sometimes arrive with missing data; double-check it's all there
            if (evt.Message.Content == null || evt.Author == null || evt.Channel.Guild == null)
            {
                return;
            }

            // Only react to the last message in the channel
            if (_lastMessageCache.GetLastMessage(evt.Channel.Id) != evt.Message.Id)
            {
                return;
            }

            // Just run the normal message handling code, with a flag to disable autoproxying
            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.Channel.GuildId, evt.Channel.Id);
            await _proxy.HandleIncomingMessage(evt.Message, ctx, allowAutoproxy : false);
        }
Ejemplo n.º 2
0
        public async Task HandleMessageEdited(Cacheable<IMessage, ulong> oldMessage, SocketMessage newMessage, ISocketMessageChannel channel)
        {
            _sentryScope.AddBreadcrumb(newMessage.Content, "event.messageEdit", data: new Dictionary<string, string>()
            {
                {"channel", channel.Id.ToString()},
                {"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()},
                {"message", newMessage.Id.ToString()}
            });
            _sentryScope.SetTag("shard", _client.GetShardIdFor((channel as IGuildChannel)?.Guild).ToString());

            // If this isn't a guild, bail
            if (!(channel is IGuildChannel gc)) return;
            
            // If this isn't the last message in the channel, don't do anything
            if (_lastMessageCache.GetLastMessage(channel.Id) != newMessage.Id) return;
            
            // Fetch account from cache if there is any
            var account = await _cache.GetAccountDataCached(newMessage.Author.Id);
            if (account == null) return; // Again: no cache = no account = no system = no proxy
            
            // Also fetch guild cache
            var guild = await _cache.GetGuildDataCached(gc.GuildId);

            // Just run the normal message handling stuff
            await _proxy.HandleMessageAsync(guild, account, newMessage, doAutoProxy: false);
        }
Ejemplo n.º 3
0
        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)
            {
                return;
            }

            var channel = _cache.GetChannel(evt.ChannelId);

            if (channel.Type != Channel.ChannelType.GuildText)
            {
                return;
            }
            var guild = _cache.GetGuild(channel.GuildId !.Value);

            // Only react to the last message in the channel
            if (_lastMessageCache.GetLastMessage(evt.ChannelId) != 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())
                using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
                    ctx = await _repo.GetMessageContext(conn, evt.Author.Value !.Id, channel.GuildId !.Value, evt.ChannelId);

            // TODO: is this missing anything?
            var equivalentEvt = new MessageCreateEvent
            {
                Id          = evt.Id,
                ChannelId   = evt.ChannelId,
                GuildId     = channel.GuildId,
                Author      = evt.Author.Value,
                Member      = evt.Member.Value,
                Content     = evt.Content.Value,
                Attachments = evt.Attachments.Value ?? Array.Empty <Message.Attachment>()
            };
            var botPermissions = _bot.PermissionsIn(channel.Id);
            await _proxy.HandleIncomingMessage(shard, equivalentEvt, ctx, allowAutoproxy : false, guild : guild, channel : channel, botPermissions : botPermissions);
        }
Ejemplo n.º 4
0
        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)
            {
                return;
            }

            var channel = _cache.GetChannel(evt.ChannelId);

            if (!DiscordUtils.IsValidGuildChannel(channel))
            {
                return;
            }
            var guild       = _cache.GetGuild(channel.GuildId !.Value);
            var lastMessage = _lastMessageCache.GetLastMessage(evt.ChannelId);

            // 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())
                using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
                    ctx = await _repo.GetMessageContext(conn, evt.Author.Value !.Id, channel.GuildId !.Value, evt.ChannelId);

            var equivalentEvt = await GetMessageCreateEvent(evt, lastMessage, channel);

            var botPermissions = _bot.PermissionsIn(channel.Id);
            await _proxy.HandleIncomingMessage(shard, equivalentEvt, ctx, allowAutoproxy : false, guild : guild, channel : channel, botPermissions : botPermissions);
        }
Ejemplo n.º 5
0
 private bool IsDuplicateMessage(DiscordMessage evt) =>
 // We consider a message duplicate if it has the same ID as the previous message that hit the gateway
 _lastMessageCache.GetLastMessage(evt.ChannelId) == evt.Id;
Ejemplo n.º 6
0
 private bool IsDuplicateMessage(Message msg) =>
 // We consider a message duplicate if it has the same ID as the previous message that hit the gateway
 _lastMessageCache.GetLastMessage(msg.ChannelId) == msg.Id;