Beispiel #1
0
        private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> messageCache, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try
            {
                if (reaction.Emote.Name != "💬")
                {
                    return;
                }

                if (channel is SocketGuildChannel guildChannel)
                {
                    IUserMessage message = await messageCache.DownloadAsync();

                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    if (string.IsNullOrEmpty(message.Content))
                    {
                        return;
                    }

                    Quote quote = await this.quoteDb.LoadOrCreate(message.Author.Id + "_" + message.Id);

                    quote.Content  = message.Content;
                    quote.UserId   = message.Author.Id;
                    quote.GuildId  = guildChannel.Guild.Id;
                    quote.UserName = message.Author.Username;
                    quote.QuoteId  = await this.GetNextQuoteId(message.GetGuild(), message.GetAuthor());

                    quote.SetDateTime(message.CreatedAt);
                    await this.quoteDb.Save(quote);

                    Log.Write("Got quote: " + message.Content, "Bot");
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Beispiel #2
0
        private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> incomingMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try
            {
                // Don't react to your own reacts!
                if (reaction.UserId == Program.DiscordClient.CurrentUser.Id)
                {
                    return;
                }

                // Only handle reacts to help embed
                if (!activeHelpEmbeds.ContainsKey(incomingMessage.Id))
                {
                    return;
                }

                ActiveHelp helpWindow = activeHelpEmbeds[incomingMessage.Id];
                helpWindow.LastInteractedWith = DateTime.Now;

                // Only handle reacts from the original user, remove the reaction
                if (helpWindow.UserId != reaction.UserId)
                {
                    IUserMessage message = await incomingMessage.DownloadAsync();

                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    return;
                }

                // Only handle relevant reacts
                if (!HelpEmotes.Contains(reaction.Emote))
                {
                    IUserMessage message = await incomingMessage.DownloadAsync();

                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    return;
                }

                if (channel is SocketGuildChannel guildChannel)
                {
                    IUserMessage message = await incomingMessage.DownloadAsync();

                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    // Adjust current page
                    if (reaction.Emote.Equals(First))
                    {
                        helpWindow.CurrentPage = 0;
                    }
                    else if (reaction.Emote.Equals(Previous))
                    {
                        helpWindow.CurrentPage -= 1;
                    }
                    else if (reaction.Emote.Equals(Next))
                    {
                        helpWindow.CurrentPage += 1;
                    }
                    else if (reaction.Emote.Equals(Last))
                    {
                        helpWindow.CurrentPage = -1;
                    }

                    Permissions permissions = CommandsService.GetPermissions(message.GetAuthor());

                    int   currentPage = helpWindow.CurrentPage;
                    Embed embed       = GetHelp(message.GetGuild(), permissions, helpWindow.CurrentPage, out currentPage);

                    // Update current page
                    helpWindow.CurrentPage = currentPage;

                    await message.ModifyAsync(x => x.Embed = embed);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }