Skip to content

Commit

Permalink
Merge pull request #757 from Polaris-cn10086/develop
Browse files Browse the repository at this point in the history
根据最新的亲密度规则对程序进行修改
  • Loading branch information
RayWangQvQ authored Sep 8, 2024
2 parents 7836737 + faf4380 commit 5aa8a4f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,32 @@ namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Live
{
public class LikeLiveRoomRequest
{
public LikeLiveRoomRequest(long roomid, string csrf)
public LikeLiveRoomRequest(long roomid, string csrf, int clickTime, long anchorId, string uid)
{
Roomid = roomid;
Csrf= csrf;
Csrf = csrf;
Click_Time = clickTime;
Anchor_Id = anchorId;
Uid = uid;
}

public long Roomid { get; set; }

public string Csrf { get; set; }

public string Csrf_token => Csrf;
public string Csrf_Token => Csrf;

public int Click_Time { get; set; }

public long Anchor_Id { get; set; }

public string Uid { get; set; }


public string RawTextBuild()
{
return
$"click_time={Click_Time.ToString()}&room_id={Roomid.ToString()}&uid={Uid}&anchor_id={Anchor_Id}&csrf_token={Csrf_Token}&csrf={Csrf}";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public interface ILiveApi : IBiliBiliApi
/// <summary>
/// 点赞直播间
/// </summary>
[HttpPost("/xlive/web-ucenter/v1/interact/likeInteract")]
[HttpPost("/xlive/app-ucenter/v1/like_info_v3/like/likeReportV3")]
[Header("Referer", "https://live.bilibili.com/")]
[Header("Origin", "https://live.bilibili.com")]
Task<BiliApiResponse> LikeLiveRoom([FormContent] LikeLiveRoomRequest request);
}
Task<BiliApiResponse> LikeLiveRoom([RawFormContent] string request);
}
16 changes: 6 additions & 10 deletions src/Ray.BiliBiliTool.Config/Options/LiveFansMedalTaskOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@ public class LiveFansMedalTaskOptions
public const int HeartBeatInterval = 60;

/// <summary>
/// 点赞次数
/// 点赞次数,默认值为30(用于点亮粉丝勋章)
/// </summary>
public int LikeNumber { get; set; } = 55;

/// <summary>
/// 点赞发送失败多少次时放弃
/// </summary>
public int LikeGiveUpThreshold { get; set; } = 5;
public int LikeNumber { get; set; } = 30;

/// <summary>
/// 发送弹幕次数
/// </summary>
public int SendDanmakuNumber { get; set; } = 15;
public int SendDanmakuNumber { get; set; } = 1;

/// <summary>
/// 弹幕发送失败多少次时放弃
/// </summary>
public int SendDanmakugiveUpThreshold { get; set; } = 5;
public int SendDanmakugiveUpThreshold { get; set; } = 3;
}
}
}
49 changes: 24 additions & 25 deletions src/Ray.BiliBiliTool.DomainService/LiveDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ public async Task SendDanmakuToFansMedalLive()
while (successCount < _liveFansMedalTaskOptions.SendDanmakuNumber &&
failedCount < _liveFansMedalTaskOptions.SendDanmakugiveUpThreshold)
{
await Task.Delay(2000);

var sendResult = await _liveApi.SendLiveDanmuku(new SendLiveDanmukuRequest(
_biliCookie.BiliJct,
spaceInfo.Data.Live_room.Roomid,
Expand All @@ -447,6 +445,9 @@ public async Task SendDanmakuToFansMedalLive()
}
else
successCount++;

var delay = new Random().Next(2000, 4000);
await Task.Delay(delay);
}


Expand All @@ -460,7 +461,7 @@ public async Task SendHeartBeatToFansMedalLive()
if (!await CheckLiveCookie()) return;

var infoList = new List<HeartBeatIterationInfoDto>();
(await GetFansMedalInfoList()).ForEach(medal =>
(await GetFansMedalInfoList()).FindAll(info => info.LiveRoomInfo.Live_Status != 0).ForEach(medal =>
infoList.Add(new(medal.RoomId, medal.LiveRoomInfo, new(), 0, 0))
);

Expand Down Expand Up @@ -559,38 +560,36 @@ public async Task SendHeartBeatToFansMedalLive()
_logger.LogInformation("【直播观看时长】完成情况:{success}/{total} ", successCount, infoList.Count);
}

/// <summary>
/// 点赞直播间
/// </summary>
public async Task LikeFansMedalLive()
{
if (!await CheckLiveCookie()) return;

var infoList = await GetFansMedalInfoList();
infoList = infoList.FindAll(info => info.LiveRoomInfo.Live_Status != 1);

infoList = infoList.FindAll(info => info.LiveRoomInfo.Live_Status != 0);
_logger.LogInformation("当前开播直播间数量:{num}", infoList.Count);
foreach (var info in infoList)
{
var successCount = 0;
var failedCount = 0;
while (successCount < _liveFansMedalTaskOptions.LikeNumber &&
failedCount < _liveFansMedalTaskOptions.LikeGiveUpThreshold)
{
var result = await _liveApi.LikeLiveRoom(new LikeLiveRoomRequest(info.RoomId, _biliCookie.BiliJct));
if (result.Code == 0)
{
// _logger.LogInformation("【点赞直播间】{roomId} 完成", info.RoomId);
successCount++;
}
else
{
_logger.LogError("【点赞直播间】{roomId} 时候出现错误", info.RoomId);
_logger.LogError("【原因】{message}", result.Message);
failedCount++;
}
// Clike_Time 暂时设置为等于设置的LikeNumber,不清楚是否会被风控,我自己抓包最大值为10
var request = new LikeLiveRoomRequest(info.RoomId, _biliCookie.BiliJct,
_liveFansMedalTaskOptions.LikeNumber,
info.LiveRoomInfo.Uid, _biliCookie.UserId);

await Task.Delay(500);
var result = await _liveApi.LikeLiveRoom(request.RawTextBuild());
if (result.Code == 0)
{
_logger.LogInformation("【点赞直播间】{roomId} 完成", info.RoomId);
}
else
{
_logger.LogError("【点赞直播间】{roomId} 时候出现错误", info.RoomId);
_logger.LogError("【原因】{message}", result.Message);
}

_logger.LogInformation("【点赞直播间】{romeId}完成情况:{success}/{total}", info.RoomId, successCount,
failedCount + successCount);
var delay = new Random().Next(5000, 8000);
await Task.Delay(delay);
}
}

Expand Down

0 comments on commit 5aa8a4f

Please sign in to comment.