Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Oct 13, 2024
1 parent dae03af commit f2b8897
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions ArchiSteamFarm/IPC/Controllers/Api/BotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,6 @@ public async Task<ActionResult<GenericResponse>> AddLicensePost(string botNames,
return Ok(new GenericResponse<IReadOnlyDictionary<string, BotAddLicenseResponse>>(result));
}

/// <summary>
/// Redeems points on given bots.
/// </summary>
[Consumes("application/json")]
[HttpPost("{botNames:required}/RedeemPoints/{definitionID:required}")]
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, EResult>>>((int) HttpStatusCode.OK)]
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.BadRequest)]
public async Task<ActionResult<GenericResponse>> AddLicensePost(string botNames, uint definitionID) {
ArgumentException.ThrowIfNullOrEmpty(botNames);
ArgumentOutOfRangeException.ThrowIfZero(definitionID);

HashSet<Bot>? bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0)) {
return BadRequest(new GenericResponse(false, Strings.FormatBotNotFound(botNames)));
}

IList<EResult> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.RedeemPoints(definitionID))).ConfigureAwait(false);

Dictionary<string, EResult> result = new(bots.Count, Bot.BotsComparer);

foreach (Bot bot in bots) {
result[bot.BotName] = results[result.Count];
}

return Ok(new GenericResponse<IReadOnlyDictionary<string, EResult>>(result));
}

/// <summary>
/// Deletes all files related to given bots.
/// </summary>
Expand Down Expand Up @@ -346,6 +318,34 @@ public async Task<ActionResult<GenericResponse>> PausePost(string botNames, [Fro
return Ok(new GenericResponse(results.All(static result => result.Success), string.Join(Environment.NewLine, results.Select(static result => result.Message))));
}

/// <summary>
/// Redeems points on given bots.
/// </summary>
[Consumes("application/json")]
[HttpPost("{botNames:required}/RedeemPoints/{definitionID:required}")]
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, EResult>>>((int) HttpStatusCode.OK)]
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.BadRequest)]
public async Task<ActionResult<GenericResponse>> RedeemPointsPost(string botNames, uint definitionID) {
ArgumentException.ThrowIfNullOrEmpty(botNames);
ArgumentOutOfRangeException.ThrowIfZero(definitionID);

HashSet<Bot>? bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0)) {
return BadRequest(new GenericResponse(false, Strings.FormatBotNotFound(botNames)));
}

IList<EResult> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.RedeemPoints(definitionID))).ConfigureAwait(false);

Dictionary<string, EResult> result = new(bots.Count, Bot.BotsComparer);

foreach (Bot bot in bots) {
result[bot.BotName] = results[result.Count];
}

return Ok(new GenericResponse<IReadOnlyDictionary<string, EResult>>(result));
}

/// <summary>
/// Redeems cd-keys on given bot.
/// </summary>
Expand Down

0 comments on commit f2b8897

Please sign in to comment.