Skip to content

Commit

Permalink
feat: 优化提示
Browse files Browse the repository at this point in the history
  • Loading branch information
withsalt committed Apr 25, 2022
1 parent 5c1870b commit cf1d228
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/BilibiliLiveCommon/Services/BilibiliLiveApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<bool> UpdateLiveRoomName(int roomId, string title)
}
finally
{
await Task.Delay(new Random().Next(5000, 10000));
await SlowDownOperation(nameof(UpdateLiveRoomName));
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ public async Task<bool> UpdateLiveRoomArea(int roomId, int areaId)
}
finally
{
await Task.Delay(new Random().Next(5000, 10000));
await SlowDownOperation(nameof(UpdateLiveRoomArea));
}
}

Expand Down Expand Up @@ -189,9 +189,8 @@ public async Task<StartLiveInfo> StartLive(int roomId, int areaId)
}
finally
{
await Task.Delay(new Random().Next(5000, 10000));
await SlowDownOperation(nameof(StartLive));
}

}

public async Task<StopLiveInfo> StopLive(int roomId)
Expand All @@ -218,7 +217,7 @@ public async Task<StopLiveInfo> StopLive(int roomId)
}
finally
{
await Task.Delay(new Random().Next(5000, 10000));
await SlowDownOperation(nameof(StopLive));
}
}

Expand Down Expand Up @@ -276,6 +275,13 @@ private async Task<LiveAreaItem> CheckArea(int areaId)
return areaItem;
}

private async Task SlowDownOperation(string operationName)
{
int sleepMsec = new Random().Next(5000, 10000);
_logger.LogInformation($"执行{operationName}操作完成,休眠{sleepMsec / 1000}秒(避免频繁操作)。");
await Task.Delay(sleepMsec);
}

#endregion
}
}

0 comments on commit cf1d228

Please sign in to comment.