예제 #1
0
        private async Task Timer_Elapsed()
        {
            if (Message is RestUserMessage message)
            {
                await message.UpdateAsync();

                var votes = new Dictionary <IEmote, int>();

                foreach (var reaction in message.Reactions)
                {
                    var reactionUsers = await message.GetReactionUsersAsync(reaction.Key, 500).FlattenAsync();

                    if (reactionUsers is null || !reactionUsers.Any(x => x.IsBot))
                    {
                        continue;
                    }

                    votes.Add(reaction.Key, reaction.Value.ReactionCount - 1);
                }

                await Message.Channel.SendMessageAsync(embed : EmbedUtils.CreatePollResultEmbed(this, votes));
            }

            _locked = false;
            OnWorkCompleted(EventArgs.Empty);
        }
예제 #2
0
        public async Task StartAsync(ITextChannel textChannel)
        {
            if (_locked)
            {
                return;
            }

            _ = textChannel ?? throw new NullReferenceException("StartAsync");

            Message = await textChannel.SendMessageAsync(embed : EmbedUtils.CreatePollEmbed(this));

            await Message.AddReactionsAsync(GetEmojis());

            SetupTimer();
            _timerStart = DateTime.UtcNow;
            _locked     = true;
            Timer.Start();
        }