Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Commit 239b0e2

Browse files
author
Awbugl
committed
Update Code
1 parent dd75fe7 commit 239b0e2

File tree

5 files changed

+195
-12
lines changed

5 files changed

+195
-12
lines changed

Andreal.Window/Common/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6-
using System.Windows;
6+
using System.Windows.Forms;
77
using System.Windows.Threading;
88
using Andreal.Core.Common;
99
using Andreal.Core.Utils;
@@ -13,6 +13,8 @@
1313
using Konata.Core.Events.Model;
1414
using Konata.Core.Interfaces.Api;
1515
using Newtonsoft.Json;
16+
using Application = System.Windows.Application;
17+
using MessageBox = System.Windows.Forms.MessageBox;
1618
using Path = Andreal.Core.Common.Path;
1719

1820

@@ -108,7 +110,7 @@ private static string Translate(WtLoginEvent.Type type)
108110
WtLoginEvent.Type.VerifyDeviceLock => "需要设备锁验证",
109111
WtLoginEvent.Type.LoginDenied => "登录被其他设备拒绝",
110112
WtLoginEvent.Type.InvalidUinOrPassword => "QQ号或密码不正确",
111-
WtLoginEvent.Type.HighRiskEnvironment => "高风险环境,被TX禁止登录",
113+
WtLoginEvent.Type.HighRiskEnvironment => "高风险环境,被tx拒绝登录",
112114
WtLoginEvent.Type.InvalidSmsCode => "短信验证码不正确",
113115
WtLoginEvent.Type.TokenExpired => "快速登录Token已过期",
114116
_ => ""
@@ -235,7 +237,7 @@ private static async void OnGroupInvite(Bot b, GroupInviteEvent e)
235237
|| Config.Settings.GroupInviterWhitelist.Contains(e.InviterUin))
236238
await b.ApproveGroupInvitation(e.GroupUin, e.InviterUin, e.Token);
237239
}
238-
240+
239241
private static async void OnBotGroupMute(Bot b, GroupMuteMemberEvent e)
240242
{
241243
if (e.MemberUin == b.Uin) await b.GroupLeave(e.GroupUin);
@@ -256,7 +258,13 @@ private static void OnCaptcha(Bot b, CaptchaEvent e)
256258
case CaptchaEvent.CaptchaType.Slider:
257259
Application.Current.Dispatcher.Invoke(() =>
258260
{
259-
var window = new SliderVerify(b, e.SliderUrl);
261+
System.Windows.Window window
262+
= MessageBox.Show("是否使用Webview滑块验证?\n选择否将使用滑块验证助手",
263+
"需要滑块验证", MessageBoxButtons.YesNo)
264+
== DialogResult.Yes
265+
? new SliderVerify(b, e.SliderUrl)
266+
: new SliderSubmit(b, e.SliderUrl);
267+
260268
window.Show();
261269
});
262270
break;
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<Window x:Class="Andreal.Window.UI.SliderSubmit"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="LoginWindow"
5+
ResizeMode="NoResize"
6+
WindowStyle="None"
7+
Width="300" Height="300"
8+
WindowStartupLocation="CenterScreen"
9+
MouseLeftButtonDown="OnMouseLeftButtonDown" x:ClassModifier="internal">
10+
11+
<Window.Resources>
12+
<Style x:Key="SystemButtonBase" TargetType="ButtonBase">
13+
<Setter Property="Background" Value="Transparent" />
14+
<Setter Property="BorderThickness" Value="0" />
15+
<Setter Property="HorizontalContentAlignment" Value="Center" />
16+
<Setter Property="VerticalContentAlignment" Value="Center" />
17+
<Setter Property="Cursor" Value="Hand" />
18+
<Setter Property="Padding" Value="1" />
19+
<Setter Property="Template">
20+
<Setter.Value>
21+
<ControlTemplate TargetType="{x:Type ButtonBase}">
22+
<Border Name="Chrome"
23+
Background="{TemplateBinding Background}"
24+
BorderThickness="{TemplateBinding BorderThickness}"
25+
BorderBrush="{TemplateBinding BorderBrush}"
26+
SnapsToDevicePixels="true"
27+
CornerRadius="5">
28+
<ContentPresenter Margin="{TemplateBinding Padding}"
29+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
30+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
31+
RecognizesAccessKey="True"
32+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
33+
</Border>
34+
</ControlTemplate>
35+
</Setter.Value>
36+
</Setter>
37+
<Style.Triggers>
38+
<Trigger Property="IsEnabled" Value="false">
39+
<Setter Property="Cursor" Value="Arrow" />
40+
</Trigger>
41+
</Style.Triggers>
42+
</Style>
43+
<Style TargetType="Button" BasedOn="{StaticResource SystemButtonBase}" x:Key="BtnStyle">
44+
<Setter Property="Background" Value="#09a3dc" />
45+
<Setter Property="Foreground" Value="#ffffff" />
46+
<Setter Property="MinHeight" Value="28" />
47+
<Setter Property="MinWidth" Value="70" />
48+
<Style.Triggers>
49+
<Trigger Property="IsMouseOver" Value="True">
50+
<Setter Property="Background" Value="#3cc3f5" />
51+
</Trigger>
52+
<Trigger Property="IsPressed" Value="True">
53+
<Setter Property="Background" Value="#098cbc" />
54+
</Trigger>
55+
<Trigger Property="IsEnabled" Value="false">
56+
<Setter Property="Background" Value="#e1e1e1" />
57+
<Setter Property="Foreground" Value="#7e7e7e" />
58+
</Trigger>
59+
</Style.Triggers>
60+
</Style>
61+
</Window.Resources>
62+
63+
<Grid Background="#23262A" Width="{Binding Width, ElementName=w}" Height="{Binding Height, ElementName=w}">
64+
<Grid.RowDefinitions>
65+
<RowDefinition Height="100" />
66+
<RowDefinition Height="100" />
67+
<RowDefinition Height="100" />
68+
</Grid.RowDefinitions>
69+
<TextBlock Grid.Row="0" Foreground="DarkGray" IsHitTestVisible="False" HorizontalAlignment="Left"
70+
Margin="52,0,0,0"
71+
Text="验证码链接" VerticalAlignment="Center"
72+
FontFamily="Microsoft YaHei" FontSize="16"
73+
Background="#23262A">
74+
</TextBlock>
75+
<Button Grid.Row="0" Foreground="DarkGray" Background="#23262A" Margin="152,0,0,0" Height="30" Width="85"
76+
HorizontalAlignment="Left"
77+
Click="OnCopyButtonClick">
78+
<TextBlock TextWrapping="Wrap" FontFamily="Microsoft YaHei" Text="点击复制" FontSize="16" />
79+
</Button>
80+
<StackPanel Grid.Row="0" Orientation="Vertical" Height="45" VerticalAlignment="Center" Width="196"
81+
Margin="0,95,0,0">
82+
<TextBlock x:Name="UrlBlock" Foreground="DarkGray" IsHitTestVisible="False"
83+
HorizontalAlignment="Left" TextWrapping="Wrap" Text=""
84+
FontFamily="Microsoft YaHei" FontSize="10"
85+
Background="#23262A">
86+
</TextBlock>
87+
</StackPanel>
88+
<StackPanel Grid.Row="1" Orientation="Vertical" Height="100" Width="196"
89+
Margin="0,30,0,0">
90+
<TextBlock Foreground="DarkGray" IsHitTestVisible="False" HorizontalAlignment="Left"
91+
Text="滑块验证助手Ticket" VerticalAlignment="Top"
92+
FontFamily="Microsoft YaHei" FontSize="16"
93+
Background="#23262A">
94+
95+
</TextBlock>
96+
97+
<TextBox x:Name="CodeBox" Width="160" VerticalAlignment="Bottom"
98+
Margin="0,10,0,0"
99+
HorizontalAlignment="Right"
100+
BorderThickness="0,0,0,1" Foreground="DarkGray"
101+
InputMethod.IsInputMethodEnabled="False"
102+
103+
Height="30" FontSize="16" Background="#23262A" />
104+
</StackPanel>
105+
106+
<StackPanel Grid.Row="2" Orientation="Horizontal" Height="50" Width="196">
107+
<Button x:Name="SubmitBtn"
108+
Margin="0,-20,0,0"
109+
Height="30"
110+
Width="200"
111+
Style="{StaticResource BtnStyle}" Click="OnSubmit">
112+
<TextBlock TextWrapping="Wrap" Text="提交" FontSize="16" VerticalAlignment="Center" />
113+
</Button>
114+
</StackPanel>
115+
</Grid>
116+
</Window>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Windows;
2+
using System.Windows.Input;
3+
using Konata.Core;
4+
using Konata.Core.Interfaces.Api;
5+
6+
namespace Andreal.Window.UI;
7+
8+
internal partial class SliderSubmit
9+
{
10+
private readonly Bot _bot;
11+
12+
internal SliderSubmit(Bot bot, string sliderUrl)
13+
{
14+
InitializeComponent();
15+
_bot = bot;
16+
UrlBlock.Text = sliderUrl;
17+
}
18+
19+
private void OnSubmit(object sender, RoutedEventArgs e)
20+
{
21+
_bot.SubmitSliderTicket(CodeBox.Text);
22+
Close();
23+
}
24+
25+
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
26+
{
27+
try
28+
{
29+
DragMove();
30+
}
31+
catch
32+
{
33+
//ignored
34+
}
35+
}
36+
37+
private void OnCopyButtonClick(object sender, RoutedEventArgs e) { Clipboard.SetText(UrlBlock.Text); }
38+
}

Andreal.Window/UI/SliderVerify.xaml.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows.Input;
1+
using System.Windows.Forms;
2+
using System.Windows.Input;
23
using Konata.Core;
34
using Konata.Core.Interfaces.Api;
45
using Microsoft.Web.WebView2.Core.DevToolsProtocolExtension;
@@ -21,7 +22,6 @@ internal SliderVerify(Bot bot, string sliderUrl)
2122
_sliderUrl = sliderUrl;
2223
_bot = bot;
2324
InitializeComponent();
24-
WebBrowser.EnsureCoreWebView2Async();
2525
InitializeAsync();
2626
}
2727

