Example #1
0
        private async Task HandleMessageQueryByReaction(Cacheable <IUserMessage, ulong> message,
                                                        ISocketMessageChannel channel, ulong userWhoReacted,
                                                        IEmote reactedEmote)
        {
            // Find the user who sent the reaction, so we can DM them
            var user = await _client.Rest.GetUserAsync(userWhoReacted);

            if (user == null)
            {
                return;
            }

            // Find the message in the DB
            var msg = await _data.GetMessage(message.Id);

            if (msg == null)
            {
                return;
            }

            // DM them the message card
            try
            {
                await user.SendMessageAsync(embed : await _embeds.CreateMemberEmbed(msg.System, msg.Member, (channel as IGuildChannel)?.Guild, LookupContext.ByNonOwner));

                await user.SendMessageAsync(embed : await _embeds.CreateMessageInfoEmbed(msg));
            }
            catch (HttpException e) when(e.DiscordCode == 50007)
            {
                // Ignore exception if it means we don't have DM permission to this user
                // not much else we can do here :/
            }

            // And finally remove the original reaction (if we can)
            var msgObj = await message.GetOrDownloadAsync();

            if (await msgObj.Channel.HasPermission(ChannelPermission.ManageMessages))
            {
                await msgObj.RemoveReactionAsync(reactedEmote, user);
            }
        }
Example #2
0
        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
            {
                var dm = await _cache.GetOrCreateDmChannel(_rest, evt.UserId);

                await _rest.CreateMessage(dm.Id, new MessageRequest
                {
                    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);
        }