示例#1
0
 public static async void Login(SoraMessage e)
 {
     await Task.Run(() => Library.Bilibili.Bilibili.QRCodeLoginRequest(
                        async(bitmap) =>
     {
         if (e.IsGroupMessage)
         {
             await e.ReplyToOriginal("登录任务已建立,请前往私聊等待登录二维码的发送");
         }
         else
         {
             await e.ReplyToOriginal("登录任务已建立,请等待登录二维码的发送");
         }
         var qr   = new MemoryImage(bitmap);
         var path = qr.ToBase64File();
         await e.SendPrivateMessage(CQCode.CQImage(path), "\n请使用Bilibili客户端扫码登录");
     },
                        async() => await e.SendPrivateMessage("检测到扫描事件,请在客户端中确认登录"),
                        async(cookie) =>
     {
         if (int.TryParse(cookie.Split(";").Where(x => x.StartsWith("DedeUserID=")).First()[11..], out var id))
         {
             await e.SendPrivateMessage("登录成功\n数据储存中……");
             var data = await Database.FindAsync <UserData>(x => x.QQ == e.Sender.Id || x.Bilibili == id);
             if (data != null)
             {
                 data.QQ             = e.Sender.Id;
                 data.Bilibili       = id;
                 data.BilibiliCookie = cookie;
                 await Database.UpdateAsync(data).ContinueWith(async x =>
                 {
                     if (x.Result > 0)
                     {
                         await e.SendPrivateMessage("记录数据已更新");
                     }
                     else if (x.IsFaulted && x.Exception != null)
                     {
                         await e.SendPrivateMessage(new StringBuilder()
                                                    .AppendLine("记录数据因异常导致更新失败,错误信息:")
                                                    .Append(ConsoleLog.ErrorLogBuilder(x.Exception))
                                                    .ToString());
                     }
                     else
                     {
                         await e.SendPrivateMessage("记录数据因未知原因导致更新失败,请稍后重试");
                     }
                 });
             }
             else
             {
                 data = new()
                 {
                     QQ             = e.Sender.Id,
                     Bilibili       = id,
                     BilibiliCookie = cookie
                 };
                 await Database.InsertAsync(data).ContinueWith(async x =>
                 {
                     if (x.Result > 0)
                     {
                         await e.SendPrivateMessage("记录数据已添加");
                     }
                     else if (x.IsFaulted && x.Exception != null)
                     {
                         await e.SendPrivateMessage(new StringBuilder()
                                                    .AppendLine("记录数据因异常导致更新失败,错误信息:")
                                                    .Append(ConsoleLog.ErrorLogBuilder(x.Exception))
                                                    .ToString());
                     }
                     else
                     {
                         await e.SendPrivateMessage("记录数据因未知原因导致更新失败,请稍后重试");
                     }
                 });
             }
         }