Пример #1
0
        private async Task BilibiliDynamicsCheckTimer(IEnumerable <VtuberEntity> vtubers)
        {
            foreach (var vtuberEntity in vtubers.Where(v => v.BilibiliUserId != 0))
            {
                var timeline = await BilibiliApi.GetDynamicsByUser(vtuberEntity.BilibiliUserId);

                if (timeline?.Any() ?? false)
                {
                    continue;
                }
                if (!LastCheckBilibiliDynamic.ContainsKey(vtuberEntity))
                {
                    LastCheckBilibiliDynamic.Add(vtuberEntity, timeline.First());
                }
            }
        }
Пример #2
0
        public async void SetChineseNameCommand(AcceptedMessage message, string[] args)
        {
            var vtuber = await GetVtuberAsync(args[2]);

            if (vtuber == null)
            {
                await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到Vtuber.");

                return;
            }
            vtuber.ChineseName = args[3];
            await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                    new UpdateOptions()
            {
                IsUpsert = true
            });

            await SendingService.SendGroupMessageAsync(message.FromGroup, "设置完成.");

            try
            {
                var uploader = (await BilibiliApi.SearchBilibiliUsersAsync(vtuber.ChineseName))
                               .OrderByDescending(v => v.Follower).FirstOrDefault(v => v.IsUploader);
                if (uploader != null && vtuber.BilibiliUserId == 0)
                {
                    vtuber.BilibiliUserId = uploader.Id;
                    await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                            new UpdateOptions()
                    {
                        IsUpsert = true
                    });

                    await SendingService.SendGroupMessageAsync(message.FromGroup, $"已根据中文名自动查找B站搬运组:" +
                                                               $"\r\n用户名: {uploader.Username}" +
                                                               $"\r\n主页: https://space.bilibili.com/{uploader.Id}" +
                                                               $"\r\n粉丝数: {uploader.Follower}");

                    await SendingService.SendGroupMessageAsync(message.FromGroup, "可使用!Vtuber 设置B站 <Vtuber名字> <B站空间ID或搬运组名称> 来修改");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("Search bilibili uploader error.", ex: ex);
            }
        }
Пример #3
0
        private async Task BilibiliLiveCheckTimer(IEnumerable <VtuberEntity> vtubers)
        {
            foreach (var vtuberEntity in vtubers.Where(v => v.BilibiliUserId != 0 && v.BilibiliLiveRoomId != -1))
            {
                if (!LastCheckBilibiliLive.ContainsKey(vtuberEntity))
                {
                    LastCheckBilibiliLive.Add(vtuberEntity, new BilibiliLiveRoom());
                }
                if (vtuberEntity.BilibiliLiveRoomId == 0)
                {
                    var userInfo = await BilibiliApi.GetBilibiliUserAsync(vtuberEntity.BilibiliUserId);

                    vtuberEntity.BilibiliLiveRoomId = userInfo.LiveRoomId == 0 ? -1 : userInfo.LiveRoomId;
                    _vtuberCollection.ReplaceOne(v => v.Id == vtuberEntity.Id, vtuberEntity,
                                                 new UpdateOptions()
                    {
                        IsUpsert = true
                    });
                    LogHelper.Info($"更新Vtuber {vtuberEntity.OriginalName} 的Live room id: {userInfo.LiveRoomId}");
                }
                if (vtuberEntity.BilibiliLiveRoomId <= 0)
                {
                    continue;
                }
                if (!BilibiliRecorders.ContainsKey(vtuberEntity) && vtuberEntity.BilibiliLiveRoomId > 0)
                {
                    BilibiliRecorders.Add(vtuberEntity,
                                          new BilibiliDanmakuRecorder(vtuberEntity.BilibiliLiveRoomId, vtuberEntity));
                    LogHelper.Info($"开始监听Vtuber {vtuberEntity.OriginalName} 的B站直播间.");
                    await BilibiliRecorders[vtuberEntity].BeginRecordAsync();
                }
                var roomInfo = await BilibiliApi.GetLiveRoomAsync(vtuberEntity.BilibiliLiveRoomId).Retry(3);

                if (roomInfo == null)
                {
                    continue;
                }
                if (roomInfo.OnLive && !LastCheckBilibiliLive[vtuberEntity].OnLive)
                {
                    var liveId    = roomInfo.LiveSession;
                    var beginTime = DateTimeExtensions.TimestampToDateTime(roomInfo.LiveBeginTime);
                    void OnLiveStoppedEvent(BilibiliDanmakuRecorder client)
                    {
                        LogHelper.Info($"{vtuberEntity.OriginalName} 已停止在B站的直播");
                        var endTime = DateTime.Now;
                        var info    = new BilibiliLiveInfo()
                        {
                            LiveId        = liveId,
                            BeginTime     = beginTime,
                            EndTime       = endTime,
                            ChannelId     = vtuberEntity.BilibiliUserId,
                            MaxPopularity = client.LiveClient.MaxPopularity,
                            Title         = roomInfo.Title
                        };

                        _biliLiveCollection.InsertOneAsync(info).Retry(5).GetAwaiter().GetResult();
                        VtuberStoppedBilibiliLiveEvent?.Invoke(vtuberEntity, roomInfo);
                        BilibiliRecorders[vtuberEntity].LiveStoppedEvent -= OnLiveStoppedEvent;
                    }

                    BilibiliRecorders[vtuberEntity].LiveStoppedEvent += OnLiveStoppedEvent;
                    VtuberBeginBilibiliLiveEvent?.Invoke(vtuberEntity, roomInfo);
                }
                LastCheckBilibiliLive[vtuberEntity] = roomInfo;
            }
        }
Пример #4
0
        public async void UpdateBilibiliProfileCommand(AcceptedMessage message, string[] args)
        {
            var vtuber = await GetVtuberAsync(args[2]);

            if (vtuber == null)
            {
                await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到相关Vtuber");

                return;
            }
            if (long.TryParse(args[3], out var uid))
            {
                var userInfo = await BilibiliApi.GetBilibiliUserAsync(uid);

                if (userInfo == null)
                {
                    await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到UID: " + uid);

                    return;
                }
                vtuber.BilibiliUserId = uid;
                await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                        new UpdateOptions()
                {
                    IsUpsert = true
                });

                await SendingService.SendGroupMessageAsync(message.FromGroup, $"保存完成:" +
                                                           $"\r\n用户名: {userInfo.Username}" +
                                                           $"\r\n主页: https://space.bilibili.com/{uid}" +
                                                           $"\r\n粉丝数: {userInfo.Follower}");

                return;
            }
            try
            {
                var uploader = (await BilibiliApi.SearchBilibiliUsersAsync(args[3]))
                               .OrderByDescending(v => v.Follower).FirstOrDefault(v => v.IsUploader);
                if (uploader != null)
                {
                    vtuber.BilibiliUserId = uploader.Id;
                    await _vtuberCollection.ReplaceOneAsync(v => v.Id == vtuber.Id, vtuber,
                                                            new UpdateOptions()
                    {
                        IsUpsert = true
                    });

                    await SendingService.SendGroupMessageAsync(message.FromGroup, $"保存完成:" +
                                                               $"\r\n用户名: {uploader.Username}" +
                                                               $"\r\n主页: https://space.bilibili.com/{uploader.Id}" +
                                                               $"\r\n粉丝数: {uploader.Follower}");

                    return;
                }
                await SendingService.SendGroupMessageAsync(message.FromGroup, "未找到 " + args[3]);
            }
            catch (Exception ex)
            {
                LogHelper.Error("Search bilibili uploader error.", ex: ex);
            }
        }