Пример #1
0
        public async Task <bool> HandleMessageUpdatedAsync(IMessageChannel channel, IMessage updatedMessage, Lazy <Task <IMessage> > freshMessageFactory)
        {
            try
            {
                var newMessage = await freshMessageFactory.Value;
                var(success, _, commandArgs) = await VoteService.TryMatchVoteCommand(newMessage);

                if (success)
                {
                    // newMessage has Reactions.Count == 0, always
                    var freshMessage = await channel.GetMessageAsync(newMessage.Id);

                    if (freshMessage is IUserMessage freshUserMessage)
                    {
                        await VoteService.ProcessVoteCommandAsync(freshUserMessage, commandArgs);
                    }

                    return(true);
                }
                else
                {
                    await VoteService.DeleteAssociatedVoteReplyIfExistsAsync(channel, newMessage.Id);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Could not process updated message {0} in channel {1}", updatedMessage.Id, channel);
            }

            return(false);
        }
Пример #2
0
        public async Task <bool> HandleMessageDeletedAsync(IMessageChannel channel, ulong messageId)
        {
            try
            {
                var wasVoteCommand = await VoteService.DeleteAssociatedVoteReplyIfExistsAsync(channel, messageId);

                if (!wasVoteCommand)
                {
                    await VoteService.DeleteVoteReplyRecordIfExistsAsync(channel, messageId);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Could not process deleted message {0} in channel {1}", messageId, channel);
            }

            return(false);
        }
Пример #3
0
        public async Task <ScheduledTaskResult> HandleAsync(ScheduledTask scheduledTask)
        {
            if (scheduledTask.Discriminator != EndOfVotingScheduledTask.Identifier)
            {
                return(ScheduledTaskResult.NotHandled);
            }

            var data    = scheduledTask.ParseData <EndOfVotingScheduledTask>();
            var channel = Client.GetGuild(data.GuildId)?.GetTextChannel(data.ChannelId);

            if (channel is null)
            {
                throw new InvalidOperationException("Unable to locate guild or channel");
            }

            if (await channel.GetMessageAsync(data.MessageId) is not IUserMessage message)
            {
                return(ScheduledTaskResult.HandledAndCompleted); // vote doesnt exist anymore
            }
            if (await VoteService.ParseVoteCommand(message) is not VoteDefinition voteDefinition)
            {
                return(ScheduledTaskResult.HandledAndCompleted); // it is not a vote anymore
            }
            if (voteDefinition.Deadline is not DateTimeOffset deadline)
            {
                return(ScheduledTaskResult.HandledAndCompleted); // the vote no longer has a deadline
            }
            if (!voteDefinition.IsPastDeadline())
            {
                scheduledTask.When = deadline;
                return(ScheduledTaskResult.HandledAndPostponed); // the vote should not be ended yet
            }

            var summary = VoteService.ComposeSummary(message, voteDefinition);
            await VoteService.UpdateVoteReplyAsync(message, summary);

            return(ScheduledTaskResult.HandledAndCompleted);
        }
Пример #4
0
 public VoteMessageEventHandler(VoteService voteService, ILogger <VoteMessageEventHandler> logger)
 {
     VoteService = voteService;
     Logger      = logger;
 }
 public VoteReactionHandler(VoteService voteService)
 {
     VoteService = voteService;
 }
Пример #6
0
 public EndOfVotingScheduledTaskHandler(VoteService voteService, DiscordSocketClient client)
 {
     VoteService = voteService;
     Client      = client;
 }