Example #1
0
 public void StreamStopped()
 {
     DataBase.me.recBLiveEnd(lid, new_commers, viewerlist.Count(), 0, selver_coins, gold_coins);
     MainHolder.broadcaster.BroadcastToAdminGroup("直播结束\n事件识别ID " + lid + "\n\n直播数据统计(系统在线期间) \n" +
                                                  "活跃观众  " + (ispickedup ? "-" : viewerlist.Count().ToString()) + "<+" + new_commers + ">\n" +
                                                  "金瓜子  " + gold_coins + "\n" +
                                                  "银瓜子  " + selver_coins);
     gold_coins   = 0;
     selver_coins = 0;
     new_commers  = 0;
     viewerlist.Clear();
     lid = -1;
     MainHolder.checkCrewGroup();
     ListTenMoreGradeUsers();
 }
Example #2
0
        public static void run()
        {
            foreach (BiliApi.BiliSpaceDynamic dyn in MainHolder.dynamics)
            {
                dyn.refresh();//先refresh一下,防止处理到存货
            }
            while (true)
            {
                foreach (BiliApi.BiliSpaceDynamic dyn in MainHolder.dynamics)
                {
                    try
                    {
                        List <Dyncard> d = new List <Dyncard>();
                        try
                        {
                            d = dyn.getLatest();
                        }
                        catch (Exception err)
                        {
                            MainHolder.DumpException(err, "DynChecker");
                            continue;
                        }
                        Thread.Sleep(0);
                        dyn.refresh(d);
                        foreach (Dyncard dc in d)
                        {
                            if ((DateTime.Now - dc.sendtime).TotalSeconds > 30)
                            {
                                continue;
                            }
                            bool atall = (DateTime.Now.Hour < 23 && DateTime.Now.Hour > 6);
                            atall &= !dc.dynamic.Contains("$Silent$");
                            switch (dc.type)
                            {
                            case 1:    //普通动态
                            case 2:    //包含图片的动态
                            case 4:    //?出现在转发和普通动态
                                if (isLivedanmakuAndBroadcast(dc))
                                {
                                    break;     //如果是转发的直播,分出去单独处理
                                }
                                MainHolder.broadcaster.BroadcastToAllGroup("[有新动态!]\nUP主:" + dc.sender.name + "\n" + dc.short_dynamic + "\nhttps://t.bilibili.com/" + dc.dynid, atall ? (IChatMessage) new AtAllMessage() : new PlainMessage("<@[免打扰模式]>"));
                                break;

                            case 256:    //音频
                                break;

                            case 8:    //视频
                                MainHolder.broadcaster.BroadcastToAllGroup("[有新视频!]\n" + dc.vinfo.title + "\nUP主:" + dc.sender.name + "\n" + dc.vinfo.short_discription + "\nhttps://www.bilibili.com/video/" + dc.vinfo.bvid + "\n", atall ? (IChatMessage) new AtAllMessage() : new PlainMessage("<@[免打扰模式]>"));
                                break;

                            case 4200:    //直播
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        MainHolder.broadcaster.BroadcastToAdminGroup("[Exception]\n这条消息可能意味着机器人发生了错误。它仍在继续运行,但可能不是很稳定。下面的信息用来帮助鸡蛋定位错误,管理不必在意。\n[B站动态部分]" + err.Message + "\n\n堆栈跟踪:\n" + err.StackTrace);
                    }
                }
                try
                {//检测鹿野粉丝数
                    if (MainHolder.enableNativeFuncs)
                    {
                        check_fans();
                    }
                }
                catch (Exception err)
                {
                    MainHolder.Logger.Warning("BiliDynChecker", "检查粉丝数时遇到错误:" + err.Message + " - " + err.StackTrace);
                }
                Thread.Sleep(15000);
            }
        }
Example #3
0
        public static void run()
        {
            int counter = 0;
            int lasterr = 0;

            while (true)
            {
                try
                {
                    counter++;
                    if (counter % 600 == 0)
                    {//5分钟一次
                        GC.Collect(5, GCCollectionMode.Optimized, true, true);
                        if (!MainHolder.bililogin.IsOnline())
                        {
                            MainHolder.broadcaster.BroadcastToAdminGroup("BiliWebToken似乎已经失效,将触发重新登录。\n");
                            MainHolder.doBiliLogin = true;
                        }
                    }
                    if (counter % 3600 == 0)
                    {//一小时执行一次
                        MainHolder.broadcaster.BroadcastToAdminGroup("[在线]\n" +
                                                                     "最近一条消息:" + lastrecv.ToString() + "\n" +
                                                                     "时段总接收消息:" + MainHolder.MsgCount + "\n" +
                                                                     "上次检查:" + laststat.ToString());
                        laststat            = DateTime.Now;
                        MainHolder.MsgCount = 0;
                    }
                    if (counter % 30 == 0)
                    {//每半分钟一次
                        if (MainHolder.bilidmkproc?.lid <= 0)
                        {
                            MainHolder.bilidmkproc?.PickupRunningLive();
                        }
                    }
                    if (counter % (60 * 60 * 12) == 0)
                    {//12小时一次
                        MainHolder.checkCrewGroup();
                    }
                    if ((counter + (60 * 60 * 6)) % (60 * 60 * 12) == 0)
                    {//12小时一次,错位+6小时      帮小伙伴续费黑名单>_<
                     //trigger_BanRefresh();
                    }
                    if (counter >= (60 * 60 * 24))
                    {
                        counter = 0;//以一天为循环体
                    }
                    WatchDog.FeedDog("sckt");
                    MainHolder.bilidmkproc?.UpdateLiveDataToDB();//每秒都更新数据库
                }
                catch (Exception err)
                {
                    if ((counter - lasterr) < (60 * 60))
                    {
                        continue;
                    }

                    MainHolder.broadcaster.BroadcastToAdminGroup("[计划任务失败]\n计划任务未能顺利完成(每小时仅报错一次防止持续错误刷屏)\n" + err.Message + "\nStack:" + err.StackTrace);
                }
                Thread.Sleep(1000);
            }
        }
Example #4
0
 public Broadcaster()
 {
     MainHolder.refreshFriendsList();
 }
Example #5
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);
        }
Example #6
0
 public static void Info(string cato, string msg)
 {
     MainHolder.logger(cato, msg);
 }
Example #7
0
 public static void Debug(string cato, string msg)
 {
     MainHolder.logger(cato, msg, System.ConsoleColor.Black, System.ConsoleColor.Gray);
 }
Example #8
0
 public static void Warning(string cato, string msg)
 {
     MainHolder.logger(cato, msg, System.ConsoleColor.DarkYellow);
 }
Example #9
0
 public static void Error(string cato, string msg)
 {
     MainHolder.logger(cato, msg, System.ConsoleColor.DarkRed);
 }
Example #10
0
 private void Sm_ExceptionHappened(object sender, Exception e, string desc = "")
 {
     MainHolder.logger("弹幕连接", desc + " - " + e.StackTrace);
 }
Example #11
0
 private void Sm_LogOutput(object sender, string text)
 {
     MainHolder.logger("弹幕连接", text);
 }