public void CallYoutubeComment(YoutubeLiveChatCallbackBody body)
 {
     InsertEventLog($"[{DateTimeExtensions.TimestampToDateTime(body.PublishTime).AddHours(8):yyyy-MM-dd HH:mm:ss}] Vtuber [{body.VtuberName}]  在 {body.LiveAuthorName} 的直播间发表了评论 {body.Message}");
     foreach (var vtuberBot in Bots)
     {
         var groups = vtuberBot.GetGroupsAsync().GetAwaiter().GetResult();
         if (groups == null)
         {
             continue;
         }
         foreach (var groupInfo in groups)
         {
             var config = Config.DefaultConfig.GroupConfigs.FirstOrDefault(v => v.GroupId == groupInfo.GroupId)
                          ?.PublishConfigs.FirstOrDefault(v => v.VtuberName == body.VtuberName);
             if (config == null || !config.YoutubeComment || LiveList.ContainsKey(body.VtuberName))
             {
                 continue;
             }
             try
             {
                 vtuberBot.GetSendingService().SendGroupMessageAsync(groupInfo.GroupId,
                                                                     $"Vtuber {body.VtuberName} 于 {DateTimeExtensions.TimestampToDateTime(body.PublishTime).AddHours(8):yyyy-MM-dd HH:mm:ss} 在 {body.LiveAuthorName} 的直播间发表了评论\r\n" +
                                                                     $"评论内容: {body.Message}\r\n" +
                                                                     $"直播地址: {body.LiveLink}")
                 .GetAwaiter().GetResult();
             }
             catch (Exception ex)
             {
                 LogHelper.Error("Cannot send message.", true, ex);
             }
         }
     }
 }
        public void CallYoutubeLiveUploaded(YoutubeLiveUploadedCallbackBody body)
        {
            var liveDetail = _liveInfoCollection.FindAsync(v => v.VideoId == body.VideoId).GetAwaiter().GetResult()
                             .FirstOrDefault();

            InsertEventLog($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] Vtuber [{body.VtuberName}] {liveDetail.Title} 的直播录像已上传完成, 下载链接: https://api.vtb.wiki/api/bot/record?file=" + body.FileHash);
            foreach (var vtuberBot in Bots)
            {
                var groups = vtuberBot.GetGroupsAsync().GetAwaiter().GetResult();
                if (groups == null || liveDetail == null)
                {
                    continue;
                }
                foreach (var groupInfo in groups)
                {
                    var config = Config.DefaultConfig.GroupConfigs.FirstOrDefault(v => v.GroupId == groupInfo.GroupId)
                                 ?.PublishConfigs.FirstOrDefault(v => v.VtuberName == body.VtuberName);
                    if (config == null || !config.YoutubeBeginLive || LiveList.ContainsKey(body.VtuberName))
                    {
                        continue;
                    }
                    try
                    {
                        vtuberBot.GetSendingService().SendGroupMessageAsync(groupInfo.GroupId,
                                                                            $"Vtuber {body.VtuberName} {liveDetail.Title} 的直播录像已上传完成, 总时长{(liveDetail.EndTime - liveDetail.BeginTime).TotalMinutes:F1}分钟\r\n下载链接: https://api.vtb.wiki/api/bot/record?file=" +
                                                                            body.FileHash)
                        .GetAwaiter().GetResult();
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error("Cannot send message.", true, ex);
                    }
                }
            }
        }
 public void CallYoutubeStopLive(YoutubeLiveCallbackBody body)
 {
     if (LiveList.ContainsKey(body.VtuberName))
     {
         LiveList.Remove(body.VtuberName);
         InsertEventLog($"[{DateTimeExtensions.TimestampToDateTime(body.ActualStartTime).AddHours(8):yyyy-MM-dd HH:mm:ss}] Vtuber [{body.VtuberName}] 停止直播");
         VtuberStopYoutubeLiveEvent?.Invoke(body);
     }
 }
Exemplo n.º 4
0
        //所有
        public static LiveList getAll(int page)
        {
            string text = getAllPage(page);

            LiveList liveList = JsonHelper.DeSerialize <LiveList>(text);

            InsertData(liveList);

            return(liveList);
        }
