Exemple #1
0
        public static async Task <BiliUser> GetCurrentUserInfoAsync()
        {
            var sESSDATA = ApplicationData.Current.LocalSettings.Values["biliUserSESSDATA"] as string;

            if (sESSDATA == null)
            {
                return(null);
            }

            var cookies = new List <(string, string)>()
            {
                ("SESSDATA", sESSDATA)
            };
            var json = JsonConvert.DeserializeObject <SelfInfoJson>(await NetHelper.HttpGet("http://api.bilibili.com/x/space/myinfo", cookies, null));
            var user = new BiliUser();

            //var file = await ApplicationData.Current.LocalCacheFolder.CreateFileAsync("avatar", CreationCollisionOption.ReplaceExisting);
            //var imgStream = await NetHelper.HttpGetStreamAsync(json.data.face, null, null);
            //var fileStream = await file.OpenStreamForWriteAsync();
            //await imgStream.CopyToAsync(fileStream);
            //imgStream.Close();
            //fileStream.Close();
            //var imgSource = new BitmapImage();
            //await imgSource.SetSourceAsync((await file.OpenStreamForReadAsync()).AsRandomAccessStream());
            var imgSource = new BitmapImage(new Uri(json.data.face));

            user.Uid       = json.data.mid;
            user.Name      = json.data.name;
            user.AvatarUrl = json.data.face;
            user.AvatarImg = imgSource;
            user.VipStatus = (VipStatus)json.data.vip.status;

            return(user);
        }
Exemple #2
0
        public static void checkCrewGroup()
        {
            Dictionary <int, long> l     = DataBase.me.listCrewBound();
            List <long>            g     = DataBase.me.getCrewGroup();
            List <long>            crews = new List <long>();
            string msg = "";

            foreach (long gg in g)
            {
                IGroupMemberInfo[] gpmemberlist = session.GetGroupMemberListAsync(gg).Result;
                foreach (IGroupMemberInfo ginfo in gpmemberlist)
                {
                    crews.Add(ginfo.Id);
                }
            }
            foreach (KeyValuePair <int, long> kvp in l)
            {
                if (!crews.Contains(kvp.Value))
                {
                    BiliUser u = new BiliUser(kvp.Key, biliapi);
                    msg += "Bili:" + u.name + " => QQ:" + kvp.Value + "\n";
                }
            }
            MainHolder.broadcaster.BroadcastToAdminGroup("[舰长群维护]\n以下舰长已绑定QQ但是还没有进入舰长群:\n" + msg);
        }
Exemple #3
0
        public PrivMessage(JToken json, ThirdPartAPIs sess)
        {
            recieiver_id = json.Value <int>("receiver_id");
            timestamp    = json.Value <int>("timestamp");
            talker       = BiliUser.getUser(json.Value <int>("sender_uid"), sess);
            msgtype      = json.Value <int>("msg_type");
            msg_seqno    = json.Value <int>("msg_seqno");
            msg_key      = json.Value <long>("msg_key");
            object jobjdes = JsonConvert.DeserializeObject(json.Value <string>("content"));

            try
            {
                if (jobjdes.GetType() != json.GetType())
                {
                    content = jobjdes.ToString();
                }
                else
                {
                    content_json = (JObject)jobjdes;
                    content      = content_json.Value <string>("content");
                }
            }
            catch
            {
                content = jobjdes.ToString();
            }
        }
Exemple #4
0
        public static int GetUserMainSiteLevel(JObject json)
        {
            var uid  = GetUserUID(json);
            var user = BiliUser.getUser(uid, MainHolder.biliapi);

            return(user.level);
        }
