public async Task <bool?> Handle(MessageEntityEx entity, PollMessage context = default, CancellationToken cancellationToken = default)
        {
            if (!this.ShouldProcess(entity, context))
            {
                return(null);
            }

            var from  = myClock.GetCurrentInstant().ToDateTimeOffset() - myJitterOffset;
            var polls = await myDB.Set <Poll>()
                        .Where(poll => poll.Time >= from)
                        .Where(poll => poll.Votes.Any(vote => vote.UserId == entity.Message.From.Id))
                        .IncludeRelatedData()
                        .ToListAsync(cancellationToken);

            var builder = new TextBuilder();

            if (polls.Count == 0)
            {
                builder.Append($"No upcoming raids.");
            }
            else
            {
                foreach (var poll in polls.OrderBy(poll => poll.Time))
                {
                    builder.Bold(b =>
                                 b.Code(bb => bb.AppendFormat("{0:t} ", poll.Time)));
                    poll.GetTitle(builder).NewLine();
                }
            }

            var content = builder.ToTextMessageContent(disableWebPreview: true);
            await myBot.SendTextMessageAsync(entity.Message.Chat, content, true, cancellationToken : cancellationToken);

            return(false);
        }
Exemple #2
0
        public static TextBuilder GetDescription(this Raid raid, TextBuilder description)
        {
            var initialLength = description.Length;

            description.Bold(builder =>
            {
                if (raid.RaidBossLevel is { } raidBossLevel)
                {
                    builder.Sanitize($@"[R{raidBossLevel}] ");
                }

                builder.Sanitize(raid.Name);
            });

            if ((raid.Gym ?? raid.PossibleGym) != null)
            {
                description
                .Sanitize(Delimeter)
                .Bold(builder => builder.Sanitize(raid.Gym ?? raid.PossibleGym));
            }
            else if (raid.NearByAddress != null)
            {
                description
                .Sanitize(Delimeter)
                .Bold(builder => builder.Sanitize(raid.NearByAddress));
            }

            if (description.Length == initialLength)
            {
                description
                .Bold(builder => builder.Sanitize(raid.Title));
            }

            return(description);
        }
 public static TextBuilder Bold(this TextBuilder builder, [InstantHandle] Action <StringBuilder> action)
 {
     using (builder.Bold())
     {
         action(builder);
         return(builder);
     }
 }
 public static TextBuilder Bold(this TextBuilder builder, string?text) =>
 builder.Bold(b => b.Append(text));