Beispiel #1
0
        public void HandleMessage(string command, string args, object clientData, Action <string, AnswerBehaviourType> sendMessageFunc)
        {
            HtmlReaderManager hrm = new HtmlReaderManager();

            hrm.Post("http://online-generators.ru/ajax.php", "processor=quotes");
            var    answerParts = hrm.Html.Split(new string[] { "##" }, StringSplitOptions.RemoveEmptyEntries);
            string quote       = answerParts[0];
            string author      = answerParts[1];

            sendMessageFunc(string.Format("{0} ©{1}", quote, author), AnswerBehaviourType.Text);
        }
Beispiel #2
0
        public void HandleMessage(string command, string args, object clientData, Action <string, AnswerBehaviourType> sendMessageFunc)
        {
            if (args.StartsWith("help"))
            {
                sendMessageFunc(GetHelpText(), AnswerBehaviourType.Text);
            }
            else
            {
                string templateCode = @"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{{
    public class Program
    {{
        public static void Main(string[] args)
        {{
            {0}
        }}
        public static void Out(object obj){{
            Console.WriteLine(obj);
        }}
    }}
}}";

                HtmlReaderManager hrm = new HtmlReaderManager();

                hrm.Post("http://rextester.com/rundotnet/Run", string.Format("LanguageChoiceWrapper=1&EditorChoiceWrapper=1&Program={0}&Input=&ShowWarnings=false&Title=&SavedOutput=&WholeError=&WholeWarning=&StatsToSave=&CodeGuid=&IsInEditMode=False&IsLive=False"
                                                                             , HttpUtility.UrlEncode(string.Format(templateCode, args))));
                var    response = JsonConvert.DeserializeObject <dynamic>(hrm.Html);
                string toReturn = response.Result.ToString();

                if (string.IsNullOrEmpty(toReturn))
                {
                    toReturn = response.Errors.ToString();
                }

                if (!string.IsNullOrEmpty(toReturn))
                {
                    toReturn = toReturn.Replace(Environment.NewLine, " ").Trim();
                    sendMessageFunc(toReturn.Length > 200 ? toReturn.Substring(0, 50) + "..." : toReturn, AnswerBehaviourType.Text);
                }
            }
        }