Beispiel #1
0
    public List <String> GetVideosByPlaylistID(string sPlaylistID, int num_vids)
    {
        List <String> feed = new List <String>();

        try
        {
            string request_uri       = string.Format(YOUTUBE_API_URL, sPlaylistID, num_vids.ToString(), api_key);
            string yt_response       = GET(request_uri);
            JavaScriptSerializer ser = new JavaScriptSerializer();
            dynamic jresponse        = ser.Deserialize <dynamic>(yt_response);

            var data = jresponse["items"];
            foreach (var searchResult in data)
            {
                MarkupBuilder mb     = new MarkupBuilder();
                string        yt_str = mb.GetMarkup("YouTube");
                string        im     = string.Format(yt_str, searchResult["snippet"]["resourceId"]["videoId"], searchResult["snippet"]["thumbnails"]["medium"]["url"], searchResult["snippet"]["title"]);
                feed.Add(im);
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("SocialApp control", "YouTubeManager GetVideosByPlaylistID", ex);
        }

        return(feed.OrderBy(x => Guid.NewGuid()).ToList());
    }
        public MarkupBuilder GetLabel(DeltinScript deltinScript, LabelInfo labelInfo)
        {
            var builder = new MarkupBuilder().StartCodeLine();

            if (Parameters.Length == 1)
            {
                builder.Add(_argumentTypes[0].GetName() + " " + Parameters[0].Name);
            }
            else
            {
                builder.Add("(");
                for (int i = 0; i < Parameters.Length; i++)
                {
                    if (i != 0)
                    {
                        builder.Add(", ");
                    }
                    builder.Add(_argumentTypes[i].GetName() + " " + Parameters[i].Name);
                }
                builder.Add(")");
            }
            builder.Add(" => ");
            builder.Add(ReturnType.GetNameOrVoid());

            return(builder);
        }
Beispiel #3
0
    public List <String> GetRandomTweet(string uname, int numtweets)
    {
        List <string>        tw_list     = new List <string>();
        string               resourceurl = string.Format(TWITTER_API_URI, uname);
        string               tw_response = GetTwitterData(resourceurl);
        JavaScriptSerializer ser         = new JavaScriptSerializer();
        dynamic              tweets      = ser.Deserialize <dynamic>(tw_response);

        foreach (var t in tweets)
        {
            try
            {
                MarkupBuilder mb     = new MarkupBuilder();
                string        tw_str = mb.GetMarkup("Twitter");
                string        s      = string.Format(tw_str, "https://twitter.com/" + uname + "/status/" + t["id"], t["text"], t["created_at"]);
                tw_list.Add(s);
            }
            catch
            {
                string dsd = "";
            }
        }

        if (tw_list.Count > 0)
        {
            return(tw_list.OrderBy(x => Guid.NewGuid()).Take(numtweets).ToList());
        }
        else
        {
            return(null);
        }
    }
        MarkupBuilder ILabeled.GetLabel(DeltinScript deltinScript, LabelInfo labelInfo)
        {
            var builder = new MarkupBuilder();

            builder.StartCodeLine().Add("new " + Name + "(");

            for (int i = 0; i < ParameterProviders.Length; i++)
            {
                if (i != 0)
                {
                    builder.Add(", ");
                }

                // Add the parameter type.
                if (labelInfo.IncludeParameterTypes)
                {
                    builder.Add(ParameterProviders[i].Type.GetName());

                    // Add a space if the name is also included.
                    if (labelInfo.IncludeParameterNames)
                    {
                        builder.Add(" ");
                    }
                }

                // Add the parameter name.
                if (labelInfo.IncludeParameterNames)
                {
                    builder.Add(ParameterProviders[i].Name);
                }
            }

            return(builder.Add(")").EndCodeLine());
        }
Beispiel #5
0
 public CodeParameter(string name, MarkupBuilder documentation, ICodeTypeSolver type, ExpressionOrWorkshopValue defaultValue)
 {
     Name          = name;
     _type         = type;
     DefaultValue  = defaultValue;
     Documentation = documentation;
 }
        public MarkupBuilder MakeFunctionLabel(DeltinScript deltinScript, CodeType type, string name, IParameterLike[] parameters, AnonymousType[] typeArgs)
        {
            var builder = new MarkupBuilder().StartCodeLine();

            if (IncludeReturnType)
            {
                builder.Add(AnonymousLabelInfo.NameFromSolver(deltinScript, type) + " ");
            }

            builder.Add(name);

            if (typeArgs.Length != 0)
            {
                builder.Add("<" + string.Join(", ", typeArgs.Select(typeArg => typeArg.GetDeclarationName())) + ">");
            }

            builder.Add("(");

            for (int i = 0; i < parameters.Length; i++)
            {
                if (i != 0)
                {
                    builder.Add(", ");
                }
                builder.Add(parameters[i].GetLabel(deltinScript, AnonymousLabelInfo));
            }

            return(builder.Add(")").EndCodeLine());
        }
Beispiel #7
0
    public List <String> GetRandomPost(string username, int num_posts)
    {
        List <String> fbpost_list = new List <String>();

        var data = getStatuses(username, num_posts);

        if (data != null)
        {
            foreach (var post in data)
            {
                try
                {
                    MarkupBuilder mb     = new MarkupBuilder();
                    string        fb_str = mb.GetMarkup("Facebook");
                    string        link   = "http://www.facebook.com/" + post["id"].ToString().Replace("_", "/posts/");
                    string        im     = string.Format(fb_str, link, mb.PreviewPrettyTrunc(post["message"].ToString(), 200), post["updated_time"].ToString());
                    fbpost_list.Add(im);
                }
                catch { }
            }

            return(fbpost_list.OrderBy(x => Guid.NewGuid()).ToList());
        }
        else
        {
            return(fbpost_list);
        }
    }
 // Creates the CompletionItem for a snippet.
 static CompletionItem MakeSnippet(string label, string detail, MarkupBuilder documentation, string insert) => new CompletionItem()
 {
     Kind             = CompletionItemKind.Snippet,
     InsertTextFormat = InsertTextFormat.Snippet,
     Label            = label,
     InsertText       = insert,
     Detail           = detail,
     Documentation    = documentation.ToMarkup()
 };
Beispiel #9
0
 public bool TryInvokeMember(MarkupBuilder builder, InvokeMemberBinder binder, object[] args, out object result)
 {
     if (binder.Name == "attr")
     {
         builder.Attributes.Add(binder.Name, (string)args[0]);
         result = builder;
         return true;
     }
     result = null;
     return false;
 }
Beispiel #10
0
    public MarkupBuilder Append(MarkupBuilder markups)
    {
        if (markups._list.First is null)
        {
            return(this);
        }

        _list.AddLast(markups._list.First);

        return(this);
    }
        public MarkupBuilder MakeVariableLabel(CodeType type, string name)
        {
            var builder = new MarkupBuilder().StartCodeLine();

            if (IncludeReturnType)
            {
                builder.Add(type.GetName()).Add(" ");
            }

            return(builder.Add(name).EndCodeLine());
        }
Beispiel #12
0
        //----------------------------------------------------------------//

        public async Task Notify(ICommand <History, Int32> historyCommand, NotificationModel model)
        {
            if (model.NotificationTime <= DateTime.Now.TimeOfDay)
            {
                History history = new History(DateTime.Now, model.CaseId, model.UserId);
                history.Id = await historyCommand.InsertAsync(history);

                String message = $"(№{history.Id}). Has @{model.UserName} done {model.CaseName}?";
                InlineKeyboardMarkup markup = MarkupBuilder.CaseNotifyKeyboardMarkup(history.Id);
                await _botClient.SendTextMessageAsync(model.ChatId, message, replyMarkup : markup);
            }
        }
        public MarkupBuilder GetLabel(DeltinScript deltinScript, LabelInfo labelInfo)
        {
            var builder = new MarkupBuilder().StartCodeLine().Add("new " + Type.GetName());

            builder.Add(CodeParameter.GetLabels(deltinScript, labelInfo.AnonymousLabelInfo, Parameters)).EndCodeLine();

            if (labelInfo.IncludeDocumentation)
            {
                builder.NewSection().Add(Documentation);
            }

            return(builder);
        }
Beispiel #14
0
    public MarkupBuilder Append(MarkupBuilder markups, TextFormat format)
    {
        if (markups._list.First is null)
        {
            return(this);
        }

        PushTextFormat(format)
        .Append(markups._list.First)
        .PopTextFormat();

        return(this);
    }
Beispiel #15
0
    public MarkupBuilder Append(MarkupBuilder markups, Style style)
    {
        if (markups._list.First is null)
        {
            return(this);
        }

        PushStyle(style);
        _list.AddLast(markups._list.First);
        PopStyle();

        return(this);
    }
Beispiel #16
0
        ///<summary>Adds a hover to the file.</summary>
        public void AddHover(DocRange range, MarkupBuilder content)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            _hoverRanges.Add(new HoverRange(range, content));
        }
        public void GetScriptsForDebugging()
        {
            var fileResolver = new Mock<IBundleParser>();
            var builder = new MarkupBuilder(fileResolver.Object);

            var files = new[] {"foo.js", "bar.js"};

            fileResolver.Setup(x => x.GetRelativeFiles(It.IsAny<string>())).Returns(files);

            var result = builder.GetScriptsForDebugging("");
            result.Should().Be("<script src=\"foo.js\"></script><script src=\"bar.js\"></script>");

        }
