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);
        }
        public virtual InlineKeyboardMarkup RenderInlineKeyboard(List <int> pollVotesCount, Strings strings, bool noApproximation, bool channel = false)
        {
            if (Closed || delete)
            {
                return(new InlineKeyboardMarkup());
            }
            InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup {
                InlineKeyboard = new List <List <InlineKeyboardButton> >()
            };

            if (channel)
            {
                inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                    InlineKeyboardButton.Create(strings.GetString(Strings.StringsList.buttonVote), url: "https://telegram.me/" + Globals.GlobalOptions.Botname + "?start=" + Cryptography.Encrypt("vote:" + ChatId + ":" + PollId, Globals.GlobalOptions.Apikey))
                });
            }
            else
            {
                int optionCount = 0;
                foreach (string optionTitle in PollVotes.Keys)
                {
                    inlineKeyboard.InlineKeyboard.Add(RenderInlineButton(optionTitle, optionCount, pollVotesCount.ElementAt(optionCount), noApproximation));
                    optionCount++;
                }
            }
            if (Appendable)
            {
                inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                    InlineKeyboardButton.Create(strings.GetString(Strings.StringsList.buttonAppend), url: "https://telegram.me/" + Globals.GlobalOptions.Botname + "?start=" + Cryptography.Encrypt("append:" + ChatId + ":" + PollId, Globals.GlobalOptions.Apikey))
                });
            }
            return(inlineKeyboard);
        }
        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;

            {
                description = StringEdit.CurrentCulture.TextInfo.ToTitleCase(anony.ToString()) + " " + pollType + ": " + pollText + ": ";
                int optionCount = 0;
                text = "\ud83d\udcca <b>" + HtmlSpecialChars.Encode(pollText).UnmarkupUsernames() + "</b>" + (!string.IsNullOrEmpty(pollDescription) ? ("\n" + HtmlSpecialChars.Encode(pollDescription) + "\n") : "\n");
                foreach (KeyValuePair <string, List <User> > x in pollVotes)
                {
                    int votingUserCount = x.Value.Count;
                    text += "\n<b>" + HtmlSpecialChars.Encode(x.Key).UnmarkupUsernames() + "</b> [" + votingUserCount + "]\n";
                    if (anony == EAnony.personal)
                    {
                        if (x.Value.Count > 0)
                        {
                            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";
                            }
                        }
                    }
                    if (!closed && !channel)
                    {
                        List <InlineKeyboardButton> thisRow = new List <InlineKeyboardButton>(1);
                        thisRow.Add((InlineKeyboardButton)InlineKeyboardButton.Create(x.Key + " - " + votingUserCount, callbackData: Cryptography.Encrypt(chatId + ":" + pollId + ":" + optionCount, apikey)));
                        inlineKeyboard.InlineKeyboard.Add(thisRow);
                    }
                    description += x.Key + ", ";
                    optionCount++;
                }
                description = description.Substring(0, description.Length - 2);
                int userCount = people.Count;
                if (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.ToString() + ":" + PollId.ToString(), apikey))
                    });
                }
                text += "\n" + string.Format(strings.GetString(userCount == 0 ? Strings.stringsList.rendererZeroVotedSoFar : (userCount == 1 ? Strings.stringsList.rendererSingleVotedSoFar : Strings.stringsList.rendererMultiVotedSoFar)), userCount);
                if (delete || closed)
                {
                    inlineKeyboard = null;
                    text          += "\n" + strings.GetString(Strings.stringsList.pollClosed);
                }
            }
            strings.SetLanguage(oldLang);
            return(new ContentParts(text, inlineKeyboard, description));
        }
