public static async Task <Notice> GetNotice(this Event self, Instant occurrence, Event.Rule rule)
        {
            foreach (Event.Notice notice in self.Notices)
            {
                if (notice.Start.IsApproximately(occurrence))
                {
                    return(new Notice(self, notice, rule));
                }
            }

            // no notice for this occurrence, create one.
            Event.Notice newNotice = new Event.Notice();
            newNotice.Start = occurrence;
            self.Notices.Add(newNotice);
            await EventsService.SaveEvent(self);

            return(new Notice(self, newNotice, rule));
        }
Exemple #2
0
        public async Task Update()
        {
            if (this.Event == null)
            {
                throw new Exception("Notice has no owner");
            }

            SocketTextChannel?channel = Program.DiscordClient.GetChannel(this.Event.Channel) as SocketTextChannel;

            if (channel is null)
            {
                return;
            }

            EmbedBuilder builder = await this.BuildEmbed();

            RestUserMessage?message = null;

            if (this.EventNotice.MessageId != null)
            {
                message = await channel.GetMessageAsync((ulong)this.EventNotice.MessageId) as RestUserMessage;
            }

            if (message is null)
            {
                message = await channel.SendMessageAsync(null, false, builder.Build());

                this.EventNotice.MessageId = message.Id;
                await EventsService.SaveEvent(this.Event);
            }
            else
            {
                await message.ModifyAsync(x =>
                {
                    x.Embed = builder.Build();
                });
            }
        }