Beispiel #18
0
    //Builds call to action boxes (box with just text or other content)
    //CTA boxes always show up on the page and take priority over social boxes and backup images
    public List <String> BuildCTAList(List <String> ctas)
    {
        List <String> cta_list = new List <string>();

        foreach (String s in ctas)
        {
            MarkupBuilder mb     = new MarkupBuilder();
            string        ct_str = mb.GetMarkup("Other");
            string        ct     = string.Format(ct_str, s);
            cta_list.Add(ct);
        }
        return(cta_list);
    }
Beispiel #19
0
    public MarkupBuilder Append(MarkupBuilder markups, TextColor color, bool asBackground = false)
    {
        if (markups._list.First is null)
        {
            return(this);
        }

        PushColor(color, asBackground)
        .Append(markups._list.First)
        .PopColor(asBackground);

        return(this);
    }
Beispiel #20
0
    public List <String> BuildImageList(string images, int num_images)
    {
        List <String> img_list   = new List <string>();
        List <string> all_images = Regex.Split(images, "{}").ToList();

        foreach (string img in all_images)
        {
            MarkupBuilder mb      = new MarkupBuilder();
            string        img_str = mb.GetMarkup("Other");
            string        im      = string.Format(img_str, img);
            img_list.Add(im);
        }
        return(img_list.OrderBy(x => Guid.NewGuid()).Take(num_images).ToList());
    }
        public override void Call(ParseInfo parseInfo, DocRange callRange)
        {
            MarkupBuilder hoverContents = new MarkupBuilder()
                                          .StartCodeLine()
                                          .Add((_constant ? "constant " : "enum ") + Name)
                                          .EndCodeLine();

            if (_constant)
            {
                hoverContents.NewSection().Add("Constant workshop types cannot be stored. Variables with this type cannot be changed from their initial value.");
            }

            parseInfo.Script.AddHover(callRange, hoverContents.ToString());
            parseInfo.Script.AddToken(callRange, TokenType, TokenModifiers.ToArray());
        }
 public static FuncMethod Method(ITypeSupplier types) => new FuncMethodBuilder()
 {
     Name          = "WaitAsync",
     Documentation = new MarkupBuilder().Add("Waits without blocking the current rule, executing the provided action when the wait completes.").NewLine()
                     .Add("Using ").Code("Wait").Add(" inside a subroutine that interacts with variables may result in weird and unexpected behaviours when executed from multiples places at once due to race conditions. ")
                     .Code("WaitAsync").Add(" will not have this issue.")
                     .NewLine().Add("You can not run the rule below multiple times simultaneously because the ").Code("Wait").Add(" will block the rule.").NewLine()
                     .StartCodeLine().Add("rule: \"My Rule\"").NewLine().Add("if(IsButtonHeld(HostPlayer(), Button.Interact))").NewLine().Add("{").NewLine()
                     .Add("    x = RandomInteger(0, 10);").NewLine().NewLine().Add("    SmallMessage(AllPlayers(), x);").NewLine().Add("    Wait(3)").NewLine().Add("    SmallMessage(AllPlayers(), x);")
                     .NewLine().Add("}").EndCodeLine().NewLine()
                     .Add("However, using ").Code("WaitAsync").Add(", the rule can be executed multiple times simultaneously.").NewLine()
                     .StartCodeLine().Add("rule: \"My Rule\"").NewLine().Add("if(IsButtonHeld(HostPlayer(), Button.Interact))").NewLine().Add("{").NewLine()
                     .Add("    x = RandomInteger(0, 10);").NewLine().NewLine().Add("    SmallMessage(AllPlayers(), x);").NewLine().Add("    WaitAsync(3, () => {").NewLine().Add("        SmallMessage(AllPlayers(), x);")
                     .NewLine().Add("    });").NewLine().Add("}").EndCodeLine()
                     .ToString(),
     Parameters = new[] {
 public PathmapClass(DeltinScript deltinScript) : base("Pathmap")
 {
     DeltinScript      = deltinScript;
     this.Constructors = new Constructor[] {
         new PathmapClassConstructor(this),
         new Constructor(this, null, AccessLevel.Public)
         {
             Documentation = "Creates an empty pathmap."
         }
     };
     Description = new MarkupBuilder()
                   .Add("A pathmap can be used for pathfinding.").NewLine()
                   .Add("Pathmaps are imported from ").Code(".pathmap").Add(" files. These files are generated from an ingame editor. Run the ").Code("Copy Pathmap Editor Code").Add(" command by opening the command palette with ").Code("ctrl+shift+p")
                   .Add(". Paste the rules into Overwatch and select the map the pathmap will be created for.")
                   .ToString();
 }
Beispiel #24
0
        public bool TryInvokeMember(MarkupBuilder builder, InvokeMemberBinder binder, object[] args, out object result)
        {
            if (binder.Name != "createElement")
            {
                result = null;
                return false;
            }

            if (!args.Any()) { throw new ArgumentNullException(nameof(args), "You need to specify alement name to create."); }

            var containsContent = args.Length > 1;

            var tag = (string)args[0];
            var content = containsContent ? args[1] : Enumerable.Empty<object>();
            result = builder.Create(tag).AddRange(content);
            return true;
        }
        /// <summary>Calls a type from the specified document range.</summary>
        /// <param name="parseInfo">The script that the type was called from.</param>
        /// <param name="callRange">The range of the call.</param>
        public virtual void Call(ParseInfo parseInfo, DocRange callRange)
        {
            parseInfo.Script.AddToken(callRange, TokenType, TokenModifiers.ToArray());

            var hover = new MarkupBuilder().StartCodeLine().Add(Kind.ToString().ToLower() + " " + Name);

            if (Generics.Length != 0)
            {
                hover.Add("<" + string.Join(", ", Generics.Select(g => g.GetName())) + ">");
            }
            hover.EndCodeLine();

            if (Description != null)
            {
                hover.NewSection().Add(Description);
            }
            parseInfo.Script.AddHover(callRange, hover);
        }
Beispiel #26
0
    public List <String> GetRandom(int userid, int num_imgs)
    {
        List <String> im_list = new List <String>();

        var jdata = GetMedia(userid);

        if (jdata.Length > 0)
        {
            int max_results = Math.Min(num_imgs, jdata.Length);
            for (int i = 0; i < max_results; i++)
            {
                MarkupBuilder mb       = new MarkupBuilder();
                string        im_str   = mb.GetMarkup("Instagram");
                var           latestig = jdata[i];
                string        im       = string.Format(im_str, latestig["link"], latestig["images"]["standard_resolution"]["url"], latestig["caption"]["text"]);

                im_list.Add(im);
            }
        }
        return(im_list.OrderBy(x => Guid.NewGuid()).ToList());
    }
Beispiel #27
0
        public override void Call(ScriptFile script, DocRange callRange)
        {
            MarkupBuilder hoverContents = new MarkupBuilder();

            if (Constant() == TypeSettable.Convertable)
            {
                hoverContents
                .StartCodeLine()
                .Add("enum " + Name)
                .EndCodeLine();
            }
            else if (Constant() == TypeSettable.Constant)
            {
                hoverContents
                .StartCodeLine()
                .Add("constant " + Name)
                .EndCodeLine()
                .NewSection()
                .Add("Constant workshop types cannot be stored. Variables with this type cannot be changed from their initial value.");
            }

            script.AddHover(callRange, hoverContents.ToString());
        }
Beispiel #28
0
 public bool TryGetMember(MarkupBuilder builder, GetMemberBinder binder, out object result)
 {
     result = null;
     return false;
 }
Beispiel #29
0
 public HoverRange(DocRange range, MarkupBuilder content)
 {
     Range   = range;
     Content = content;
 }
Beispiel #30
0
 public string Render(MarkupBuilder markupBuilder)
 {
     return MarkupRenderer.Render(markupBuilder);
 }
 private static MarkupBuilder AddHookInfo(MarkupBuilder markupBuilder) => markupBuilder.NewLine().Add("This is a hook variable, meaning it can only be set at the rule-level.");
Beispiel #32
0
 public CodeParameter(string name, MarkupBuilder documentation, ICodeTypeSolver type)
 {
     Name          = name;
     _type         = type;
     Documentation = documentation;
 }