From 2b7bb2e873851b23a63eec031a17f1a96a0e0474 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 15 Feb 2023 22:55:00 +0800 Subject: [PATCH 01/44] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=BB=99?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=82=B9=E8=B5=9E=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Helper/WebService.cs | 44 ++++++++++++++++- src/MaaWpfGui/Main/CopilotViewModel.cs | 51 ++++++++++++++++++-- src/MaaWpfGui/Main/VersionUpdateViewModel.cs | 4 +- 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/src/MaaWpfGui/Helper/WebService.cs b/src/MaaWpfGui/Helper/WebService.cs index 32afaf5244..d5db55f31a 100644 --- a/src/MaaWpfGui/Helper/WebService.cs +++ b/src/MaaWpfGui/Helper/WebService.cs @@ -31,7 +31,7 @@ namespace MaaWpfGui.Helper public static string Proxy { get; set; } = ViewStatusStorage.Get("VersionUpdate.Proxy", string.Empty); - public static string RequestUrl(string url) + public static string RequestGet(string url) { try { @@ -63,6 +63,46 @@ namespace MaaWpfGui.Helper } } + public static string RequestPost(string url, string body) + { + try + { + HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); + httpWebRequest.Method = "POST"; + httpWebRequest.UserAgent = RequestUserAgent; + httpWebRequest.Accept = "application/vnd.github.v3+json"; + if (!string.IsNullOrWhiteSpace(Proxy)) + { + httpWebRequest.Proxy = new WebProxy(Proxy); + } + + var bytes = Encoding.UTF8.GetBytes(body); + httpWebRequest.ContentType = "application/json"; + httpWebRequest.ContentLength = bytes.Length; + using (var requestStream = httpWebRequest.GetRequestStream()) + { + requestStream.Write(bytes, 0, bytes.Length); + } + + var httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse; + if (httpWebResponse.StatusCode != HttpStatusCode.OK) + { + return null; + } + + var streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8); + var responseContent = streamReader.ReadToEnd(); + streamReader.Close(); + httpWebResponse.Close(); + return responseContent; + } + catch (Exception e) + { + Logger.Error(e.ToString(), MethodBase.GetCurrentMethod().Name); + return null; + } + } + private const string CacheDir = "cache/gui/"; private const string MaaApi = "https://ota.maa.plus/MaaAssistantArknights/api/"; @@ -76,7 +116,7 @@ namespace MaaWpfGui.Helper var url = MaaApi + api; - var response = RequestUrl(url); + var response = RequestGet(url); if (response == null) { return LoadApiCache(api); diff --git a/src/MaaWpfGui/Main/CopilotViewModel.cs b/src/MaaWpfGui/Main/CopilotViewModel.cs index a879c6b45b..50a1aca7d8 100644 --- a/src/MaaWpfGui/Main/CopilotViewModel.cs +++ b/src/MaaWpfGui/Main/CopilotViewModel.cs @@ -18,10 +18,13 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Net; +using System.Reflection; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using System.Windows.Interop; +using MaaWpfGui.Helper; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Stylet; @@ -163,18 +166,19 @@ namespace MaaWpfGui } _isDataFromWeb = false; + _copilotId = 0; } else if (filename.ToLower().StartsWith(CopilotIdPrefix)) { var copilotIdStr = filename.ToLower().Remove(0, CopilotIdPrefix.Length); - int.TryParse(copilotIdStr, out int copilotID); - jsonStr = RequestCopilotServer(copilotID); + int.TryParse(copilotIdStr, out _copilotId); + jsonStr = RequestCopilotServer(_copilotId); _isDataFromWeb = true; } else if (int.TryParse(filename, out _)) { - int.TryParse(filename, out int copilotID); - jsonStr = RequestCopilotServer(copilotID); + int.TryParse(filename, out _copilotId); + jsonStr = RequestCopilotServer(_copilotId); _isDataFromWeb = true; } else @@ -221,6 +225,7 @@ namespace MaaWpfGui } private bool _isDataFromWeb = false; + private int _copilotId = 0; private const string TempCopilotFile = "resource/_temp_copilot.json"; private string TaskType = "General"; @@ -496,6 +501,44 @@ namespace MaaWpfGui Idle = true; } + private readonly string _copilotRatingUrl = "https://prts.maa.plus/copilot/rating"; + + public bool CouldLikeWebJson() + { + // TODO: 还要加个限制,如果点过赞了就不让再点了 + return _isDataFromWeb && _copilotId != 0; + } + + public void LikeWebJson() + { + if (!CouldLikeWebJson()) + { + return; + } + + string jsonParam = JsonConvert.SerializeObject(new + { + id = _copilotId, + rating = "Like", + }); + WebService.RequestPost(_copilotRatingUrl, jsonParam); + } + + public void DislikeWebJson() + { + if (!CouldLikeWebJson()) + { + return; + } + + string jsonParam = JsonConvert.SerializeObject(new + { + id = _copilotId, + rating = "Dislike", + }); + WebService.RequestPost(_copilotRatingUrl, jsonParam); + } + private const string CopilotUiUrl = "https://www.prts.plus/"; private string _url = CopilotUiUrl; diff --git a/src/MaaWpfGui/Main/VersionUpdateViewModel.cs b/src/MaaWpfGui/Main/VersionUpdateViewModel.cs index 412a453c10..bdb54d4292 100644 --- a/src/MaaWpfGui/Main/VersionUpdateViewModel.cs +++ b/src/MaaWpfGui/Main/VersionUpdateViewModel.cs @@ -646,7 +646,7 @@ namespace MaaWpfGui { for (var i = 0; i < requestSource.Length; i++) { - response = WebService.RequestUrl(requestSource[i] + url); + response = WebService.RequestGet(requestSource[i] + url); if (!string.IsNullOrEmpty(response)) { break; @@ -974,4 +974,4 @@ namespace MaaWpfGui Process.Start(e.Parameter.ToString()); } } -} +} \ No newline at end of file From 477bf479fdf1ea379bae1c63923d9586dc92b371 Mon Sep 17 00:00:00 2001 From: uye <2396806385@qq.com> Date: Thu, 16 Feb 2023 03:52:45 +0800 Subject: [PATCH 02/44] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B5=9E/?= =?UTF-8?q?=E8=B8=A9=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Main/CopilotViewModel.cs | 40 +++++++---- src/MaaWpfGui/Main/VersionUpdateViewModel.cs | 2 +- src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 2 +- src/MaaWpfGui/Res/Localizations/zh-tw.xaml | 2 +- src/MaaWpfGui/Views/CopilotView.xaml | 71 +++++++++++++------- 5 files changed, 77 insertions(+), 40 deletions(-) diff --git a/src/MaaWpfGui/Main/CopilotViewModel.cs b/src/MaaWpfGui/Main/CopilotViewModel.cs index 50a1aca7d8..31315668e7 100644 --- a/src/MaaWpfGui/Main/CopilotViewModel.cs +++ b/src/MaaWpfGui/Main/CopilotViewModel.cs @@ -165,21 +165,23 @@ namespace MaaWpfGui return; } - _isDataFromWeb = false; - _copilotId = 0; + IsDataFromWeb = false; + CopilotId = 0; } else if (filename.ToLower().StartsWith(CopilotIdPrefix)) { var copilotIdStr = filename.ToLower().Remove(0, CopilotIdPrefix.Length); - int.TryParse(copilotIdStr, out _copilotId); - jsonStr = RequestCopilotServer(_copilotId); - _isDataFromWeb = true; + int.TryParse(copilotIdStr, out var numberStyles); + CopilotId = numberStyles; + jsonStr = RequestCopilotServer(CopilotId); + IsDataFromWeb = true; } else if (int.TryParse(filename, out _)) { - int.TryParse(filename, out _copilotId); - jsonStr = RequestCopilotServer(_copilotId); - _isDataFromWeb = true; + int.TryParse(filename, out var numberStyles); + CopilotId = numberStyles; + jsonStr = RequestCopilotServer(CopilotId); + IsDataFromWeb = true; } else { @@ -350,7 +352,7 @@ namespace MaaWpfGui TaskType = "Copilot"; } - if (_isDataFromWeb) + if (IsDataFromWeb) { File.Delete(TempCopilotFile); File.WriteAllText(TempCopilotFile, json.ToString()); @@ -475,7 +477,7 @@ namespace MaaWpfGui AddLog(errMsg, UILogColor.Error); } - bool ret = _asstProxy.AsstStartCopilot(_isDataFromWeb ? TempCopilotFile : Filename, Form, TaskType, + bool ret = _asstProxy.AsstStartCopilot(IsDataFromWeb ? TempCopilotFile : Filename, Form, TaskType, Loop ? LoopTimes : 1); if (ret) { @@ -506,7 +508,19 @@ namespace MaaWpfGui public bool CouldLikeWebJson() { // TODO: 还要加个限制,如果点过赞了就不让再点了 - return _isDataFromWeb && _copilotId != 0; + return IsDataFromWeb && CopilotId != 0; + } + + public bool IsDataFromWeb + { + get => _isDataFromWeb; + set => SetAndNotify(ref _isDataFromWeb, value); + } + + public int CopilotId + { + get => _copilotId; + set => SetAndNotify(ref _copilotId, value); } public void LikeWebJson() @@ -518,7 +532,7 @@ namespace MaaWpfGui string jsonParam = JsonConvert.SerializeObject(new { - id = _copilotId, + id = CopilotId, rating = "Like", }); WebService.RequestPost(_copilotRatingUrl, jsonParam); @@ -533,7 +547,7 @@ namespace MaaWpfGui string jsonParam = JsonConvert.SerializeObject(new { - id = _copilotId, + id = CopilotId, rating = "Dislike", }); WebService.RequestPost(_copilotRatingUrl, jsonParam); diff --git a/src/MaaWpfGui/Main/VersionUpdateViewModel.cs b/src/MaaWpfGui/Main/VersionUpdateViewModel.cs index bdb54d4292..6ce5dd662d 100644 --- a/src/MaaWpfGui/Main/VersionUpdateViewModel.cs +++ b/src/MaaWpfGui/Main/VersionUpdateViewModel.cs @@ -974,4 +974,4 @@ namespace MaaWpfGui Process.Start(e.Parameter.ToString()); } } -} \ No newline at end of file +} diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index e2a1168b5e..71b9a38abc 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -104,7 +104,7 @@ 繁荣证章 建造点数 锻造赤金 - + 不选择 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index f7f1afdc4f..05269740a0 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -311,7 +311,7 @@ 選擇作業 作業檔可以直接用滑鼠拖進來喔 (o゚v゚)ノ 自動編隊 - LoopTimes + 迴圈次數 自動編隊暫時無法辨識“特別關注”的幹員 開始 diff --git a/src/MaaWpfGui/Views/CopilotView.xaml b/src/MaaWpfGui/Views/CopilotView.xaml index a44f341726..3e2f785dbc 100644 --- a/src/MaaWpfGui/Views/CopilotView.xaml +++ b/src/MaaWpfGui/Views/CopilotView.xaml @@ -11,7 +11,7 @@ xmlns:s="https://github.com/canton7/Stylet" xmlns:vm="clr-namespace:MaaWpfGui" d:DataContext="{d:DesignInstance {x:Type vm:CopilotViewModel}}" - d:DesignHeight="495" + d:DesignHeight="550" d:DesignWidth="800" AllowDrop="True" Drop="{s:Action DropFile}" @@ -99,28 +99,51 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + +