예제 #1
0
        private async Task PlaceVote(Cacheable <IUserMessage, ulong> userMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (!voters.ContainsKey(reaction.UserId))
            {
                voters.Add(reaction.UserId, new List <int>());
            }
            List <int> ballot = voters[reaction.UserId];

            if (ballot.Count >= serverData.UserVoteLimit)
            {
                //We need to send the user a fraggin message??? Nope. Maxed out votes, ignore this particular reaction?? Assuming it is even a vote... (which it may very well not be)
                return;
            }

            int vote = MojiCommand.EmojiToVoteNumber(reaction.Emote);

            if (vote >= movieOptions.Length || ballot.Contains(vote))
            {
                //User tried to vote for something outside the valid range, or they already voted for this
                return;
            }

            //If the execution makes it here, we can safely add the vote to the ballot
            voters[reaction.UserId].Add(vote);

            numVotes = CalculateBallotScore();

            //Update any embeds here!
            await voteMessage.ModifyAsync(VoteMessage => {
                VoteMessage.Content = "Movie Vote!!!";
                VoteMessage.Embed   = MakeVoteEmbed();
                return;
            });
        }
예제 #2
0
        //This will be called whenever
        public async Task ReactCallback(Cacheable <IUserMessage, ulong> userMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try {
                //Need to check if the emoji even belongs to this server, and if the message being reacted to is the correct one.
                if (this.channel.Id == channel.Id && reaction.MessageId == voteMessage.Id && reaction.UserId != Program.Instance.client.CurrentUser.Id)
                {
                    //Check how to deal with this reaction.
                    if (VerifyAsVote(reaction))
                    {
                        await PlaceVote(userMessage, channel, reaction);
                    }

                    //This is the reset command
                    if (MojiCommand.IsReset(reaction.Emote))
                    {
                        await ResetVote(userMessage, channel, reaction);
                    }

                    if (MojiCommand.IsStop(reaction.Emote))
                    {
                        await EndVote(userMessage, channel, reaction);
                    }
                }
            } catch (Exception ex) {
                await Program.Instance.Log(new LogMessage(LogSeverity.Error, "React Callback Voting", "An unknown error occurred.", ex));
            }
        }
예제 #3
0
        public async Task Action(Cacheable <IUserMessage, ulong> userMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (this.channel.Id == channel.Id && reaction.MessageId == suggestionsMessage.Id && reaction.UserId != Program.Instance.client.CurrentUser.Id)
            {
                int old = pageNumber;
                //
                if (MojiCommand.IsLeftEnd(reaction.Emote))
                {
                    //Show the first page
                    old = 0;
                }

                if (MojiCommand.IsLeft(reaction.Emote))
                {
                    //Show the previous page
                    old -= 1;
                }

                if (MojiCommand.IsRight(reaction.Emote))
                {
                    //Show the next page
                    old += 1;
                }

                if (MojiCommand.IsRightEnd(reaction.Emote))
                {
                    //Show the last page
                    old = totalPages - 1;
                }

                if (old != pageNumber && old >= 0 && old <= totalPages)
                {
                    pageNumber = old;
                    await suggestionsMessage.ModifyAsync(VoteMessage => {
                        VoteMessage.Content = "Moves Info!!";
                        VoteMessage.Embed   = MakeEmbed();
                        return;
                    });
                }
            }
        }