Beispiel #4
0
        private static ContentParts prepare(Strings strings, Pointer pointer)
        {
            string text = String.Format(strings.GetString(Strings.stringsList.startMessage), strings.GetString((Strings.stringsList)Enum.Parse(typeof(Strings.stringsList), pointer.PollType.ToString())), (pointer.Anony == EAnony.anonymous ? "✅" : "☑"));
            InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup();

            inlineKeyboard.InlineKeyboard = new List <List <InlineKeyboardButton> >();
            inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> ());
            inlineKeyboard.InlineKeyboard[0].Add(InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.startMessageChangePollTypeButton), callbackData: "page:chpoll"));
            inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> ());
            inlineKeyboard.InlineKeyboard[1].Add(InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.stringsList.startMessagePersonalButton), (pointer.Anony == EAnony.personal ? "✅" : "☑")), callbackData: "comm:pers"));
            inlineKeyboard.InlineKeyboard[1].Add(InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.stringsList.startMessageAnonyButton), (pointer.Anony == EAnony.anonymous ? "✅" : "☑")), callbackData: "comm:anony"));
            return(new ContentParts(text, inlineKeyboard, null));
        }
        public virtual InlineKeyboardMarkup RenderModerationInlineKeyboard(Strings strings)
        {
            InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup {
                InlineKeyboard = new List <List <InlineKeyboardButton> >
                {
                    new List <InlineKeyboardButton> {
                        InlineKeyboardButton.Create(EmojiStore.Done + " " + strings.GetString(Strings.StringsList.done), callbackData: "comm:options:" + this.ChatId + ":" + this.PollId)
                    }
                }
            };

            return(inlineKeyboard);
        }
        public override InlineKeyboardMarkup RenderInlineKeyboard(List <int> pollVotesCount, Strings strings, bool noApproximation, bool channel = false)
        {
            InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup();

            inlineKeyboard.InlineKeyboard = new List <List <InlineKeyboardButton> >();
            if (!closed && !delete)
            {
                inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton>()
                {
                    InlineKeyboardButton.Create(strings.GetString(Strings.StringsList.buttonVote), url: $"https://telegram.me/{ Globals.GlobalOptions.Botname }?start={ Cryptography.Encrypt($"board:{ ChatId.ToString() }:{ PollId.ToString() }") }")
                });
            }
            return(inlineKeyboard);
        }
        public virtual List <InlineKeyboardButton> RenderInlineButton(string optionTitle, int optionCount, int votersCount, bool noApproximation)
        {
            string oneLineTitle = optionTitle.Split('\n')[0];
            Match  match        = GetAppendingMatch(oneLineTitle);

            if (match.Success)
            {
                oneLineTitle = oneLineTitle.Substring(match.Index + match.Length + 2);
            }
            var inlineKeyboardRow = new List <InlineKeyboardButton> {
                InlineKeyboardButton.Create(oneLineTitle.Truncate(30) + " - " + RenderNumberUpdateFriendly(votersCount, noApproximation), callbackData: Cryptography.Encrypt(chatId + ":" + pollId + ":" + optionCount, Globals.GlobalOptions.Apikey))
            };

            return(inlineKeyboardRow);
        }
Beispiel #8
0
        protected virtual InlineKeyboardMarkup GenerateUserMarkup(Strings strings, string apikey)
        {
            string botname = Globals.Botname;

            if (delete)
            {
                return(null);
            }
            InlineKeyboardMarkup inline = new InlineKeyboardMarkup {
                InlineKeyboard = new List <List <InlineKeyboardButton> >()
            };

            if (!closed)
            {
                inline.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                    InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.publish), switchInlineQuery: pollText)
                });
                if (pollType != EPolls.board)
                {
                    inline.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                        InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.publishWithLink), switchInlineQuery: "$c:" + pollText)
                    });
                    inline.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                        InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.buttonVote), callbackData: "comm:iwannavote:" + Cryptography.Encrypt(chatId + ":" + pollId, apikey)),
                        InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.commPageRefresh), callbackData: "comm:update:" + chatId + ":" + pollId)
                    });
                }
                else
                {
                    inline.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                        InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.buttonVote), url: "https://telegram.me/" + Globals.Botname + "bot?start=" + Cryptography.Encrypt("board:" + chatId + ":" + pollId, apikey)),
                        InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.commPageRefresh), callbackData: "comm:update:" + chatId + ":" + pollId)
                    });
                }
            }
            inline.InlineKeyboard.Add(new List <InlineKeyboardButton>()
            {
                InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.commPageOptions), callbackData: "comm:options:" + chatId + ":" + pollId),
                InlineKeyboardButton.Create((closed ? strings.GetString(Strings.stringsList.commPageReopen) : strings.GetString(Strings.stringsList.commPageClose)), callbackData: "comm:" + (closed ? "reopen:" : "close:") + chatId + ":" + pollId),
                InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.commPageDelete), callbackData: "comm:delete:" + chatId + ":" + pollId),
            });
            return(inline);
        }
