Beispiel #1
0
 public BiliVideo(string vid, ThirdPartAPIs sess)
 {
     this.sess    = sess;
     this.vid     = vid;
     participants = new List <BiliUser>();
     fetchVideoInfo();
 }
        public static short getLiveStatus(int roomid)
        {
            string  data = ThirdPartAPIs._get("https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + roomid);
            JObject json = (JObject)JsonConvert.DeserializeObject(data);

            return(json["data"]["room_info"].Value <short>("live_status"));
        }
Beispiel #3
0
        public static BiliUser getUser(int uid, ThirdPartAPIs sess)
        {
            if (userlist.ContainsKey(uid))
            {
                return(userlist[uid]);
            }

            return(new BiliUser(uid, sess));
        }
        public BiliLiveRoom(int roomid, IAuthBase auth)
        {
            this.sess = new ThirdPartAPIs(auth.GetLoginCookies());
            string  data = ThirdPartAPIs._get("https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + roomid);
            JObject json = (JObject)JsonConvert.DeserializeObject(data);

            roomid      = json["data"]["room_info"].Value <int>("room_id");
            shortid     = json["data"]["room_info"].Value <int>("short_id");
            title       = json["data"]["room_info"].Value <string>("title");
            cover       = json["data"]["room_info"].Value <string>("cover");
            tags        = json["data"]["room_info"].Value <string>("tags").Split(',');
            keyframe    = json["data"]["room_info"].Value <string>("keyframe");
            status      = json["data"]["room_info"].Value <short>("live_status");
            lid         = json["data"]["room_info"].Value <int>("live_start_time");
            this.roomid = roomid;
            manage      = new LiveManagement(this);
            //keyframe
        }
Beispiel #5
0
        /// <summary>
        /// 从UID创建数据
        /// <para>系统会自己去抓数据</para>
        /// </summary>
        /// <param name="uid"></param>
        public BiliUser(int uid, ThirdPartAPIs sess, bool nocache = false)
        {
            if (userlist == null)
            {
                userlist = new Dictionary <int, BiliUser>();
            }
            try
            {
                this.sess  = sess;
                raw_json   = (JObject)JsonConvert.DeserializeObject(sess.getBiliUserInfoJson(uid));
                this.uid   = int.Parse(raw_json["data"]["mid"].ToString());
                name       = raw_json["data"]["name"].ToString();
                sex        = raw_json["data"]["sex"].ToString();
                sign       = raw_json["data"]["sign"].ToString();
                rank       = int.Parse(raw_json["data"]["rank"].ToString());
                level      = int.Parse(raw_json["data"]["level"].ToString());
                coins      = int.Parse(raw_json["data"]["coins"].ToString());
                face       = raw_json["data"]["face"].ToString();
                fans_badge = raw_json["data"]["fans_badge"].ToString() != "false";
                try
                {
                    official = new OfficialInfo()
                    {
                        Type        = (OfficialType)raw_json["data"]["official"].Value <int>("type"),
                        Title       = raw_json["data"]["official"].Value <string>("title"),
                        Description = raw_json["data"]["official"].Value <string>("desc"),
                        Role        = raw_json["data"]["official"].Value <int>("role")
                    };
                }
                catch { }
            }
            catch
            {
                this.uid = uid;
            }
            if (userlist.ContainsKey(uid))
            {
                userlist.Remove(uid);
            }

            userlist.Add(uid, this);
        }
Beispiel #6
0
 /// <summary>
 /// 手动数据初始化
 /// 尽量别用!!
 /// </summary>
 /// <param name="uid"></param>
 /// <param name="name"></param>
 /// <param name="sex"></param>
 /// <param name="sign"></param>
 /// <param name="fans_badge"></param>
 /// <param name="coins"></param>
 /// <param name="face"></param>
 /// <param name="level"></param>
 /// <param name="rank"></param>
 public BiliUser(int uid, string name, string sex, string sign, bool fans_badge, int coins, string face, int level, int rank, OfficialInfo official, ThirdPartAPIs sess)
 {
     if (userlist == null)
     {
         userlist = new Dictionary <int, BiliUser>();
     }
     this.uid        = uid;
     this.name       = name;
     this.sex        = sex;
     this.sign       = sign;
     this.fans_badge = fans_badge;
     this.coins      = coins;
     this.face       = face;
     this.level      = level;
     this.rank       = rank;
     this.official   = official;
     if (userlist.ContainsKey(uid))
     {
         userlist.Remove(uid);
     }
     this.sess = sess;
     userlist.Add(uid, this);
 }
 public BiliSpaceDynamic(int uid, IAuthBase auth)
 {
     this.sess = new ThirdPartAPIs(auth.GetLoginCookies());
     this.uid  = uid;
 }
 public BiliSpaceDynamic(int uid, ThirdPartAPIs sess)
 {
     this.sess = sess;
     this.uid  = uid;
 }
Beispiel #9
0
 public LiveManagement(BiliLiveRoom blr)
 {
     this.blr  = blr;
     this.sess = blr.sess;
 }
Beispiel #10
0
        public static void INIT(JObject config)
        {
            Directory.CreateDirectory("saves");
            while (true)
            {
                try
                {
                    ConnectionPool.initConnections(
                        config["sql"].Value <string>("server"), config["sql"].Value <string>("user"), config["sql"].Value <string>("passwd"),
                        config["minecraft"].Value <string>("server"), config["minecraft"].Value <string>("user"), config["minecraft"].Value <string>("passwd")
                        );
                    MainHolder.Logger.Info("SideLoad", "DBConnectiong pool is UP.");
                    break;
                }
                catch (Exception e)
                {
                    MainHolder.logger("SideLoad", "FATAL - DBConnectiong FAILED.", ConsoleColor.Black, ConsoleColor.Red);
                    MainHolder.logger("Database", e.Message, ConsoleColor.Black, ConsoleColor.Yellow);
                    MainHolder.logger("Database", e.StackTrace, ConsoleColor.Black, ConsoleColor.Yellow);
                }
            }

            //更新成员列表
            pool.submitWorkload(new pThreadPool.workload(() =>
            {
                MainHolder.logger("Database", "Updating member info...");
                var glist = DataBase.me.listGroup();
                foreach (var g in glist)
                {
                    MainHolder.logger("Database", "Updating members for " + g);
                    DataBase.me.update_groupmembers(g);
                }
                MainHolder.logger("Database", "Updating member info Done");
            }));

            /*
             * //QQ登录
             * pool.submitWorkload(new pThreadPool.workload(() =>
             * {
             *  qqlogin = new QLogin.QLogin();
             *  doQQLogin = true;
             *  while (true)
             *  {
             *      while (!doQQLogin) Thread.Sleep(500);
             *      if (File.Exists("saves/qq_login_info.json"))
             *      {
             *          MainHolder.logger("QQLowlevelApi", "Found save.json, loading...");
             *          var j = File.ReadAllText("saves/qq_login_info.json");
             *          qqlogin.DeSerilize(j);
             *          if (ThirdPartAPIs.getQQLevel(1250542735, istrying: true) > 5)
             *          {
             *              MainHolder.logger("QQLowlevelApi", "Done.");
             *          }
             *      }
             *      MainHolder.logger("QQLowlevelApi", "Trying to loging...");
             *      var qrcode = qqlogin.getQR();
             *      MemoryStream ms = new MemoryStream();
             *      qrcode.Save(ms, ImageFormat.Png);
             *      ms.Seek(0, SeekOrigin.Begin);
             *      var msg = MainHolder.session.UploadPictureAsync(UploadTarget.Group, ms).Result;
             *      broadcaster.BroadcastToAdminGroup(new IChatMessage[] {
             *              (IChatMessage)msg,
             *              new PlainMessage("等级查询模块需要扫描二维码授权")
             *              });
             *      var result = qqlogin.Login();
             *      switch (result)
             *      {
             *          case QLogin.QLogin.QLoginStatus.Online:
             *              broadcaster.BroadcastToAdminGroup("二维码授权成功");
             *              MainHolder.logger("QQLowlevelApi", "Done");
             *              if (File.Exists("saves/qq_login_info.json")) File.Delete("saves/qq_login_info.json");
             *              var js = qqlogin.Serilize();
             *              File.WriteAllText("saves/qq_login_info.json", js);
             *              break;
             *          case QLogin.QLogin.QLoginStatus.Offline:
             *              broadcaster.BroadcastToAdminGroup("授权失败:OFFLINE");
             *              MainHolder.logger("QQLowlevelApi", "OFFLINE");
             *              break;
             *          case QLogin.QLogin.QLoginStatus.QRExpired:
             *              broadcaster.BroadcastToAdminGroup("授权失败:QRCODE_EXPIRED");
             *              MainHolder.logger("QQLowlevelApi", "QRCODE_EXPIRED");
             *              break;
             *          case QLogin.QLogin.QLoginStatus.Failed:
             *              broadcaster.BroadcastToAdminGroup("授权失败:FAILED");
             *              MainHolder.logger("QQLowlevelApi", "FAILED");
             *              break;
             *      }
             *      doQQLogin = false;
             *  }
             * }));
             */
            //B站登录、加载相关模块
            pool.submitWorkload(new pThreadPool.workload(() =>
            {
                while (true)
                {
                    try
                    {
                        while (!doBiliLogin)
                        {
                            Thread.Sleep(500);
                        }
                        while (true)
                        {
                            if (File.Exists("saves/bili_login_info.json"))
                            {
                                bililogin = null;
                                try
                                {
                                    var js = File.ReadAllText("saves/bili_login_info.json");
                                    logger("Bililogin", "Records read.");
                                    bililogin = new QRLogin(js);
                                    if (bililogin.LoggedIn)
                                    {
                                        logger("Bililogin", "已使用预先保存的状态登录");
                                        broadcaster.BroadcastToAdminGroup("已从存档恢复相关数据并获取必要的授权,将释放被挂起的模块。");
                                        break;
                                    }
                                    else
                                    {
                                        logger("Bililogin", "保存的登录状态不可用");
                                    }
                                }
                                catch (Exception err)
                                {
                                    logger("Bililogin", "未能从bililogin.bin中恢复保存的登录状态:" + err.Message);
                                    logger("Bililogin", err.StackTrace);
                                }
                            }
                            bililogin = new BiliApi.Auth.QRLogin();
                            broadcaster.BroadcastToAdminGroup(new IChatMessage[] {
                                new ImageMessage(null, "https://api.pwmqr.com/qrcode/create/?url=" + HttpUtility.UrlEncode(bililogin.QRToken.ScanUrl), null),
                                new PlainMessage("Token=" + bililogin.QRToken.OAuthKey + "\n部分模块依赖B站账号访问权,已挂起。授权完成后将释放它们。")
                            });
                            bililogin.Login();
                            broadcaster.BroadcastToAdminGroup("已获取必要的授权,将释放被挂起的模块。");
                            if (File.Exists("saves/bili_login_info.json"))
                            {
                                File.Delete("saves/bili_login_info.json");
                            }
                            try
                            {
                                var js = bililogin.Serilize();
                                File.WriteAllText("saves/bili_login_info.json", js);
                            }
                            catch (Exception err)
                            {
                                broadcaster.BroadcastToAdminGroup("BiliApi.NET返回了一处错误:" + err.Message + "\n 该错误不致命,将忽略该错误并继续执行剩余操作。");
                            }
                            break;
                        }
                        biliapi = new BiliApi.ThirdPartAPIs(bililogin.Cookies);
                        break;
                    }
                    catch (Exception err)
                    {
                        broadcaster.BroadcastToAdminGroup("BiliApi.NET返回了一处错误:" + err.Message + "\n输入#lb再次尝试登录");
                        doBiliLogin = false;
                        Thread.Sleep(1000);
                    }
                }
                //B站登录完成,加载相关模块
                try
                {
                    BiliUser.userlist = new Dictionary <int, BiliUser>();
                    dynamics          = new List <BiliSpaceDynamic>();
                    string str        = "";
                    foreach (Cookie c in bililogin.Cookies)
                    {
                        str += c.Name + "=" + c.Value + ";";
                    }
                    bilidmkproc = new BiliDanmakuProcessor(2064239, str);
                    bilidmkproc.Init_connection();
                    MainHolder.logger("SideLoad", "BLive-DMKReceiver is UP.", ConsoleColor.Black, ConsoleColor.White);
                }
                catch (Exception)
                {
                    MainHolder.logger("SideLoad", "BLive-DMKReceiver FAILED.", ConsoleColor.Black, ConsoleColor.Red);
                }
                try
                {
                    if (MainHolder.useBiliRecFuncs)
                    {
                        PrivmessageChecker.startthreads();
                        MainHolder.logger("SideLoad", "BiliPrivMessageReceiver is UP.", ConsoleColor.Black, ConsoleColor.White);
                    }
                    else
                    {
                        MainHolder.logger("SideLoad", "BiliPrivMessageReceiver is DISABLED.", ConsoleColor.Black, ConsoleColor.White);
                    }
                }
                catch (Exception)
                {
                    MainHolder.logger("SideLoad", "BiliPrivMessageReceiver FAILED.", ConsoleColor.Black, ConsoleColor.Red);
                }
                try
                {
                    /*
                     * AdminJScriptHandler.JsEngine.SetValue("BiliAPI", biliapi);
                     * AdminJScriptHandler.JsEngine.SetValue("StreamMonitor", bilidmkproc.lr.sm);
                     * AdminJScriptHandler.JsEngine.SetValue("LiveRoom", bilidmkproc.blr);
                     * AdminJScriptHandler.JsEngine.SetValue("DataBase", DataBase.me);
                     * AdminJScriptHandler.JsEngine.SetValue("MCDataBase", DBHandler.me);
                     */
                }
                catch
                {
                    //不处理错误
                }
                //return;
                try
                {
                    DynChecker.startthreads();
                    MainHolder.logger("SideLoad", "DynChecker is UP.", ConsoleColor.Black, ConsoleColor.White);
                }
                catch (Exception)
                {
                    MainHolder.logger("SideLoad", "DynChecker FAILED.", ConsoleColor.Black, ConsoleColor.Red);
                }
            }));

            try
            {
                AdminJScriptHandler.InitEngine();
                UserJScriptHandler.InitEngine();

                //AdminJScriptHandler.JsEngine.SetValue("biliready", false);

                MainHolder.logger("SideLoad", "JSEngine is UP.", ConsoleColor.Black, ConsoleColor.White);
            }
            catch (Exception)
            {
                MainHolder.logger("SideLoad", "JSEngine FAILED.", ConsoleColor.Black, ConsoleColor.Red);
            }

            try
            {
                broadcaster = new Broadcaster();
                MainHolder.logger("SideLoad", "Broadcaster is UP.", ConsoleColor.Black, ConsoleColor.White);
            }
            catch (Exception err)
            {
                throw;
                MainHolder.logger("SideLoad", "Broadcaster FAILED.", ConsoleColor.Black, ConsoleColor.Red);
            }
            doBiliLogin = true;
            try
            {
                tms = new TCPMessageServer(15510);
                tms.init_server_async();
                MainHolder.logger("SideLoad", "Connection-Point service is UP.", ConsoleColor.Black, ConsoleColor.White);
            }
            catch (Exception)
            {
                MainHolder.logger("SideLoad", "Connection-Point service FAILED.", ConsoleColor.Black, ConsoleColor.Red);
            }

            try
            {
                SecondlyTask.startthreads();
                MainHolder.logger("SideLoad", "ScheduledTask-Manager is UP.", ConsoleColor.Black, ConsoleColor.White);
            }
            catch (Exception)
            {
                MainHolder.logger("SideLoad", "FATAL ScheduledTask-Manager FAILED.", ConsoleColor.Black, ConsoleColor.Red);
            }

            try
            {
                /*
                 * han.host.threadpool.submitWorkload(() =>
                 * {
                 *  while (true)
                 *  {
                 *      try
                 *      {
                 *          broadcaster.processQueueMsgSend();
                 *      }
                 *      catch
                 *      {
                 *          logger.Warning("msgsendqueue_FATAL", "消息发送环路出现严重错误,已忽略本次发送");
                 *      }
                 *  }
                 * });
                 */
                MainHolder.logger("SideLoad", "Broadcaster-SenderLoop is NOLONGER HOSTED.", ConsoleColor.Black, ConsoleColor.Yellow);
            }
            catch (Exception)
            {
                MainHolder.logger("SideLoad", "Broadcaster-SenderLoop FAILED.", ConsoleColor.Black, ConsoleColor.Red);
            }

            //MCServerChecker.startthreads();
            MainHolder.logger("SideLoad", "MCServer checker is DISABLED.", ConsoleColor.Black, ConsoleColor.Red);
        }