Exemple #5
0
        private async Task InitUserAsync()
        {
            InitializingProgressRing.IsActive = true;
            _user = await BiliUserManager.GetBiliUserAsync(Settings.SESSDATA);

            try
            {
                AvatarImage.Source = new BitmapImage(new Uri(_user.AvatarUrl));
            }
            catch (Exception ex)
            {
                _logger.Info(ex, ex.Message);
            }
            UserNameTextBlock.Text            = _user.Name;
            InitializingProgressRing.IsActive = false;
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Version currentOSVer = Environment.OSVersion.Version;

            log.Debug($"OS Version: {currentOSVer}");
            if (currentOSVer >= new Version(10, 0))
            {
                Task.Delay(50).ContinueWith(_ =>
                {
                    this.Dispatcher.Invoke(() => {
                        EnableBlurWin10();
                    });
                });
            }
            else if (currentOSVer == new Version(6, 1))
            {
                Task.Delay(200).ContinueWith(_ =>
                {
                    this.Dispatcher.Invoke(() => {
                        EnableBlurWin7();
                    });
                });
                log.Warn("Win7放弃支持毛玻璃,即使有毛玻璃会有几道光,且会根据主题颜色变色,赶紧升级Win10吧!");
            }
            else
            {
                isSupportBlur   = false;
                this.Background = new SolidColorBrush(Color.FromArgb(255, 250, 250, 250));
                log.Warn("还没用Win10啊,不能感受毛玻璃效果了,赶紧升级吧!");
            }

            BiliApiHelper.access_key = Properties.Settings.Default.access_key;

            bool isTryLogin = true;

            if (!string.IsNullOrEmpty(BiliApiHelper.access_key))
            {
                log.Info("已通过配置文件读取到授权码");
                log.Debug("授权码:" + BiliApiHelper.access_key);
            }
            else
            {
                log.Warn("没有获取到授权码,里区将对你躲♂藏");
                isTryLogin = false;
            }

            Task.Run(async() =>
            {
                if (isTryLogin)
                {
                    BiliUser bu      = new BiliUser();
                    UserInfoModel um = await bu.GetMyUserInfo();
                    if (um.uname != null)
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            log.Info("授权码有效,登录账户名:" + um.uname);
                            UserInfoName.Content  = um.uname;
                            UserInfoAvatar.Source = new BitmapImage(new Uri(um.face));

                            UserInfoOther.Text = $"{um.RankStr} LV{um.level_info.current_level} 硬币:{um.coins}";
                        });
                    }
                    else
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            log.Warn("授权码已经失效");
                            UserInfoName.Content = "授权码已经失效!";
                        });
                    }
                }

                if (!Directory.Exists(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\pic\"))
                {
                    log.Info("未检测到封面存放目录,正在创建\\pic");
                    Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\pic\");
                }

                if (!Directory.Exists(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\video\"))
                {
                    log.Info("未检测到视频存放目录,正在创建\\video");
                    Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\video\");
                }
            });

            Updater up = new Updater();

            up.CheckUpdate();
            textBlockTitle.Text = $"BiliRanking V{up.Version} - 不 止 统 计";
        }
        /// <summary>
        /// 单个客户端的消息循环。该方法通常不应被外部调用
        /// 警告:该方法阻塞当前线程。
        /// </summary>
        /// <param name="msg_sock"></param>
        public void _thread_message_process(Socket msg_sock)
        {
            try
            {
                int    type = 0;
                string name = "UNKNOW";
                //Dictionary<long, GroupMemberInfo> infos = new Dictionary<long, GroupMemberInfo>();
                Dictionary <long, string> qqname_index  = new Dictionary <long, string>();
                Dictionary <long, string> qqgname_index = new Dictionary <long, string>();
                List <int> uid_tobebound = new List <int>();
                MainHolder.Logger.Warning("RMTAPI", "新连接");
                //MainHolder.broadcaster.broadcastToAdminGroup("<DEBUG>[第三方连结API]\n一个新的节点试图连接,开启子MessageLoop");
                while (serverthread_flag)
                {
                    //客户端连接服务器成功后,服务器接收客户端发送的消息
                    byte[] buffer = new byte[1024];
                    //实际接收到的有效字节数
                    int len = msg_sock.Receive(buffer, buffer.Length, SocketFlags.None);
                    if (len == 0)
                    {
                        continue;
                    }
                    string   str = Encoding.UTF8.GetString(buffer, 0, len);
                    string[] st  = str.Split('^');
                    if (st.Length < 2)
                    {
                        continue;
                    }

                    if (type == 0)
                    {
                        switch (st[0])
                        {
                        case "M":
                            MainHolder.broadcaster.BroadcastToAdminGroup(str.Substring(2));
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "A":
                            MainHolder.broadcaster.BroadcastToAllGroup(str.Substring(2));
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "D":
                            if (MainHolder.useBiliRecFuncs)
                            {
                                MainHolder.bilidmkproc.blr.sendDanmaku(str.Substring(2));
                            }
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "E":
                            MainHolder.broadcaster.SendToAnEgg(str.Substring(2));
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "INIT":
                            name = str.Substring(5);
                            //MainHolder.broadcaster.broadcastToAdminGroup("[第三方连结API]\n一个节点通过了Challenge,已对其开放消息广播API\n应用名称:" + name);
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "CREWE":
                            type = 1;
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^MODE_SWITCHED_1"));
                            break;

                        case "DANMAKU":
                            type = 2;
                            mode2socklist.Add(msg_sock);
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^MODE_SWITCHED_2#_MODE_JSON"));
                            break;

                        default:
                            MainHolder.broadcaster.BroadcastToAdminGroup("[第三方连结API]\n接收到不能被识别的远程消息:\n" + str);
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^UNKNOW_MESSAGE_TYPE"));
                            break;
                        }
                    }
                    else if (type == 1)//舰长群UID绑定模式
                    {
                        switch (st[0])
                        {
                        case "I":
                            if (qqname_index.Count < 1 || qqgname_index.Count < 1)
                            {    //初始化舰长群数据
                                qqname_index.Clear();
                                qqgname_index.Clear();
                                Dictionary <int, long> l = DataBase.me.listCrewBound();
                                List <long>            g = DataBase.me.getCrewGroup();
                                foreach (long gg in g)
                                {
                                    IGroupMemberInfo[] members = MainHolder.session.GetGroupMemberListAsync(gg).Result;    //抓群成员
                                    foreach (IGroupMemberInfo ginfo in members)
                                    {
                                        if (!DataBase.me.isUserBoundedUID(ginfo.Id))
                                        {
                                            qqname_index.Add(ginfo.Id, ginfo.Name);
                                            qqgname_index.Add(ginfo.Id, ginfo.Name);
                                        }
                                    }
                                }
                            }
                            if (uid_tobebound.Count < 1)
                            {
                                uid_tobebound = DataBase.me.listCrewunBoundUID();
                            }
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "N":    //下一个需操作的用户
                        {
                            foreach (int uid in uid_tobebound)
                            {
                                BiliUser biuser = new BiliUser(uid, MainHolder.biliapi);
                                msg_sock.Send(Encoding.UTF8.GetBytes("BINFO^" + uid + "^SOF@" + biuser.name + "^EOF@"));
                                uid_tobebound.Remove(uid);
                                break;
                            }
                        }
                        break;

                        case "S":    //QQ名片和名中关键字查找
                        {
                            Dictionary <long, string> hits = new Dictionary <long, string>();
                            foreach (KeyValuePair <long, string> item in qqname_index)
                            {
                                if (item.Value.IndexOf(st[1]) > -1 && !hits.ContainsKey(item.Key))
                                {
                                    hits.Add(item.Key, item.Value);
                                }
                            }
                            foreach (KeyValuePair <long, string> item in qqgname_index)
                            {
                                if (item.Value.IndexOf(st[1]) > -1 && !hits.ContainsKey(item.Key))
                                {
                                    hits.Add(item.Key, item.Value);
                                }
                            }
                            msg_sock.Send(Encoding.UTF8.GetBytes("KEEPALIVE^SOF@"));
                            foreach (KeyValuePair <long, string> item in hits)
                            {
                                len = msg_sock.Receive(buffer, buffer.Length, SocketFlags.None);
                                string rpl = Encoding.UTF8.GetString(buffer, 0, len);        //等待询问
                                if (rpl == "?")
                                {
                                    msg_sock.Send(Encoding.UTF8.GetBytes(item.Key + "^" + item.Value));
                                }
                                else
                                {
                                    break;
                                }
                            }
                            Encoding.UTF8.GetString(buffer, 0, len);        //等待询问
                            msg_sock.Send(Encoding.UTF8.GetBytes("KEEPALIVE^EOF@"));
                        }
                        break;

                        case "B":    //UID和QQ绑定
                            if (DataBase.me.boundBiliWithQQ(long.Parse(st[1]), long.Parse(st[2])))
                            {
                                BiliUser biuser = new BiliUser(int.Parse(st[1]), MainHolder.biliapi);
                                MainHolder.broadcaster.SendToQQ(long.Parse(st[2]), "管理员手动将您的QQ号与B站账号\"" + biuser.name + "\"绑定。如有错误,请联系管理解决。");
                                msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            }
                            else
                            {
                                msg_sock.Send(Encoding.UTF8.GetBytes("ERROR^FAIL"));
                            }

                            break;

                        case "Q":    //退出模式1
                            type = -1;
                            msg_sock.Send(Encoding.UTF8.GetBytes("CMD^RECONN"));
                            msg_sock.Close();
                            break;

                        default:
                            MainHolder.broadcaster.BroadcastToAdminGroup("[第三方连结API]\n(type=1)接收到不能被识别的远程消息:\n" + str);
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^UNKNOW_MESSAGE_TYPE"));
                            break;
                        }
                    }
                    else if (type == 2)
                    {
                        switch (st[0])
                        {
                        case "BAN":
                            MainHolder.bilidmkproc.blr.manage.banUID(int.Parse(st[1]), int.Parse(st[2]));
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "DEBAN":
                            MainHolder.bilidmkproc.blr.manage.debanBID(int.Parse(st[1]));
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;

                        case "SEND":
                            if (MainHolder.useBiliRecFuncs)
                            {
                                MainHolder.bilidmkproc.blr.sendDanmaku(st[1]);
                            }
                            msg_sock.Send(Encoding.UTF8.GetBytes("REPLY^OK"));
                            break;
                        }
                    }
                }
                MainHolder.broadcaster.BroadcastToAdminGroup("<DEBUG>[第三方连结API]\n\"" + name + "\"对应的一个子MessageLoop结束");
            }
            catch (Exception err)
            {
                MainHolder.Logger.Warning("RMTAPI", "连接点(ConnectPoint)服务的一个消息循环异常结束");
                MainHolder.Logger.Warning("RMTAPI", err.Message + err.StackTrace);
            }
        }