Beispiel #9
0
        private static ContentParts prepare(Strings strings, Pointer pointer)
        {
            string text = strings.GetString(Strings.stringsList.setLanguage);
            InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup();

            inlineKeyboard.InlineKeyboard = new List <List <InlineKeyboardButton> >();
            var values = Enum.GetValues(typeof(Strings.langs));
            int j      = -1;

            for (int i = 1; i < values.Length; i++)
            {
                int wI = i - 1;
                if (wI % 2 == 0)
                {
                    inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton>());
                    j++;
                }
                inlineKeyboard.InlineKeyboard[j].Add(InlineKeyboardButton.Create(strings.GetLangName((Strings.langs)values.GetValue(i)) + (values.GetValue(i).Equals(pointer.Lang) ? " ✅" : ""), callbackData: ("comm:lang:" + values.GetValue(i))));
            }
            inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                InlineKeyboardButton.Create("\ud83d\udcbe " + strings.GetString(Strings.stringsList.done), callbackData: "comm:showWelcome")
            });
            return(new ContentParts(text, inlineKeyboard, null));
        }
        protected ContentParts GetPollOutputOld(Strings strings, int peopleCount, List <int> pollVotesCount, bool noApproximation, bool channel = false)
        {
            Strings.Langs oldLang = strings.CurrentLang;
            strings.SetLanguage(lang);
            string text;
            string inlineTitle = this.pollText;
            //TODO Make this pretty
            string inlineDescription;
            InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup();

            inlineKeyboard.InlineKeyboard = new List <List <InlineKeyboardButton> >();
            //if (offset == null) {
            if (!closed)
            {
                inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton>()
                {
                    InlineKeyboardButton.Create(strings.GetString(Strings.StringsList.buttonVote), url: $"https://telegram.me/{ Globals.GlobalOptions.Botname }?start={ Cryptography.Encrypt($"board:{ ChatId.ToString() }:{ PollId.ToString() }") }")
                });
            }
            inlineDescription = StringEdit.CurrentCulture.TextInfo.ToTitleCase(anony.ToString()) + " " + pollType + ": " + pollText + ": ";
            text = "\ud83d\udcdd <b>" + HtmlSpecialChars.Encode(pollText).UnmarkupUsernames() + "</b>" + (!string.IsNullOrEmpty(pollDescription) ? ("\n" + HtmlSpecialChars.Encode(pollDescription) + "\n") : "\n");
            foreach (KeyValuePair <int, BoardVote> x in pollVotes)
            {
                string toAdd = (anony == EAnony.personal ? "\n\u200E<b>" + HtmlSpecialChars.Encode(x.Value.Name.Replace("\u200F", "").Replace("\u202B", "").Replace("\u202E", "").Truncate(25)) + ": </b>" : "\n\ud83d\udc64 ") + HtmlSpecialChars.Encode(x.Value.Text) + "\n";
                if (text.Length + toAdd.Length <= 4000)
                {
                    text += toAdd;
                    inlineDescription += x.Value.Text + ", ";
                }
                else
                {
                    text += "\n▶️ <a href=\"https://telegram.me/" + Globals.GlobalOptions.Botname + "?start=" + Cryptography.Encrypt("pag:" + chatId + ":" + pollId + ":0") + "\">" + strings.GetString(Strings.StringsList.boardShowMore) + "</a>\n";
                    break;
                }
            }
            if (delete || closed)
            {
                inlineKeyboard = null;
            }
            inlineDescription = inlineDescription.Substring(0, inlineDescription.Length - 2);
            text += "\n" + string.Format(strings.GetString(pollVotes.Count == 0 ? Strings.StringsList.rendererZeroVotedSoFar : (pollVotes.Count == 1 ? Strings.StringsList.rendererSingleVotedSoFar : Strings.StringsList.rendererMultiVotedSoFar)), pollVotes.Count);
            if (closed)
            {
                text += "\n" + strings.GetString(Strings.StringsList.pollClosed);
            }

            /*} else {
             *      inlineDescription = "";
             *      if (offset < pollVotes.Count) {
             *              int difference = (int)offset - (pollVotes.Count - 1);
             *              text = "";
             *              for (int i = (int)offset; i < offset + 5; i++) {
             *                      try {
             *                              var x = pollVotes.ElementAt(i);
             *                              text += (anony == EAnony.personal ? "\u200E<b>" + HtmlSpecialChars.Encode(x.Value.Name.Replace("\u200F", "").Replace("\u202B", "").Replace("\u202E", "").Truncate(25)) + ": </b>" : "\ud83d\udc64 ") + HtmlSpecialChars.Encode(x.Value.Text) + "\n\n";
             *                      } catch (ArgumentOutOfRangeException){
             *                              break;
             *                      }
             *              }
             *              inlineKeyboard.InlineKeyboard.Add(new List<InlineKeyboardButton> {
             *                              InlineKeyboardButton.Create("<<", callbackData:"comm:pag:" + chatId + ":" + pollId + ":" + (offset - 5 >= 0 ? (offset - 5) : 0)),
             *                              InlineKeyboardButton.Create(">>", callbackData:"comm:pag:" + chatId + ":" + pollId + ":" + (offset + 5 < pollVotes.Count ? (offset + 5) : pollVotes.Count - 1))
             *                      });
             *              text += string.Format(strings.GetString(Strings.StringsList.boardPagBottomLine), (offset + 1), (pollVotes.Count - offset < 5 ? pollVotes.Count - (offset - 5) : (offset + 5)),pollVotes.Count);
             *      } else {
             *              text = strings.GetString(Strings.StringsList.boardPagCantFind);
             *      }
             * }*/
            strings.SetLanguage(oldLang);
            return(new ContentParts(text, inlineKeyboard, inlineTitle, inlineDescription));
        }
