Skip to content

Commit

Permalink
feat(test/consoleapp/program.cs): 加提示, 提高用户体验
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Apr 23, 2022
1 parent e0bb3d9 commit d397016
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions test/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using System.Text.Json;
using static Konata.Core.Events.Model.CaptchaEvent;

Console.WriteLine("Hello, World!");
Console.WriteLine("QQBotHub ConsoleApp - QQ登录软件");


// Create a bot instance
Console.Write("QQ: ");
Console.Write("输入你的 QQ: ");
string uin = Console.ReadLine().Trim();
Console.Write("Password: ");
Console.Write("输入你的 QQ密码: ");
string password = Console.ReadLine();
var botKeystore = new BotKeyStore(uin: uin, password: password);

Expand All @@ -25,16 +25,30 @@
// Handle the captcha
bot.OnCaptcha += (bot, e) =>
{
bool isSuccess = false;
System.Console.WriteLine();
if (e.Type == CaptchaType.Slider)
{
Console.WriteLine("☆★☆★ 滑动验证");
Console.WriteLine("请复制下方链接在浏览器打开, 然后如 README.md 中所写获取 ticket, 然后在下方输入");
System.Console.WriteLine();
Console.WriteLine(e.SliderUrl);
bot.SubmitSliderTicket(Console.ReadLine());
System.Console.WriteLine();
Console.WriteLine("☆★☆★ 粘贴 ticket:");
isSuccess = bot.SubmitSliderTicket(Console.ReadLine()?.Trim() ?? "");
}
else if (e.Type == CaptchaType.Sms)
{
Console.WriteLine("☆★☆★ 短信验证");
System.Console.WriteLine();
Console.WriteLine(e.Phone);
bot.SubmitSmsCode(Console.ReadLine());
System.Console.WriteLine();
Console.WriteLine("☆★☆★ 输入接收到的验证码:");
isSuccess = bot.SubmitSmsCode(Console.ReadLine()?.Trim() ?? "");
}
System.Console.WriteLine();
Console.WriteLine($"验证 {(isSuccess ? "通过" : "失败, 请重新验证")}");
System.Console.WriteLine();
};

// Print the log
Expand All @@ -56,19 +70,20 @@
bot.OnFriendMessage += (_, e)
=> Console.WriteLine($"好友消息: {e.Message.Chain?.FirstOrDefault()?.ToString() ?? ""}");

//bot.OnLoginFailed

// ... More handlers
}

// Do login
if (!await bot.Login())
while (!await bot.Login())
{
Console.WriteLine("Login failed");
return;
Console.WriteLine("登录失败, 自动尝试重新登录并验证, 若为 QQ或密码错误, 请重新运行软件 以便 重新输入QQ及密码");
}

Console.WriteLine("We got online!");
Console.WriteLine("登录成功");

Console.WriteLine("下方是你的 BotKeyStore.json, 请将它复制好, 用于登录使用");
Console.WriteLine("不要复制 start 与 end 两行");
Console.WriteLine("-------------------------------start-------------------------------------");
string jsonStr = JsonSerializer.Serialize(bot.KeyStore,
new JsonSerializerOptions { WriteIndented = true });
Expand Down

0 comments on commit d397016

Please sign in to comment.