@@ -32,8 +32,23 @@ private DevToolsProtocolHelper CdpHelper
3232

3333
private async void InitializeAsync()
3434
{
35-
await WebBrowser.EnsureCoreWebView2Async();
36-
await CdpHelper.Network.EnableAsync();
35+
try
36+
{
37+
await WebBrowser.EnsureCoreWebView2Async();
38+
await CdpHelper.Network.EnableAsync();
39+
}
40+
catch
41+
{
42+
if (MessageBox.Show("未找到Webview运行时!是否下载Webview安装包?(安装后请重启Andreal)\n选择否将使用滑块验证助手", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
43+
System.Diagnostics.Process.Start("https://go.microsoft.com/fwlink/p/?LinkId=2124703");
44+
else
45+
{
46+
var window = new SliderSubmit(_bot, _sliderUrl);
47+
window.Show();
48+
}
49+
Close();
50+
}
51+
3752
await
3853
CdpHelper.Network
3954
.SetUserAgentOverrideAsync("Mozilla/5.0 (Linux; Android 10; PCT-AL10 Build/HUAWEIPCT-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.72 MQQBrowser/6.2 TBS/046011 Mobile Safari/537.36 V1_AND_SQ_8.8.88_2770_YYB_D A_8088800 QQ/8.8.88.7830 NetType/WIFI WebP/0.3.0 Pixel/1080",
@@ -51,10 +66,12 @@ private async void InitializeAsync()
5166
CdpHelper.Network.LoadingFinished += async (_, args) =>
5267
{
5368
if (args.RequestId != _ticketId) return;
54-
69+
5570
_ticketId = args.RequestId;
56-
_ticket = JObject.Parse((await CdpHelper.Network.GetResponseBodyAsync(_ticketId))
57-
.Body)["ticket"]!.ToString();
71+
_ticket
72+
= JObject.Parse((await CdpHelper.Network
73+
.GetResponseBodyAsync(_ticketId))
74+
.Body)["ticket"]!.ToString();
5875

5976
_bot.SubmitSliderTicket(_ticket);
6077
Close();

Andreal.Window/UI/UserControl/Accounts.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@ private async void OnLoginAccountCommandExecute(object parameter)
6767

6868
private async void OnLogoutAccountCommandExecute(object parameter) { await _selectedobject?.Bot?.Logout()!; }
6969

70-
private async void OnDeleteAccountCommandExecute(object parameter) { await Program.OnRemove(_selectedobject!); }
70+
private async void OnDeleteAccountCommandExecute(object parameter)
71+
{
72+
await Program.OnRemove(_selectedobject!);
73+
_selectedobject = null;
74+
}
7175
}

0 commit comments

Comments
 (0)