示例#1
0
        public static async Task Run(SocketMessage message, string[] arg, string msg)
        {
            if (arg.Count() > 2)
            {
                int id = 0;
                RextesterHelper.languages.TryGetValue(arg[1].ToLower(), out id);
                if (id != 0)
                {
                    RextesterResponse result = await RextesterHelper.runCodeAsync(msg.Substring(5 + arg[1].Length), id);

                    if (result.Result != "" && result.Result != null)
                    {
                        if (result.Result.Length > 1994)
                        {
                            result.Result = $"{result.Result.Substring(0, 1991)}...";
                        }
                        await message.Channel.SendMessageAsync($"```{result.Result}```");
                    }
                    await message.Channel.SendMessageAsync("", false, genCodeResult(result, message.Author));
                }
                else
                {
                    await message.Channel.SendMessageAsync($":no_entry: `Unknown language: {arg[1]}`");
                }
            }
            else if (arg.Count() > 1 && arg[1].ToUpper() == "LIST")
            {
                await message.Channel.SendMessageAsync("", false, genLangList());
            }
            else
            {
                await message.Channel.SendMessageAsync($":no_entry: `Please include language name and code`");
            }
        }
示例#2
0
        public static async Task <RextesterResponse> runCodeAsync(string prog, int language)
        {
            string cargs = "";

            compiler_args.TryGetValue(language, out cargs);

            var values = new Dictionary <string, string>
            {
                { "LanguageChoiceWrapper", language.ToString() }, // 1 C#, 5 Python
                { "EditorChoiceWrapper", "1" },
                { "LayoutChoiceWrapper", "1" },
                { "Program", prog },
                { "ShowWarnings", "false" },
                { "IsInEditMode", "false" },
                { "IsLive", "false" },
                { "CompilerArgs", cargs },
                { "Input", "" }
            };

            HttpClient client = new HttpClient();

            client.Timeout = new TimeSpan(0, 0, 10);

            var content = new FormUrlEncodedContent(values);

            try
            {
                var httpresponse = await(await client.PostAsync("http://rextester.com/rundotnet/Run", content)).Content.ReadAsStringAsync();
                return(JsonConvert.DeserializeObject <RextesterResponse>(httpresponse));
            }
            catch
            {
                RextesterResponse response = new RextesterResponse();
                response.Errors = "Code ran longer than 10 seconds !";
                response.Stats  = "";
                response.Result = "";
                return(response);
            }
        }
示例#3
0
        static Embed genCodeResult(RextesterResponse result, SocketUser author)
        {
            EmbedBuilder em = new EmbedBuilder();

            em.Color = Color.Blue;
            EmbedAuthorBuilder eab = new EmbedAuthorBuilder();

            eab.Name    = $"{author.Username}#{author.Discriminator}'s Code Result";
            eab.IconUrl = author.GetAvatarUrl();
            em.Author   = eab;
            if (result.Errors != null)
            {
                em.AddField("Errors:", $"```{result.Errors}```");
            }
            if (result.Warnings != null)
            {
                em.AddField("Warnings:", $"```{result.Warnings}```");
            }
            if (result.Stats != "")
            {
                em.AddField("Stats:", result.Stats);
            }
            return(em.Build());
        }