mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
get inventory with language (#3409)
* get inventory with language * get inventory with language * edit * edit
This commit is contained in:
@@ -283,7 +283,7 @@ public sealed class BotController : ArchiController {
|
||||
[HttpGet("{botNames:required}/Inventory/{appID}/{contextID}")]
|
||||
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, BotInventoryResponse>>>((int) HttpStatusCode.OK)]
|
||||
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.BadRequest)]
|
||||
public async Task<ActionResult<GenericResponse>> InventoryGet(string botNames, uint appID, ulong contextID) {
|
||||
public async Task<ActionResult<GenericResponse>> InventoryGet(string botNames, uint appID, ulong contextID, [FromQuery] string? language = null) {
|
||||
ArgumentException.ThrowIfNullOrEmpty(botNames);
|
||||
|
||||
if (appID == 0) {
|
||||
@@ -300,7 +300,7 @@ public sealed class BotController : ArchiController {
|
||||
return BadRequest(new GenericResponse(false, Strings.FormatBotNotFound(botNames)));
|
||||
}
|
||||
|
||||
IList<(HashSet<Asset>? Result, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.GetInventory(appID, contextID))).ConfigureAwait(false);
|
||||
IList<(HashSet<Asset>? Result, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.GetInventory(appID, contextID, language: language))).ConfigureAwait(false);
|
||||
|
||||
Dictionary<string, BotInventoryResponse> result = new(bots.Count, Bot.BotsComparer);
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ public sealed class ArchiHandler : ClientMsgHandler, IDisposable {
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async IAsyncEnumerable<Asset> GetMyInventoryAsync(uint appID = Asset.SteamAppID, ulong contextID = Asset.SteamCommunityContextID, bool tradableOnly = false, bool marketableOnly = false, ushort itemsCountPerRequest = ArchiWebHandler.MaxItemsInSingleInventoryRequest) {
|
||||
public async IAsyncEnumerable<Asset> GetMyInventoryAsync(uint appID = Asset.SteamAppID, ulong contextID = Asset.SteamCommunityContextID, bool tradableOnly = false, bool marketableOnly = false, ushort itemsCountPerRequest = ArchiWebHandler.MaxItemsInSingleInventoryRequest, string? language = null) {
|
||||
ArgumentOutOfRangeException.ThrowIfZero(appID);
|
||||
ArgumentOutOfRangeException.ThrowIfZero(contextID);
|
||||
ArgumentOutOfRangeException.ThrowIfZero(itemsCountPerRequest);
|
||||
@@ -208,6 +208,10 @@ public sealed class ArchiHandler : ClientMsgHandler, IDisposable {
|
||||
count = itemsCountPerRequest
|
||||
};
|
||||
|
||||
if (language != null) {
|
||||
request.language = language;
|
||||
}
|
||||
|
||||
// We need to store asset IDs to make sure we won't get duplicate items
|
||||
HashSet<ulong>? assetIDs = null;
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ public sealed class ArchiWebHandler : IDisposable {
|
||||
/// This method should be used exclusively for foreign inventories (other users), but in special circumstances it can be used for fetching bot's own inventory as well.
|
||||
/// </remarks>
|
||||
[PublicAPI]
|
||||
public async IAsyncEnumerable<Asset> GetInventoryAsync(ulong steamID = 0, uint appID = Asset.SteamAppID, ulong contextID = Asset.SteamCommunityContextID) {
|
||||
public async IAsyncEnumerable<Asset> GetInventoryAsync(ulong steamID = 0, uint appID = Asset.SteamAppID, ulong contextID = Asset.SteamCommunityContextID, string? language = null) {
|
||||
ArgumentOutOfRangeException.ThrowIfZero(appID);
|
||||
ArgumentOutOfRangeException.ThrowIfZero(contextID);
|
||||
|
||||
@@ -259,6 +259,8 @@ public sealed class ArchiWebHandler : IDisposable {
|
||||
throw new InvalidOperationException(nameof(ASF.InventorySemaphore));
|
||||
}
|
||||
|
||||
language ??= "english";
|
||||
|
||||
ulong startAssetID = 0;
|
||||
|
||||
// We need to store asset IDs to make sure we won't get duplicate items
|
||||
@@ -269,7 +271,7 @@ public sealed class ArchiWebHandler : IDisposable {
|
||||
int rateLimitingDelay = (ASF.GlobalConfig?.InventoryLimiterDelay ?? GlobalConfig.DefaultInventoryLimiterDelay) * 1000;
|
||||
|
||||
while (true) {
|
||||
Uri request = new(SteamCommunityURL, $"/inventory/{steamID}/{appID}/{contextID}?l=english&count={MaxItemsInSingleInventoryRequest}{(startAssetID > 0 ? $"&start_assetid={startAssetID}" : "")}");
|
||||
Uri request = new(SteamCommunityURL, $"/inventory/{steamID}/{appID}/{contextID}?l={language}&count={MaxItemsInSingleInventoryRequest}{(startAssetID > 0 ? $"&start_assetid={startAssetID}" : "")}");
|
||||
|
||||
await ASF.InventorySemaphore.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ public sealed class Actions : IAsyncDisposable, IDisposable {
|
||||
|
||||
/// <remarks>This action should be used if you require full inventory exclusively, otherwise consider calling <see cref="ArchiHandler.GetMyInventoryAsync" /> instead.</remarks>
|
||||
[PublicAPI]
|
||||
public async Task<(HashSet<Asset>? Result, string Message)> GetInventory(uint appID = Asset.SteamAppID, ulong contextID = Asset.SteamCommunityContextID, Func<Asset, bool>? filterFunction = null) {
|
||||
public async Task<(HashSet<Asset>? Result, string Message)> GetInventory(uint appID = Asset.SteamAppID, ulong contextID = Asset.SteamCommunityContextID, Func<Asset, bool>? filterFunction = null, string? language = null) {
|
||||
ArgumentOutOfRangeException.ThrowIfZero(appID);
|
||||
ArgumentOutOfRangeException.ThrowIfZero(contextID);
|
||||
|
||||
@@ -186,7 +186,7 @@ public sealed class Actions : IAsyncDisposable, IDisposable {
|
||||
|
||||
using (await GetTradingLock().ConfigureAwait(false)) {
|
||||
try {
|
||||
return (await Bot.ArchiHandler.GetMyInventoryAsync(appID, contextID).Where(item => filterFunction(item)).ToHashSetAsync().ConfigureAwait(false), Strings.Success);
|
||||
return (await Bot.ArchiHandler.GetMyInventoryAsync(appID, contextID, language: language).Where(item => filterFunction(item)).ToHashSetAsync().ConfigureAwait(false), Strings.Success);
|
||||
} catch (TimeoutException e) {
|
||||
Bot.ArchiLogger.LogGenericWarningException(e);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user