示例#1
0
        private int[] GetPending()
        {
            Authenticator.Singleton.CheckLogin();

            string res = "";

            try
            {
                string body = CreateGetPendingRequestBody();
                res = _webClient.UploadString(_config.TaskFetchUrl, body);
            }
            catch
            {
                return(new int[0]);
            }

            string[]   split   = Regex.Split(res, "\r\n|\r|\n");
            List <int> sidList = new List <int>();

            foreach (string s in split)
            {
                if (int.TryParse(s, out int sid))
                {
                    sidList.Add(sid);
                }
            }

            return(sidList.ToArray());
        }
示例#2
0
        private void Login()
        {
            string requestBody = $"user_id={_config.JudgerName}&password={_config.Password}";

            _httpClient.UploadString(_loginUrl, requestBody, 3);

            if (CheckLogin())
            {
                return;
            }

            throw new AdapterException("Maybe no http_judge privilege!\n" +
                                       "Please check your judger username, password and privilege!");
        }
示例#3
0
        public JudgeTask[] Fetch()
        {
            string resultString = _httpClient.UploadString(_config.TaskFetchUrl, CreateRequestBody(), 3);

            JudgeTask[] tasks = ParseTask(resultString);
            return(tasks);
        }
示例#4
0
        public bool Login()
        {
            if (CheckLogin())
            {
                return(true);
            }

            string body = string.Format("user_id={0}&password={1}", _config.JudgerName, _config.Password);

            try
            {
                string res = _webClient.UploadString(loginUrl, body, 3);
            }
            catch { }

            return(CheckLogin());
        }
示例#5
0
        private bool Login()
        {
            if (CheckLogin())
            {
                return(true);
            }

            string requestBody = $"user_id={Config.JudgerName}&password={Config.Password}";

            try
            {
                _httpClient.UploadString(_loginUrl, requestBody, 3);
            }
            catch
            { }

            return(CheckLogin());
        }
示例#6
0
        /// <summary>
        /// 登录HUSTOJ
        /// </summary>
        public bool Login()
        {
            if (CheckLogin())
            {
                return(true);
            }

            string requestBody = string.Format("user_id={0}&password={1}", Config.JudgerName, Config.Password);

            try
            {
                _httpClient.UploadString(loginUrl, requestBody, 3);
            }
            catch
            { }

            return(CheckLogin());
        }
示例#7
0
        public bool Submit(JudgeResult result)
        {
            using (HttpWebClient client = ConfiguredClient.Create())
            {
                client.DefaultContentType = "application/json";

                client.UploadString(_config.ResultSubmitUrl, GetDataForSubmit(result), 3);
            }
            return(true);
        }
示例#8
0
        private string[] GetTestDataList(int pid)
        {
            string body = "gettestdatalist=1&pid=" + pid;
            string res  = _webClient.UploadString(_config.TaskFetchUrl, body, 3);

            string[] split = Regex.Split(res, "\r\n|\r|\n");

            List <string> dataList = new List <string>();

            foreach (string s in split)
            {
                if (!string.IsNullOrEmpty(s))
                {
                    dataList.Add(s);
                }
            }

            return(dataList.ToArray());
        }
示例#9
0
        private void Login()
        {
            string        requestBody = $"username={_config.JudgerName}&password={_config.Password}";
            string        jsonResp    = _httpClient.UploadString(_loginUrl, requestBody, 3);
            ServerMessage message     = Json.DeSerialize <ServerMessage>(jsonResp);

            if (!message.IsSuccess)
            {
                LogManager.Error("Login failed, please check password!");
            }
        }
示例#10
0
 public static string SendRequest(string url, string data)
 {
     HttpWebClient http = new HttpWebClient
     {
         ContentType = "application/json",
         Accept = "*/*",
         KeepAlive = true,
         Method = "POST",
         Encoding = Encoding.UTF8,
         UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36",
         TimeOut = 10000
     };
     return http.UploadString(url, data.ToString());
 }
示例#11
0
        public bool Submit(JudgeResult result)
        {
            try
            {
                using (HttpWebClient client = ConfiguredClient.Create())
                {
                    client.CookieContainer = Authenticator.Singleton.CookieContainer;

                    client.UploadString(_config.ResultSubmitUrl, GetDataForSubmit(result), 3);
                    return(true);
                }
            }
            catch { }

            return(false);
        }
示例#12
0
        public bool Login()
        {
            string requestBody = string.Format("username={0}&password={1}", _config.JudgerName, _config.Password);

            try
            {
                string result = _webClient.UploadString(loginUrl, requestBody, 3);

                ServerMessage message = SampleJsonSerializaer.DeSerialize <ServerMessage>(result);
                return(message.IsSuccessful);
            }
            catch
            {
                return(false);
            }
        }
