diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index 9355f6cd3..7fbbb645b 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -97,10 +97,8 @@ - - - + diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 1b447b93d..8bb94eb88 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -23,7 +23,6 @@ */ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Linq; using HtmlAgilityPack; using SteamKit2; using System; @@ -373,14 +372,14 @@ namespace ArchiSteamFarm { return response != null; // Steam API doesn't respond with any error code, assume any response is a success } - internal async Task> GetInventory() { - List result = new List(); + internal async Task> GetInventory() { + List result = new List(); try { JObject jObject = await WebBrowser.UrlGetToJObject("https://steamcommunity.com/my/inventory/json/753/6", Cookie).ConfigureAwait(false); IEnumerable jTokens = jObject.SelectTokens("$.rgInventory.*"); foreach (JToken jToken in jTokens) { - result.Add(JsonConvert.DeserializeObject(jToken.ToString())); + result.Add(JsonConvert.DeserializeObject(jToken.ToString())); } } catch (Exception e) { Logging.LogGenericException(Bot.BotName, e); @@ -389,7 +388,7 @@ namespace ArchiSteamFarm { return result; } - internal async Task SendTradeOffer(List items, ulong partnerID, string token = null) { + internal async Task SendTradeOffer(List items, ulong partnerID, string token = null) { if (items == null || partnerID == 0) { return false; } @@ -401,11 +400,11 @@ namespace ArchiSteamFarm { SteamTradeOfferRequest trade = new SteamTradeOfferRequest(); - foreach (SteamInventoryItem item in items) { - trade.me.assets.Add(new SteamTradeItem() { - appid = 753, - contextid = 6, - amount = int.Parse(item.amount), + foreach (SteamItem item in items) { + trade.me.assets.Add(new SteamItem() { + appid = "753", + contextid = "6", + amount = item.amount, assetid = item.id }); } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 06fc9a3a3..5f8f9c0b6 100644 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -47,6 +47,7 @@ namespace ArchiSteamFarm { internal static readonly HashSet GlobalBlacklist = new HashSet { 303700, 335590, 368020, 425280 }; private readonly string ConfigFile, LoginKeyFile, MobileAuthenticatorFile, SentryFile; + private readonly Timer SendItemsTimer; internal readonly string BotName; internal readonly ArchiHandler ArchiHandler; @@ -57,7 +58,6 @@ namespace ArchiSteamFarm { internal readonly SteamFriends SteamFriends; internal readonly SteamUser SteamUser; internal readonly Trading Trading; - private Timer Timer; private bool KeepRunning = true; private bool InvalidPassword = false; @@ -72,7 +72,6 @@ namespace ArchiSteamFarm { internal string SteamPassword { get; private set; } = "null"; internal string SteamNickname { get; private set; } = "null"; internal string SteamApiKey { get; private set; } = "null"; - internal string SteamTradeToken { get; private set; } = "null"; internal string SteamParentalPIN { get; private set; } = "0"; internal ulong SteamMasterID { get; private set; } = 0; internal ulong SteamMasterClanID { get; private set; } = 0; @@ -83,7 +82,8 @@ namespace ArchiSteamFarm { internal bool UseAsfAsMobileAuthenticator { get; private set; } = false; internal bool ShutdownOnFarmingFinished { get; private set; } = false; internal bool SendOnFarmingFinished { get; private set; } = false; - internal uint SendTradePeriod { get; private set; } = 0; + internal string SteamTradeToken { get; private set; } = "null"; + internal byte SendTradePeriod { get; private set; } = 0; internal HashSet Blacklist { get; private set; } = new HashSet(); internal bool Statistics { get; private set; } = true; @@ -176,6 +176,15 @@ namespace ArchiSteamFarm { CardsFarmer = new CardsFarmer(this); Trading = new Trading(this); + if (SendTradePeriod > 0 && SendItemsTimer == null) { + SendItemsTimer = new Timer( + async e => await ResponseSendTrade(BotName).ConfigureAwait(false), + null, + TimeSpan.FromHours(SendTradePeriod), // Delay + TimeSpan.FromHours(SendTradePeriod) // Period + ); + } + // Before attempting to connect, initialize our list of CMs SteamDirectory.Initialize().Wait(); @@ -344,7 +353,7 @@ namespace ArchiSteamFarm { SendOnFarmingFinished = bool.Parse(value); break; case "SendTradePeriod": - SendTradePeriod = uint.Parse(value); + SendTradePeriod = byte.Parse(value); break; case "Blacklist": Blacklist.Clear(); @@ -503,7 +512,7 @@ namespace ArchiSteamFarm { token = bot.SteamTradeToken; } - List inventory = await bot.ArchiWebHandler.GetInventory().ConfigureAwait(false); + List inventory = await bot.ArchiWebHandler.GetInventory().ConfigureAwait(false); if (inventory.Count == 0) { return "Nothing to send, inventory seems empty!"; } @@ -1044,15 +1053,6 @@ namespace ArchiSteamFarm { Trading.CheckTrades(); await CardsFarmer.StartFarming().ConfigureAwait(false); - - if (SendTradePeriod != 0) { - Timer = new Timer( - async e => await ResponseSendTrade(BotName).ConfigureAwait(false), - null, - TimeSpan.FromHours(SendTradePeriod), // Delay - Timeout.InfiniteTimeSpan // Period - ); - } break; case EResult.NoConnection: case EResult.ServiceUnavailable: diff --git a/ArchiSteamFarm/SteamInventoryItem.cs b/ArchiSteamFarm/SteamInventoryItem.cs deleted file mode 100644 index e162ca586..000000000 --- a/ArchiSteamFarm/SteamInventoryItem.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - _ _ _ ____ _ _____ - / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ - / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ - / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | -/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| - - Copyright 2015 Łukasz "JustArchi" Domeradzki - Contact: JustArchi@JustArchi.net - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -using Newtonsoft.Json; - -namespace ArchiSteamFarm { - internal class SteamInventoryItem { - [JsonProperty] - internal string id { get; set; } - - [JsonProperty] - internal string classid { get; set; } - - [JsonProperty] - internal string instanceid { get; set; } - - [JsonProperty] - internal string amount { get; set; } - - [JsonProperty] - internal int pos { get; set; } - } -} diff --git a/ArchiSteamFarm/SteamItem.cs b/ArchiSteamFarm/SteamItem.cs index 5e3e7c734..a42b9bc00 100644 --- a/ArchiSteamFarm/SteamItem.cs +++ b/ArchiSteamFarm/SteamItem.cs @@ -37,6 +37,12 @@ namespace ArchiSteamFarm { [JsonProperty] internal string assetid { get; set; } + [JsonProperty] + internal string id { + get { return assetid; } + set { assetid = value; } + } + [JsonProperty] internal string currencyid { get; set; } @@ -51,5 +57,8 @@ namespace ArchiSteamFarm { [JsonProperty] internal bool missing { get; set; } + + [JsonProperty] + internal int pos { get; set; } } } diff --git a/ArchiSteamFarm/SteamTradeItemList.cs b/ArchiSteamFarm/SteamItemList.cs similarity index 91% rename from ArchiSteamFarm/SteamTradeItemList.cs rename to ArchiSteamFarm/SteamItemList.cs index a410b44e0..db5aacd6f 100644 --- a/ArchiSteamFarm/SteamTradeItemList.cs +++ b/ArchiSteamFarm/SteamItemList.cs @@ -26,9 +26,9 @@ using Newtonsoft.Json; using System.Collections.Generic; namespace ArchiSteamFarm { - internal class SteamTradeItemList { + internal class SteamItemList { [JsonProperty] - internal List assets { get; set; } = new List(); + internal List assets { get; set; } = new List(); [JsonProperty] internal List currency { get; set; } = new List(); diff --git a/ArchiSteamFarm/SteamTradeItem.cs b/ArchiSteamFarm/SteamTradeItem.cs deleted file mode 100644 index 429a5629b..000000000 --- a/ArchiSteamFarm/SteamTradeItem.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* - _ _ _ ____ _ _____ - / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ - / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ - / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | -/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| - - Copyright 2015 Łukasz "JustArchi" Domeradzki - Contact: JustArchi@JustArchi.net - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -using Newtonsoft.Json; - -namespace ArchiSteamFarm { - internal class SteamTradeItem { - [JsonProperty] - internal int appid { get; set; } - - [JsonProperty] - internal int contextid { get; set; } - - [JsonProperty] - internal int amount { get; set; } - - [JsonProperty] - internal string assetid { get; set; } - } -} diff --git a/ArchiSteamFarm/SteamTradeOfferRequest.cs b/ArchiSteamFarm/SteamTradeOfferRequest.cs index 0a5fad9a3..fa2e6e52b 100644 --- a/ArchiSteamFarm/SteamTradeOfferRequest.cs +++ b/ArchiSteamFarm/SteamTradeOfferRequest.cs @@ -33,9 +33,9 @@ namespace ArchiSteamFarm { internal int version { get; set; } = 2; [JsonProperty] - internal SteamTradeItemList me { get; set; } = new SteamTradeItemList(); + internal SteamItemList me { get; set; } = new SteamItemList(); [JsonProperty] - internal SteamTradeItemList them { get; set; } = new SteamTradeItemList(); + internal SteamItemList them { get; set; } = new SteamItemList(); } } diff --git a/ArchiSteamFarm/config/example.xml b/ArchiSteamFarm/config/example.xml index 8ab58c015..25d858dbb 100644 --- a/ArchiSteamFarm/config/example.xml +++ b/ArchiSteamFarm/config/example.xml @@ -13,6 +13,7 @@ + @@ -104,22 +105,25 @@ - - - + + + - - - - - - - - - + + + + + + + + + + + +