Пример #1
0
        protected virtual InlineKeyboardMarkup GenerateUserMarkup(Strings strings, string apikey)
        {
            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://t.me/" + Globals.GlobalOptions.Botname + "/?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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public virtual string RenderExpansion(Strings strings)
 {
     return("<a href=\"" + "https://hamilton.wjclub.tk/" + Globals.GlobalOptions.Botname + "/" + Cryptography.Encrypt("lookup:" + this.ChatId + ":" + this.PollId, Globals.GlobalOptions.Apikey) + "\">\ud83c\udf0e " + strings.GetString(Strings.StringsList.viewInBrowserExpansion) + "</a>");
 }
Пример #4
0
        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);
        }
Пример #5
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));
        }