Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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;

            {
                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));
        }
Exemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            _site = null;
            if (SiteId != 0)
            {
                _site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(SiteId);
            }

            if (_site == null || !_site.isEnabled)
            {
                return;
            }

            string link = String.IsNullOrEmpty(_site.link) ? "http://awapi.com" : _site.link;

            _feed = new SyndicationFeed(_site.title + " - Poll Feed", "", new Uri(link));
            _feed.Authors.Add(new SyndicationPerson("*****@*****.**"));

            _feed.AttributeExtensions.Add(new XmlQualifiedName("site"), _site.title);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("sitelink"), _site.link);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("defaultculture"), _site.cultureCode);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("culture"), CultureCode);
            if (PollId > 0)
            {
                _feed.AttributeExtensions.Add(new XmlQualifiedName("pollid"), PollId.ToString());
            }

            AddParamsToFeed();

            context.Response.ContentType     = "text/xml";
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;

            switch (MethodName)
            {
            case "getpoll":
                _feed.Title = new TextSyndicationContent(_site.title + " - Poll");
                GetPoll(PollId, CultureCode);
                break;

            case "getpolllist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Poll List");
                GetPollList(SiteId, CultureCode, PageIndex, PageSize);
                break;

            default:
                break;
            }

            string    output = "";
            XmlWriter writer = XmlWriter.Create(context.Response.Output);

            if (_feed != null)
            {
                switch (ReturnType)
                {
                case "atom":
                    context.Response.ContentType = "application/atom+xml";
                    Atom10FeedFormatter atom = new Atom10FeedFormatter(_feed);
                    atom.WriteTo(writer);
                    break;

                case "json":
                    context.Response.ContentType = "application/json";
                    Rss20FeedFormatter rssFeed = new Rss20FeedFormatter(_feed);
                    if (rssFeed != null)
                    {
                        output = Newtonsoft.Json.JsonConvert.SerializeObject(rssFeed);
                        //JavaScriptSerializer ser = new JavaScriptSerializer();
                        //output = ser.Serialize(rssFeed);
                    }
                    break;

                default:        //rss
                    context.Response.ContentType = "application/rss+xml";
                    Rss20FeedFormatter rss = new Rss20FeedFormatter(_feed);
                    rss.WriteTo(writer);
                    break;
                }
            }

            if (output != "")
            {
                context.Response.Write(output);
            }

            writer.Close();
        }