Example #1
0
        public async Task <BilibiliUserVm> GetUserName(string uname)
        {
            using (var client = new HttpClient())
            {
                var     url = $"https://api.bilibili.com/x/web-interface/search/type?context=&keyword={uname}&page=1&search_type=bili_user";
                JObject result;

                var r = await client.GetStringAsync(url);

                result = JsonConvert.DeserializeObject <JObject>(r);
                if (result["code"].ToString() != "0")
                {
                    throw new Exception($"接口请求出错:{result["message"]}");
                }

                if (result["data"]["result"] == null)
                {
                    return(null);
                }

                var user = result["data"]["result"].First;
                var res  = new BilibiliUserVm
                {
                    Uid      = user["mid"].Value <int>(),
                    UserName = user["uname"].Value <string>(),
                    Face     = "http:" + user["upic"].Value <string>(),
                };

                return(res);
            }
        }
Example #2
0
 private void UpdateUser(ref BilibiliUserVm user, BilibiliUserVm info)
 {
     user.Face        = info.Face;
     user.Guard_level = info.Guard_level;
     user.Is_alive    = info.Is_alive;
     user.UserName    = info.UserName;
 }
        private async Task SetOrder(BilibiliUserVm v, int newOrder)
        {
            if (v.QueueNo == newOrder)
            {
                return;
            }

            var max = App.MainWin.MainVm.Config.BilibiliUsers
                      .Where(m => m.IsInQueue)
                      .Count();

            var target = App.MainWin.MainVm.Config.BilibiliUsers
                         .Where(m => m.IsInQueue)
                         .Where(m => m.QueueNo == newOrder)
                         .FirstOrDefault();

            if (target == null)
            {
                return;
            }

            var listNo = new Queue <int>();
            var curent = 1;

            while (curent <= max)
            {
                if (curent == newOrder)
                {
                    curent++;
                    continue;
                }

                listNo.Enqueue(curent);
                curent++;
            }

            v.QueueNo = newOrder;

            foreach (var p in App.MainWin.MainVm.Config.BilibiliUsers
                     .Where(m => m.IsInQueue)
                     .Where(m => m.Uid != v.Uid)
                     .OrderBy(m => m.QueueNo))
            {
                p.QueueNo = listNo.Dequeue();
            }

            await App.MainWin.MainVm.UpdateSearchAsync();
        }
        private async Task AddOrRemove(BilibiliUserVm v)
        {
            if (v.IsInQueue)
            {
                // 本次是移出
                v.IsInQueue = false;
                int order = 1;
                foreach (var p in App.MainWin.MainVm.Config.BilibiliUsers.Where(m => m.IsInQueue).OrderBy(m => m.QueueNo))
                {
                    p.QueueNo = order++;
                }
            }
            else
            {
                // 本次是移入
                v.IsInQueue   = true;
                v.InQueueTime = DateTime.Now;
                v.QueueNo     = App.MainWin.MainVm.Config.BilibiliUsers.Where(m => m.IsInQueue).Count();
            }

            await App.MainWin.MainVm.UpdateSearchAsync();
        }