Beispiel #11
0
        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));
        }
Beispiel #12
0
 public static InlineKeyboardMarkup GetTheModerationKeyboard(Strings strings, long chatID, int pollID)
 {
     return(GetOneButtonMarkup(InlineKeyboardButton.Create(strings.GetString(Strings.StringsList.moderate), callbackData: String.Format("comm:moderate:{0}:{1}", chatID, pollID))));
 }
Beispiel #13
0
        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;
            string description;
            InlineKeyboardMarkup inlineKeyboard = new InlineKeyboardMarkup();

            inlineKeyboard.InlineKeyboard = new List <List <InlineKeyboardButton> >();
            if (offset == null)
            {
                if (!closed)
                {
                    inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton>()
                    {
                        InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.buttonVote), url: "https://telegram.me/" + Globals.Botname + "bot?start=" + Cryptography.Encrypt("board:" + ChatId.ToString() + ":" + PollId.ToString(), apikey))
                    });
                }
                //inlineKeyboard.InlineKeyboard.Add(new List<InlineKeyboardButton>() { InlineKeyboardButton.Create(strings.GetString(Strings.stringsList.buttonVote), url: "https://telegram.me/" + Globals.Botname + "bot?start=" + "board:" + ChatId + ":" + PollId) });
                description = StringEdit.CurrentCulture.TextInfo.ToTitleCase(anony.ToString()) + " " + pollType + ": " + pollText + ": ";
                text        = "\ud83d\udcdd <b>" + HtmlSpecialChars.Encode(pollText).UnmarkupUsernames() + "</b>" + (!string.IsNullOrEmpty(pollDescription) ? ("\n" + HtmlSpecialChars.Encode(pollDescription) + "\n") : "\n");
                foreach (KeyValuePair <int, BoardVote> x in pollVotes)
                {
                    string toAdd = (anony == EAnony.personal ? "\n\u200E<b>" + HtmlSpecialChars.Encode(x.Value.Name.Replace("\u200F", "").Replace("\u202B", "").Replace("\u202E", "").Truncate(25)) + ": </b>" : "\n\ud83d\udc64 ") + HtmlSpecialChars.Encode(x.Value.Text) + "\n";
                    if (text.Length + toAdd.Length <= 4000)
                    {
                        text        += toAdd;
                        description += x.Value.Text + ", ";
                    }
                    else
                    {
                        text += "\n▶️ <a href=\"https://telegram.me/" + Globals.Botname + "bot?start=" + Cryptography.Encrypt("pag:" + chatId + ":" + pollId + ":0", apikey) + "\">" + strings.GetString(Strings.stringsList.boardShowMore) + "</a>\n";
                        break;
                    }
                }
                if (delete || closed)
                {
                    inlineKeyboard = null;
                }
                description = description.Substring(0, description.Length - 2);
                text       += "\n" + string.Format(strings.GetString(pollVotes.Count == 0 ? Strings.stringsList.rendererZeroVotedSoFar : (pollVotes.Count == 1 ? Strings.stringsList.rendererSingleVotedSoFar : Strings.stringsList.rendererMultiVotedSoFar)), pollVotes.Count);
                if (closed)
                {
                    text += "\n" + strings.GetString(Strings.stringsList.pollClosed);
                }
            }
            else
            {
                description = "";
                if (offset < pollVotes.Count)
                {
                    int difference = (int)offset - (pollVotes.Count - 1);
                    text = "";
                    for (int i = (int)offset; i < offset + 5; i++)
                    {
                        try {
                            var x = pollVotes.ElementAt(i);
                            text += (anony == EAnony.personal ? "\u200E<b>" + HtmlSpecialChars.Encode(x.Value.Name.Replace("\u200F", "").Replace("\u202B", "").Replace("\u202E", "").Truncate(25)) + ": </b>" : "\ud83d\udc64 ") + HtmlSpecialChars.Encode(x.Value.Text) + "\n\n";
                        } catch (ArgumentOutOfRangeException) {
                            break;
                        }
                    }
                    inlineKeyboard.InlineKeyboard.Add(new List <InlineKeyboardButton> {
                        InlineKeyboardButton.Create("<<", callbackData: "comm:pag:" + chatId + ":" + pollId + ":" + (offset - 5 >= 0 ? (offset - 5) : 0)),
                        InlineKeyboardButton.Create(">>", callbackData: "comm:pag:" + chatId + ":" + pollId + ":" + (offset + 5 < pollVotes.Count ? (offset + 5) : pollVotes.Count - 1))
                    });
                    text += string.Format(strings.GetString(Strings.stringsList.boardPagBottomLine), (offset + 1), (pollVotes.Count - offset < 5 ? pollVotes.Count - (offset - 5) : (offset + 5)), pollVotes.Count);
                }
                else
                {
                    text = strings.GetString(Strings.stringsList.boardPagCantFind);
                }
            }
            strings.SetLanguage(oldLang);
            return(new ContentParts(text, inlineKeyboard, description));
        }