Exemplo n.º 5
0
        public static LiveList getAppId(string appid, int page)
        {
            string url = "https://share.egame.qq.com/cgi-bin/pgg_live_async_fcgi?param={\"key\":{\"module\":\"pgg_live_read_ifc_mt_svr\",\"method\":\"get_pc_live_list\",\"param\":{\"appid\":\"" + appid + "\",\"page_num\":" + page + ",\"page_size\":120,\"tag_id\":0,\"tag_id_str\":\"\"}}}&app_info={\"platform\":4,\"terminal_type\":2,\"egame_id\":\"egame_official\",\"imei\":\"\",\"version_code\":\"9.9.9.9\",\"version_name\":\"9.9.9.9\"}";

            string text = getWeb(url);

            LiveList liveList = JsonHelper.DeSerialize <LiveList>(text);

            InsertData(liveList);

            return(liveList);
        }
 public void CallYoutubeBeginLive(YoutubeLiveCallbackBody body)
 {
     if (!LiveList.ContainsKey(body.VtuberName))
     {
         LogHelper.Info($"Vtuber [{body.VtuberName}] 已开始直播 {body.LiveLink} ({body.LiveTitle}) -{DateTimeExtensions.TimestampToDateTime(body.ActualStartTime).AddHours(8):yyyy-MM-dd HH:mm:ss}");
         InsertEventLog($"[{DateTimeExtensions.TimestampToDateTime(body.ActualStartTime).AddHours(8):yyyy-MM-dd HH:mm:ss}] Vtuber [{body.VtuberName}] 开始直播 {body.LiveTitle} ({body.LiveLink})");
         if (DateTime.Now - DateTimeExtensions.TimestampToDateTime(body.ActualStartTime).AddHours(8) <
             TimeSpan.FromMinutes(10))
         {
             foreach (var vtuberBot in Bots)
             {
                 var groups = vtuberBot.GetGroupsAsync().GetAwaiter().GetResult();
                 if (groups == null)
                 {
                     continue;
                 }
                 foreach (var groupInfo in groups)
                 {
                     var config = Config.DefaultConfig.GroupConfigs.FirstOrDefault(v => v.GroupId == groupInfo.GroupId)
                                  ?.PublishConfigs.FirstOrDefault(v => v.VtuberName == body.VtuberName);
                     if (config == null || !config.YoutubeBeginLive || LiveList.ContainsKey(body.VtuberName))
                     {
                         continue;
                     }
                     try
                     {
                         vtuberBot.GetSendingService().SendGroupMessageAsync(groupInfo.GroupId,
                                                                             $"{body.VtuberName} 在 {DateTimeExtensions.TimestampToDateTime(body.ActualStartTime).AddHours(8):yyyy-MM-dd HH:mm:ss} 开始了直播 {body.LiveTitle}\r\n" +
                                                                             $"链接: {body.LiveLink}\r\n当前观众数量: {body.ViewersCount}\r\n" +
                                                                             $"原定开播时间: {DateTimeExtensions.TimestampToDateTime(body.ScheduledStartTime).AddHours(8):yyyy-MM-dd HH:mm:ss}\r\n" +
                                                                             $"实际开播时间: {DateTimeExtensions.TimestampToDateTime(body.ActualStartTime).AddHours(8):yyyy-MM-dd HH:mm:ss}")
                         .GetAwaiter().GetResult();
                     }
                     catch (Exception ex)
                     {
                         LogHelper.Error("Cannot send message.", true, ex);
                     }
                 }
             }
         }
         LiveList.Add(body.VtuberName, body.LiveLink);
         VtuberBeginYoutubeLiveEvent?.Invoke(body);
     }
 }
Exemplo n.º 7
0
        private static void InsertData(LiveList liveList)
        {
            var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            var db = new QueryFactory(connection, new MySqlCompiler());

            foreach (var item in liveList.data.key.retBody.data.live_data.live_list)
            {
                var query = db.Query("RankInfo").Insert(new
                {
                    UserId     = item.anchor_id,
                    UserNick   = item.anchor_name,
                    UserFans   = item.fans_count,
                    RoomOnline = item.online,
                    RoomTitle  = item.title,
                    AppName    = item.appname
                });
            }
        }