示例#13
0
        private bool Login()
        {
            string requestBody = $"username={Config.JudgerName}&password={Config.Password}";

            try
            {
                string response = _httpClient.UploadString(_loginUrl, requestBody, 3);

                ServerMessageEntity message = Json.DeSerialize <ServerMessageEntity>(response);
                return(message.IsSuccess);
            }
            catch
            {
                return(false);
            }
        }
示例#14
0
        /// <summary>
        /// SauceNao调用
        /// </summary>
        /// <param name="cqcode">图片CQ码</param>
        /// <param name="e"></param>
        public static void SauceNao_Call(CQCode cqcode, CQGroupMessageEventArgs e)
        {
            string url = "https://saucenao.com/search.php?output_type=2&api_key=56faa0cddf50860330a295e0c331be7c4b4c021f&db=999&numres=3&url=";

            url += CommonHelper.GetImageURL(cqcode.ToSendString());
            using (HttpWebClient http = new HttpWebClient()
            {
                TimeOut = 10000,
                Encoding = Encoding.UTF8,
                Proxy = MainSave.Proxy,
                AllowAutoRedirect = true,
            })
            {
                try
                {
                    Directory.CreateDirectory(MainSave.ImageDirectory + "SauceNaotemp");
                    var result = JsonConvert.DeserializeObject <SauceNao_Result.SauceNAO>(http.DownloadString(url));
                    if (result == null || result.results == null || result.results.Count == 0)
                    {
                        e.CQLog.Info("SauceNao识图", "拉取结果失败,建议重试");
                        e.FromGroup.SendGroupMessage("诶嘿,网络出了点小差~");
                        return;
                    }
                    e.CQLog.Info("SauceNao识图", "结果获取成功,正在拉取缩略图");
                    int count = 1;
                    result.results = result.results.Take(1).ToList();
                    string str = result.ToString();
                    foreach (var item in result.results)
                    {
                        try
                        {
                            string filename = Guid.NewGuid().ToString().ToString();
                            http.DownloadFile(item.header.thumbnail, $@"{MainSave.ImageDirectory}\SauceNaotemp\{filename}.jpg");
                            str = str.Replace($"{{{count}}}", CQApi.CQCode_Image($@"\SauceNaotemp\{filename}.jpg").ToSendString());
                        }
                        catch
                        {
                            str = str.Replace($"{{{count}}}", item.header.thumbnail);
                        }
                        finally { count++; }
                    }
                    e.FromGroup.SendGroupMessage(str);
                    List <int> ls = result.results.Where(x => x.data.pixiv_id.HasValue).Select(x => x.data.pixiv_id.Value).ToList();
                    if (ls.Count != 0)
                    {
                        e.FromGroup.SendGroupMessage("有Pixiv图片信息,尝试拉取原图...");
                        foreach (var item in ls)
                        {
                            try
                            {
                                http.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                                if (!File.Exists($@"{MainSave.ImageDirectory}\LoliconPic\${item}.jpg"))
                                {
                                    dynamic jObject   = JObject.Parse(http.UploadString("https://api.pixiv.cat/v1/generate", $"p={item}"));
                                    string  pixiv_url = string.Empty;
                                    try
                                    {
                                        var urllist = jObject.original_urls_proxy;
                                        pixiv_url = urllist[0];
                                        e.FromGroup.SendGroupMessage("此图为多P图片,选择第一P下载");
                                        MainSave.CQLog.Info("SauceNao识图", "此图为多P图片,选择第一P下载");
                                    }
                                    catch
                                    {
                                        pixiv_url = jObject.Value <string>("original_url_proxy");
                                    }
                                    if (!Directory.Exists($@"{MainSave.ImageDirectory}\LoliconPic"))
                                    {
                                        Directory.CreateDirectory($@"{MainSave.ImageDirectory}\LoliconPic");
                                    }
                                    http.DownloadFile(pixiv_url, $@"{MainSave.ImageDirectory}\LoliconPic\{item}.jpg");
                                    MainSave.CQLog.Info("SauceNao识图", $"pid={item}的图片下载成功,尝试发送");
                                }
                                QQMessage staues = e.FromGroup.SendGroupMessage(CQApi.CQCode_Image($@"\LoliconPic\{item}.jpg"));
                            }
                            catch (Exception exc)
                            {
                                e.FromGroup.SendGroupMessage($"pid={item}的图片拉取失败,错误信息:{exc.Message}");
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    e.CQLog.Info("SauceNao搜图", $"搜索失败,错误信息:{exc.Message}在{exc.StackTrace}");
                    e.FromGroup.SendGroupMessage($"拉取失败,错误信息:{exc.Message}");
                }
                try
                {
                    string path = $@"{MainSave.ImageDirectory}\SauceNaotemp";
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }
                }
                catch { }
            }
        }