public static Uri GetThumbUrl(this Poll poll, IUrlHelper urlHelper) { var thumbnail = default(Uri); if (poll.Portal is { } portal) { thumbnail = portal.GetImage(urlHelper, 64, false); } return(thumbnail ?? poll.Raid().GetThumbUrl(urlHelper)); }
private static StringBuilder GetTitleBase(this Poll poll, ParseMode mode) { var result = poll.Raid()?.GetDescription(mode) ?? new StringBuilder(); if (poll.Time != null) { if (result.Length > 0) { result.Insert(0, RaidEx.Delimeter); } result.Insert(0, new StringBuilder().Bold((builder, m) => builder.Sanitize($"Бой {poll.Time:t}", m), mode)); } return(result); }
public static StringBuilder GetDescription(this Poll poll, IUrlHelper urlHelper, ParseMode mode = Helpers.DefaultParseMode) { var description = poll.GetTitleBase(mode); if (!string.IsNullOrEmpty(poll.Title)) { if (description.Length > 0) { description.NewLine().Sanitize(poll.Title, mode); } else { description.Bold((builder, m) => builder.Sanitize(poll.Title, m), mode); if (poll.Portal is { } portal) { description.Sanitize(poll.ExRaidGym ? " ☆\u00A0" : " ◊\u00A0", mode); description.Link(portal.Name, $"https://pogo.tools/{portal.Guid}", mode); if (poll.ExRaidGym) { description.Sanitize(" (EX Raid Gym)", mode); } } } } switch (mode) { case ParseMode.Html: case ParseMode.Markdown: var raid = poll.Raid(); if (raid?.Lat != null && raid?.Lon != null) { description .Sanitize(/*string.IsNullOrEmpty(poll.Title) ? Environment.NewLine : */ RaidEx.Delimeter, mode) .Link("Map", raid.GetLink(urlHelper), mode); } break; } return(description); }
public static InputTextMessageContent GetMessageText(this Poll poll, IUrlHelper urlHelper, ParseMode mode = Helpers.DefaultParseMode, bool disableWebPreview = false) { var text = poll.GetDescription(urlHelper, mode).NewLine(); text.Append(" "); // for better presentation in telegram pins & notifications if (poll.Cancelled) { text .NewLine() .Bold((builder, m) => builder.Sanitize("Cancellation!", m).NewLine(), mode); } var compactMode = poll.Votes?.Count > 10; var pollVotes = poll.Votes ?? Enumerable.Empty <Vote>(); GroupVotes(text, pollVotes, ourVoteGrouping); text.Link("\x200B", poll.Raid()?.GetLink(urlHelper), mode); return(text.ToTextMessageContent(mode, disableWebPreview)); int GroupVotes(StringBuilder result, IEnumerable <Vote> enumerable, IEnumerable <VoteGrouping> grouping, string extraPhrase = null) { int groupsCount = 0; foreach (var voteGroup in enumerable .GroupBy(vote => grouping.OrderBy(_ => _.Order).FirstOrDefault(_ => vote.Team?.HasAnyFlags(_.Flag) ?? false)) .OrderBy(voteGroup => voteGroup.Key.DisplayOrder)) { groupsCount++; var votesNumber = voteGroup.Aggregate(0, (i, vote) => i + vote.Team.GetPlusVotesCount() + 1); var countStr = votesNumber == 1 ? voteGroup.Key.Singular : voteGroup.Key.Plural; StringBuilder FormatCaption(StringBuilder sb) { var captionParts = new[] { votesNumber.ToString(), extraPhrase, countStr }.Where(s => !string.IsNullOrWhiteSpace(s)); return(sb .NewLine() .Sanitize(string.Join(" ", captionParts), mode) .NewLine()); } if (voteGroup.Key.NestedGrouping is {} nestedGrouping) { var nestedResult = new StringBuilder(); if (GroupVotes(nestedResult, voteGroup, nestedGrouping) > 1) { FormatCaption(result).Append(nestedResult); } else { GroupVotes(result, voteGroup, nestedGrouping, countStr); } continue; } FormatCaption(result); foreach (var vote in voteGroup.GroupBy(_ => _.Team?.RemoveFlags(VoteEnum.Modifiers)).OrderBy(_ => _.Key)) { var votes = vote.OrderBy(v => v.Modified); if (compactMode) { result .Sanitize(vote.Key?.Description()).Append('\x00A0') .AppendJoin(", ", votes.Select(v => v.GetUserLinkWithPluses(mode))) .NewLine(); } else { result .AppendJoin(Helpers.NewLineString, votes.Select(v => $"{v.Team?.Description().Sanitize(mode)} {v.GetUserLinkWithPluses(mode)}")) .NewLine(); } } } return(groupsCount); } }