ReplyMarkup GenerateOptionsMarkup(Strings strings) { InlineKeyboardMarkup inline = new InlineKeyboardMarkup { InlineKeyboard = new List <List <InlineKeyboardButton> >() }; if (this.pollType != EPolls.board) { inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.StringsList.optionsPercentageNone), (PercentageBar == PercentageBars.Bars.none).ToCheck()), callbackData: "comm:percentage:none:" + chatId + ":" + pollId), InlineKeyboardButton.Create(PercentageBars.GetIconArray(PercentageBars.Bars.dots).Implode() + " " + (PercentageBar == PercentageBars.Bars.dots).ToCheck(), callbackData: "comm:percentage:dots:" + chatId + ":" + pollId), InlineKeyboardButton.Create(PercentageBars.GetIconArray(PercentageBars.Bars.thumbs).Implode() + " " + (PercentageBar == PercentageBars.Bars.thumbs).ToCheck(), callbackData: "comm:percentage:thumbs:" + chatId + ":" + pollId), }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.StringsList.optionsSorted), Sorted.ToCheck()), callbackData: "comm:sorted:" + chatId + ":" + pollId), }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.StringsList.optionsAppendable), Appendable.ToCheck()), callbackData: "comm:appendable:" + chatId + ":" + pollId), }); } inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(RenderModerationEmoji() + " " + strings.GetString(Strings.StringsList.moderate), callbackData: "comm:moderate:" + chatId + ":" + pollId), }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(string.Format(strings.GetString(Strings.StringsList.clone), EmojiStore.Clone), callbackData: "comm:clone:" + this.ChatId + ":" + this.PollId) }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create("\ud83d\udcbe " + strings.GetString(Strings.StringsList.done), callbackData: "comm:update:" + chatId + ":" + pollId) }); return(inline); }
protected override ContentParts GetContent(Strings strings, string apikey, bool channel = false, int?offset = null, bool moderatePane = true) { Strings.langs oldLang = strings.CurrentLang; strings.SetLanguage(lang); string text; InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup(); inlineKeyboard.InlineKeyboard = new List <List <InlineKeyboardButton> >(); string description = ""; { int userCount = 0; int optionCount = 0; int percentageUserCount = 0; text = "\ud83d\udcca <b>" + HtmlSpecialChars.Encode(pollText).UnmarkupUsernames() + "</b>" + (!string.IsNullOrEmpty(pollDescription) ? ("\n" + HtmlSpecialChars.Encode(pollDescription) + "\n") : "\n"); Dictionary <string, List <User> > newVotes; if (this.Sorted) { newVotes = pollVotes.CloneDictionary(); newVotes = newVotes.Sort(); } else { newVotes = pollVotes; } if (this.PercentageBar != PercentageBars.Bars.none) { foreach (KeyValuePair <string, List <User> > x in pollVotes) { percentageUserCount += x.Value.Count; } } bool descTooLong = false; foreach (KeyValuePair <string, List <User> > x in newVotes) { int votingUserCount = x.Value.Count; text += String.Format("\n<b>{0}</b> [{1}]\n", HtmlSpecialChars.Encode(x.Key).UnmarkupUsernames(), votingUserCount); if (anony == EAnony.personal) { if (x.Value.Count > 0) { if (PercentageBar != PercentageBars.Bars.none) { text += PercentageBars.RenderPercentage((double)x.Value.Count / percentageUserCount, this.PercentageBar, true); } User last = x.Value.Last(); foreach (User user in x.Value) { text += "\u200E" + (user == last ? "└" : "├") + " " + HtmlSpecialChars.Encode((user.FirstName + (user.LastName != null ? " " + user.LastName : "")).Replace("\u200F", "").Replace("\u202B", "").Replace("\u202E", "").Truncate(25)) + "\n"; userCount++; } } else { if (PercentageBar != PercentageBars.Bars.none) { text += PercentageBars.RenderPercentage((double)x.Value.Count / percentageUserCount, this.PercentageBar); } } } else { if (PercentageBar != PercentageBars.Bars.none) { text += PercentageBars.RenderPercentage((double)x.Value.Count / percentageUserCount, this.PercentageBar); } userCount += x.Value.Count; } string unsortedKey = pollVotes.Keys.ElementAt(optionCount); if (!closed && !channel) { List <InlineKeyboardButton> thisRow = new List <InlineKeyboardButton>(1); thisRow.Add((InlineKeyboardButton)InlineKeyboardButton.Create(unsortedKey + " - " + pollVotes.Values.ElementAt(optionCount).Count, callbackData: Cryptography.Encrypt(chatId + ":" + pollId + ":" + optionCount, apikey))); inlineKeyboard.InlineKeyboard.Add(thisRow); } if (description.Length < 150) { description += unsortedKey.Truncate(15) + " | "; } else { descTooLong = true; } optionCount++; } if (descTooLong) { description += " | ..."; } description = "Personal vote - " + userCount + " participants\n" + description; if (!closed && channel) { inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.buttonVote), url: "https://telegram.me/" + Globals.Botname + "bot?start=" + Cryptography.Encrypt("vote:" + ChatId + ":" + PollId, apikey)) }); } if (!closed && Appendable) { inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.buttonAppend), url: "https://telegram.me/" + Globals.Botname + "bot?start=" + Cryptography.Encrypt("append:" + ChatId + ":" + PollId, apikey)) }); } if (delete) { inlineKeyboard = null; } description = description.Substring(0, description.Length - 3); text += "\n" + string.Format(strings.GetString(userCount == 0 ? Strings.stringsList.rendererZeroVotedSoFar : (userCount == 1 ? Strings.stringsList.rendererSingleVotedSoFar : Strings.stringsList.rendererMultiVotedSoFar)), userCount); if (closed) { text += "\n" + strings.GetString(Strings.stringsList.pollClosed); } } strings.SetLanguage(oldLang); return(new ContentParts(text, inlineKeyboard, description)); }
string RenderPercentage(int currentOptionUserCount, int peopleCount) { return(PercentageBars.RenderPercentage((double)currentOptionUserCount / peopleCount, this.PercentageBar, true)); }