Example #1
0
        public void FilterJoinTianXuan()
        {
            using (var scope = Global.ServiceProviderRoot.CreateScope())
            {
                var options = scope.ServiceProvider.GetRequiredService <IOptionsMonitor <LiveLotteryTaskOptions> >();

                var check = new CheckTianXuanDto
                {
                    Award_name = "ºì°ü"
                };
                var re = check.AwardNameIsSatisfied(options.CurrentValue.IncludeAwardNameList, options.CurrentValue.ExcludeAwardNameList);
                Assert.True(re);
            }
        }
        public void TryJoinTianXuan(ListItemDto target)
        {
            _logger.LogInformation("【直播间】{name}({id})", target.Title, target.Roomid);

            try
            {
                CheckTianXuanDto check = _liveApi.CheckTianXuan(target.Roomid)
                                         .GetAwaiter().GetResult()
                                         .Data;

                if (check == null)
                {
                    _logger.LogInformation("数据异常,跳过");
                    return;
                }

                if (check.Status != 1)
                {
                    _logger.LogInformation("已开奖,跳过" + Environment.NewLine);
                    return;
                }

                _logger.LogInformation("【奖励】{name}", check.Award_name);
                _logger.LogInformation("【条件】{text}", check.Require_text);
                _logger.LogInformation("【赠礼】{gift}", check.Gift_price > 0 ? check.GiftDesc : "无");

                if (check.Gift_price != 0)
                {
                    _logger.LogInformation("需赠送礼物,跳过" + Environment.NewLine);
                    return;
                }

                //根据配置过滤
                if (!check.AwardNameIsSatisfied(_liveLotteryTaskOptions.IncludeAwardNameList, _liveLotteryTaskOptions.ExcludeAwardNameList))
                {
                    _logger.LogInformation("不满足配置的筛选条件,跳过" + Environment.NewLine);
                    return;
                }

                var request = new JoinTianXuanRequest
                {
                    Id       = check.Id,
                    Gift_id  = check.Gift_id,
                    Gift_num = check.Gift_num,
                    Csrf     = _biliCookie.BiliJct
                };
                var re = _liveApi.Join(request)
                         .GetAwaiter().GetResult();
                if (re.Code == 0)
                {
                    _logger.LogInformation("【参与抽奖】成功 √" + Environment.NewLine);
                    return;
                }

                _logger.LogInformation("【参与抽奖】失败");
                _logger.LogInformation("【原因】{msg}" + Environment.NewLine, re.Message);
            }
            catch (Exception ex)
            {
                _logger.LogWarning("【异常】{msg},{detail}" + Environment.NewLine, ex.Message, ex);
                //ignore
            }
        }
        public void TryJoinTianXuan(ListItemDto target)
        {
            _logger.LogDebug("【房间】{name}", target.Title);
            try
            {
                CheckTianXuanDto check = _liveApi.CheckTianXuan(target.Roomid)
                                         .GetAwaiter().GetResult()
                                         .Data;

                if (check == null)
                {
                    _logger.LogDebug("数据异常,跳过");
                    return;
                }

                if (check.Status != TianXuanStatus.Enable)
                {
                    _logger.LogDebug("已开奖,跳过" + Environment.NewLine);
                    return;
                }

                //根据配置过滤
                if (!check.AwardNameIsSatisfied(_liveLotteryTaskOptions.IncludeAwardNameList, _liveLotteryTaskOptions.ExcludeAwardNameList))
                {
                    _logger.LogDebug("不满足配置的筛选条件,跳过" + Environment.NewLine);
                    return;
                }

                //是否需要赠礼
                if (check.Gift_price > 0)
                {
                    _logger.LogDebug("【赠礼】{gift}", check.GiftDesc);
                    _logger.LogDebug("需赠送礼物,跳过" + Environment.NewLine);
                    return;
                }

                //条件
                if (check.Require_type != RequireType.None && check.Require_type != RequireType.Follow)
                {
                    _logger.LogDebug("【条件】{text}", check.Require_text);
                    _logger.LogDebug("要求粉丝勋章,跳过");
                    return;
                }

                _logger.LogInformation("【房间】{name}", target.ShortTitle);
                _logger.LogInformation("【主播】{name}({id})", target.Uname, target.Uid);
                _logger.LogInformation("【奖品】{name}【条件】{text}", check.Award_name, check.Require_text);

                var request = new JoinTianXuanRequest
                {
                    Id       = check.Id,
                    Gift_id  = check.Gift_id,
                    Gift_num = check.Gift_num,
                    Csrf     = _biliCookie.BiliJct
                };
                var re = _liveApi.Join(request)
                         .GetAwaiter().GetResult();
                if (re.Code == 0)
                {
                    _logger.LogInformation("【抽奖】成功 √" + Environment.NewLine);
                    if (check.Require_type == RequireType.Follow)
                    {
                        _tianXuanFollowed.AddIfNotExist(target, x => x.Uid == target.Uid);
                    }
                    return;
                }

                _logger.LogInformation("【抽奖】失败");
                _logger.LogInformation("【原因】{msg}" + Environment.NewLine, re.Message);
            }
            catch (Exception ex)
            {
                _logger.LogWarning("【异常】{msg},{detail}" + Environment.NewLine, ex.Message, ex);
                //ignore
            }
        }