Skip to content

Commit

Permalink
去除未使用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed May 28, 2022
1 parent 35075e1 commit 60b076a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 137 deletions.
83 changes: 0 additions & 83 deletions ASFEnhance/Cart/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,89 +162,6 @@ internal static class Command
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}

/// <summary>
/// 添加内购物品到购物车
/// </summary>
/// <param name="bot"></param>
/// <param name="query"></param>
/// <returns></returns>
internal static async Task<string?> ResponseAddCartIngameItems(Bot bot, string query)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

Dictionary<string, SteamGameID> itemIDs = FetchItemIDs(query);

if (itemIDs.Count < 2)
{
return bot.FormatBotResponse("参数错误, 最少需要两个参数");
}
else if (itemIDs.First().Value.GameType == SteamGameIDType.Error)
{
return bot.FormatBotResponse(string.Format(Langs.ArgumentNotInteger, "AppID"));
}

StringBuilder response = new();
response.AppendLine(Langs.MultipleLineResult);

uint appID = itemIDs.First().Value.GameID;
response.AppendLine(string.Format("AppID : {0}", appID));

bool first = true;
foreach (KeyValuePair<string, SteamGameID> item in itemIDs)
{
if (first)
{
first = false;
continue;
}

string input = item.Key;
SteamGameID itemID = item.Value;

if (itemID.GameType == SteamGameIDType.Item)
{
EResult? success = await WebRequest.AddCart(bot, appID, itemID.GameID).ConfigureAwait(false);
response.AppendLine(bot.FormatBotResponse(string.Format("- {0}|{1} : {2}", appID, itemID.GameID, success == null ? Langs.CartNetworkError : success)));
}
else
{
response.AppendLine(bot.FormatBotResponse(string.Format("- {0} : {1}", input, string.Format(Langs.ArgumentNotInteger, "itemID"))));
}
}
return response.ToString();
}

/// <summary>
/// 添加商品到购物车 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <param name="query"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseAddCartIngameItems(string botNames, string query)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

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

if ((bots == null) || (bots.Count == 0))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseAddCartIngameItems(bot, query))).ConfigureAwait(false);

List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!);

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}

/// <summary>
/// 清空购物车
/// </summary>
Expand Down
29 changes: 0 additions & 29 deletions ASFEnhance/Cart/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,6 @@ internal static class WebRequest
return response != null;
}

/// <summary>
/// 添加购物车(游戏物品)
/// </summary>
/// <param name="bot"></param>
/// <param name="appID"></param>
/// <param name="classID"></param>
/// <returns></returns>
internal static async Task<SteamKit2.EResult?> AddCart(Bot bot, uint appID, uint classID)
{
Uri request = new(SteamStoreURL, "/cart/addtocart");
Uri referer = new(SteamStoreURL, $"/itemstore/{appID}/detail/{classID}/");

Dictionary<string, string> data = new(5, StringComparer.Ordinal)
{
{ "action", "add_to_cart" },
{ "microtxnappid", appID.ToString() },
{ "microtxnassetclassid", classID.ToString() },
};

ObjectResponse<ResultResponse>? response = await bot.ArchiWebHandler.UrlPostToJsonObjectWithSession<ResultResponse>(request, data: data, referer: referer).ConfigureAwait(false);

if (response == null)
{
return null;
}

return response.Content.Result;
}

/// <summary>
/// 清空当前购物车
/// </summary>
Expand Down
25 changes: 0 additions & 25 deletions ASFEnhance/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,6 @@ internal static Dictionary<string, SteamGameID> FetchGameIDs(string query, Steam
return result;
}

/// <summary>
/// 匹配内购物品ID
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
internal static Dictionary<string, SteamGameID> FetchItemIDs(string query)
{
Dictionary<string, SteamGameID> result = new();

string[] entries = query.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

foreach (string entry in entries)
{
if (uint.TryParse(entry, out uint itemID) && (itemID > 0))
{
result.Add(entry, new(SteamGameIDType.Item, itemID));
}
else
{
result.Add(entry, new(SteamGameIDType.Error, 0));
}
}
return result;
}

/// <summary>
/// 获取版本号
/// </summary>
Expand Down

0 comments on commit 60b076a

Please sign in to comment.