コード例 #1
0
ファイル: CodexHandler.cs プロジェクト: Lightningwing92/Mimir
        public async Task ReactionHandler(Cacheable <IUserMessage, ulong> messageParam, ISocketMessageChannel channel, SocketReaction reactionParam)
        {
            var reactions = new EmojiSet();                          // Get emoji set
            var message   = await messageParam.GetOrDownloadAsync(); // Get message

            if (message == null)
            {
                return;                  // Return if null
            }
            if (!reactionParam.User.IsSpecified)
            {
                return;                                                    // Return if the user is not specified
            }
            if (_messages.TryGetValue(message.Id, out CodexMessage codex)) // Try to get the value of the message and store it in a variable
            {
                if (reactionParam.UserId == _client.CurrentUser.Id)
                {
                    return;                                                                             // Return if the user is the bot
                }
                if (codex.User != null && reactionParam.UserId != codex.User.Id)                        // Return if the users is not the user that initialized the command
                {
                    var _ = message.RemoveReactionAsync(reactionParam.Emote, reactionParam.User.Value); // Remove reaction
                    return;
                }
                await message.RemoveReactionAsync(reactionParam.Emote, reactionParam.User.Value); // Remove reaction

                if (reactionParam.Emote.Name == reactions.EmoteTRASH.Name)
                {
                    if (codex.EmoteStopAction == StopAction.DeleteMessage) // If the emotestop action is to delete, delete message
                    {
                        await message.DeleteAsync();
                    }
                    else if (codex.EmoteStopAction == StopAction.ClearReactions) // If the emotestop action is to clear reactions, remove all reactions
                    {
                        await message.RemoveAllReactionsAsync();
                    }
                    _messages.Remove(message.Id);                               // Remove message from dictionary
                }
                else if (reactionParam.Emote.Name == reactions.EmoteBACK.Name)  // If the reaction is EmoteBACK, then modify the message to display the embed list
                {
                    codex.CurrentPage = codex.Count;                            // Set current page to the last embed (this is always the title embed)
                    await message.ModifyAsync(x => x.Embed = codex.GetEmbed()); // Modify message to title page
                }
                else
                {
                    codex.CurrentPage = reactions.GetNum(reactionParam.Emote);  // Set current page to the numerical equivelent of the chosen reaction
                    await message.ModifyAsync(x => x.Embed = codex.GetEmbed()); // Modify the message to match current page
                }
            }
        }
コード例 #2
0
ファイル: CodexHandler.cs プロジェクト: Lightningwing92/Mimir
        public async Task <IUserMessage> SendCodexMessage(IMessageChannel channel, CodexMessage codexMessage)
        {
            var message = await channel.SendMessageAsync("", false, codexMessage.GetEmbed()); // Sent message

            EmojiSet reactions = new EmojiSet();                                              // Get emoji set
            await message.AddReactionAsync(reactions.EmoteBACK);                              // Add back emote

            for (int i = 0; i < codexMessage.Count - 1; i++)                                  // For each message in Codex Message minus 1
            {
                await message.AddReactionAsync(reactions.GetEmote(i));                        // Add the number reaction
            }
            await message.AddReactionAsync(reactions.EmoteTRASH);                             // Add end emote

            _messages.Add(message.Id, codexMessage);                                          // Add the message to the messages dictionary

            return(message);                                                                  // Return the message
        }