Exemplo n.º 8
0
        private static void InsertData(LiveList liveList)
        {
            //入库
            var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            var db = new QueryFactory(connection, new MySqlCompiler());

            foreach (var item in liveList.data.rl)
            {
                var query = db.Query("RankInfo").Insert(new
                {
                    UserId     = item.uid,
                    UserNick   = item.nn,
                    RoomId     = item.rid,
                    RoomOnline = item.ol,
                    RoomTitle  = item.rn,
                    AppName    = item.c2name,
                    Od         = item.od
                });
            }
        }
Exemplo n.º 9
0
        private static void RankTask()
        {
            //所有 3 页
            LiveList liveList = getAll(1);

            if (liveList.data.pgcnt >= 2)
            {
                getAll(2);
            }

            if (liveList.data.pgcnt >= 3)
            {
                getAll(3);
            }

            //颜值 2 页
            liveList = getYZ(1);

            if (liveList.data.pgcnt >= 2)
            {
                getYZ(2);
            }

            //舞蹈 2 页
            liveList = getWD(1);

            if (liveList.data.pgcnt >= 2)
            {
                getWD(2);
            }

            //二次元 2 页
            liveList = getECY(1);

            if (liveList.data.pgcnt >= 2)
            {
                liveList = getECY(2);
            }
        }
Exemplo n.º 10
0
        private static void RankTask()
        {
            //所有 3 页
            LiveList liveList = getAppId("hot", 1);

            if (liveList.data.key.retBody.data.total > 120)
            {
                getAppId("hot", 2);
            }

            if (liveList.data.key.retBody.data.total > 240)
            {
                getAppId("hot", 3);
            }

            //梦工厂 2 页
            liveList = getAppId("2000000157", 1);

            if (liveList.data.key.retBody.data.total > 120)
            {
                getAppId("2000000157", 2);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Gets a sequence of live objects from the collection, causing a purge.
 /// </summary>
 /// <returns>The sequence of live objects.</returns>
 IEnumerator <T> IEnumerable <T> .GetEnumerator()
 {
     return(LiveList.GetEnumerator());
 }
Exemplo n.º 12
0
        public MainWindow()
        {
            InitializeComponent();

            // create population of Stocks
            _securities = new LiveList<Security>();
            _securities.PublishInner.Connect(
                Enumerable
                    .Range(0, 1000)
                    .Select(i =>
                        {
                            var security = new Security
                            {
                                Price = { PublishValue = i * 1000000 },
                                SharesOnIssue = { PublishValue = 1 }
                            };
                            do
                            {
                                security.Code.PublishValue = RandomString(3);
                            } while (_securities.PublishInner.Any(s => s.Code == security.Code));

                            return security;
                        }));

            // setup queries
            MarketCaps = _securities.Select(s => s.MarketCap);
            TotalMarketCap = MarketCaps.Sum();
            TotalPublishedRate = TotalPublished
                .Convert<int,double>()
                .ToLiveRateOfChange();

            // bind UI counters
            DataContext = this;

            // make constant deltas
            Observable.Start(() =>
                {
                    while (true)
                    {
                        using (Publish.Transaction())
                        {
                            TotalPublished.PublishValue++;

                            var now = HiResTimer.Now();
                            var securities = _securities.PublishInner.ToArray();
                            securities.FastParallel(
                                (s, from, to) =>
                                {
                                    for (var i = from; i < to; i++)
                                    {
                                        var security = s[i];
                                        var oldPrice = security.Price.PublishValue;
                                        var price = oldPrice;

                                        var delta = 0.01M; //random.Next(-5, 6) / 100M;
                                        //if (delta == 0)
                                        //    delta = 0.01M;

                                        price += delta;
                                        if (price < 0)
                                            price -= delta * 2;
                                        security.Price.SetValue(price, now);
                                    }
                                });
                        }
                    }
                });

            Observable
                .Timer(TimeSpan.Zero, TimeSpan.FromSeconds(0.11))
                .Subscribe(l =>
                    {
                        //using (Publish.Transaction())
                        _NonPublished.PublishValue++;
                    });
        }