示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            GitHubPush.Start();
            RobotSocket.Start();

            while (true)
            {
                string data = Console.ReadLine();
                if (data == "stop")
                {
                    GitHubPush.Stop();
                }
            }
        }
示例#2
0
        private static void AcceptAsync(HttpListenerContext context)
        {
            try
            {
                HttpListenerRequest request = context.Request;
                switch (request.HttpMethod)
                {
                case "POST":
                {
                    Stream       stream  = context.Request.InputStream;
                    StreamReader reader  = new StreamReader(stream, Encoding.UTF8);
                    var          content = reader.ReadToEnd();
                    //HttpProcessor.HandlePOSTRequest(content, context.Request, context.Response);
                    context.Response.StatusCode = 200;
                    var data1 = Encoding.UTF8.GetBytes("OK");
                    context.Response.OutputStream.Write(data1, 0, data1.Length);
                    context.Response.OutputStream.Close();
                    Task.Run(() =>
                        {
                            var obj = JObject.Parse(content).ToObject <Git>();
                            if (obj.Ref == null)
                            {
                                return;
                            }
                            Logs.LogWrite("发现推送:" + obj.repository.html_url + "|" + obj.head_commit.id);
                            string message = "GitHub仓库更新了!\n";
                            message       += "仓库:" + obj.repository.html_url + "\n";
                            message       += "更新者:" + obj.pusher.name + "\n";
                            message       += "UUID:" + obj.head_commit.id + "\n";
                            message       += "消息:" + obj.head_commit.message + "\n";
                            message       += "时间:" + obj.head_commit.timestamp;
                            var data2      = GetString(obj.repository.html_url);
                            if (MainConfig.特殊推送.ContainsKey(data2))
                            {
                                var list = MainConfig.特殊推送[data2];
                                foreach (var item in list)
                                {
                                    RobotSocket.SendGroupMessage(item, message);
                                }
                            }
                            else
                            {
                                foreach (var item in MainConfig.推送群号)
                                {
                                    RobotSocket.SendGroupMessage(item, message);
                                }
                            }
                        });
                }
                break;

                case "GET":
                {
                    var data = request.QueryString;
                    //HttpProcessor.HandleGETRequest(data, context.Request, context.Response);
                    context.Response.StatusCode = 200;
                    var data1 = Encoding.UTF8.GetBytes("OK");
                    context.Response.OutputStream.Write(data1, 0, data1.Length);
                    context.Response.OutputStream.Close();
                }
                break;
                }
            }
            catch (Exception e)
            {
                Logs.LogError(e);
            }
        }