Trading: Further improvements

I even merged some classes together, I'm magician
This commit is contained in:
JustArchi
2016-01-14 02:24:55 +01:00
parent 3df34ece61
commit d507b40c97
9 changed files with 53 additions and 128 deletions

View File

@@ -97,10 +97,8 @@
<Compile Include="Logging.cs" /> <Compile Include="Logging.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SteamInventoryItem.cs" />
<Compile Include="SteamItem.cs" /> <Compile Include="SteamItem.cs" />
<Compile Include="SteamTradeItem.cs" /> <Compile Include="SteamItemList.cs" />
<Compile Include="SteamTradeItemList.cs" />
<Compile Include="SteamTradeOffer.cs" /> <Compile Include="SteamTradeOffer.cs" />
<Compile Include="SteamTradeOfferRequest.cs" /> <Compile Include="SteamTradeOfferRequest.cs" />
<Compile Include="Trading.cs" /> <Compile Include="Trading.cs" />

View File

@@ -23,7 +23,6 @@
*/ */
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Linq;
using HtmlAgilityPack; using HtmlAgilityPack;
using SteamKit2; using SteamKit2;
using System; 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 return response != null; // Steam API doesn't respond with any error code, assume any response is a success
} }
internal async Task<List<SteamInventoryItem>> GetInventory() { internal async Task<List<SteamItem>> GetInventory() {
List<SteamInventoryItem> result = new List<SteamInventoryItem>(); List<SteamItem> result = new List<SteamItem>();
try { try {
JObject jObject = await WebBrowser.UrlGetToJObject("https://steamcommunity.com/my/inventory/json/753/6", Cookie).ConfigureAwait(false); JObject jObject = await WebBrowser.UrlGetToJObject("https://steamcommunity.com/my/inventory/json/753/6", Cookie).ConfigureAwait(false);
IEnumerable<JToken> jTokens = jObject.SelectTokens("$.rgInventory.*"); IEnumerable<JToken> jTokens = jObject.SelectTokens("$.rgInventory.*");
foreach (JToken jToken in jTokens) { foreach (JToken jToken in jTokens) {
result.Add(JsonConvert.DeserializeObject<SteamInventoryItem>(jToken.ToString())); result.Add(JsonConvert.DeserializeObject<SteamItem>(jToken.ToString()));
} }
} catch (Exception e) { } catch (Exception e) {
Logging.LogGenericException(Bot.BotName, e); Logging.LogGenericException(Bot.BotName, e);
@@ -389,7 +388,7 @@ namespace ArchiSteamFarm {
return result; return result;
} }
internal async Task<bool> SendTradeOffer(List<SteamInventoryItem> items, ulong partnerID, string token = null) { internal async Task<bool> SendTradeOffer(List<SteamItem> items, ulong partnerID, string token = null) {
if (items == null || partnerID == 0) { if (items == null || partnerID == 0) {
return false; return false;
} }
@@ -401,11 +400,11 @@ namespace ArchiSteamFarm {
SteamTradeOfferRequest trade = new SteamTradeOfferRequest(); SteamTradeOfferRequest trade = new SteamTradeOfferRequest();
foreach (SteamInventoryItem item in items) { foreach (SteamItem item in items) {
trade.me.assets.Add(new SteamTradeItem() { trade.me.assets.Add(new SteamItem() {
appid = 753, appid = "753",
contextid = 6, contextid = "6",
amount = int.Parse(item.amount), amount = item.amount,
assetid = item.id assetid = item.id
}); });
} }

View File

@@ -47,6 +47,7 @@ namespace ArchiSteamFarm {
internal static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 303700, 335590, 368020, 425280 }; internal static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 303700, 335590, 368020, 425280 };
private readonly string ConfigFile, LoginKeyFile, MobileAuthenticatorFile, SentryFile; private readonly string ConfigFile, LoginKeyFile, MobileAuthenticatorFile, SentryFile;
private readonly Timer SendItemsTimer;
internal readonly string BotName; internal readonly string BotName;
internal readonly ArchiHandler ArchiHandler; internal readonly ArchiHandler ArchiHandler;
@@ -57,7 +58,6 @@ namespace ArchiSteamFarm {
internal readonly SteamFriends SteamFriends; internal readonly SteamFriends SteamFriends;
internal readonly SteamUser SteamUser; internal readonly SteamUser SteamUser;
internal readonly Trading Trading; internal readonly Trading Trading;
private Timer Timer;
private bool KeepRunning = true; private bool KeepRunning = true;
private bool InvalidPassword = false; private bool InvalidPassword = false;
@@ -72,7 +72,6 @@ namespace ArchiSteamFarm {
internal string SteamPassword { get; private set; } = "null"; internal string SteamPassword { get; private set; } = "null";
internal string SteamNickname { get; private set; } = "null"; internal string SteamNickname { get; private set; } = "null";
internal string SteamApiKey { 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 string SteamParentalPIN { get; private set; } = "0";
internal ulong SteamMasterID { get; private set; } = 0; internal ulong SteamMasterID { get; private set; } = 0;
internal ulong SteamMasterClanID { 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 UseAsfAsMobileAuthenticator { get; private set; } = false;
internal bool ShutdownOnFarmingFinished { get; private set; } = false; internal bool ShutdownOnFarmingFinished { get; private set; } = false;
internal bool SendOnFarmingFinished { 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<uint> Blacklist { get; private set; } = new HashSet<uint>(); internal HashSet<uint> Blacklist { get; private set; } = new HashSet<uint>();
internal bool Statistics { get; private set; } = true; internal bool Statistics { get; private set; } = true;
@@ -176,6 +176,15 @@ namespace ArchiSteamFarm {
CardsFarmer = new CardsFarmer(this); CardsFarmer = new CardsFarmer(this);
Trading = new Trading(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 // Before attempting to connect, initialize our list of CMs
SteamDirectory.Initialize().Wait(); SteamDirectory.Initialize().Wait();
@@ -344,7 +353,7 @@ namespace ArchiSteamFarm {
SendOnFarmingFinished = bool.Parse(value); SendOnFarmingFinished = bool.Parse(value);
break; break;
case "SendTradePeriod": case "SendTradePeriod":
SendTradePeriod = uint.Parse(value); SendTradePeriod = byte.Parse(value);
break; break;
case "Blacklist": case "Blacklist":
Blacklist.Clear(); Blacklist.Clear();
@@ -503,7 +512,7 @@ namespace ArchiSteamFarm {
token = bot.SteamTradeToken; token = bot.SteamTradeToken;
} }
List<SteamInventoryItem> inventory = await bot.ArchiWebHandler.GetInventory().ConfigureAwait(false); List<SteamItem> inventory = await bot.ArchiWebHandler.GetInventory().ConfigureAwait(false);
if (inventory.Count == 0) { if (inventory.Count == 0) {
return "Nothing to send, inventory seems empty!"; return "Nothing to send, inventory seems empty!";
} }
@@ -1044,15 +1053,6 @@ namespace ArchiSteamFarm {
Trading.CheckTrades(); Trading.CheckTrades();
await CardsFarmer.StartFarming().ConfigureAwait(false); 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; break;
case EResult.NoConnection: case EResult.NoConnection:
case EResult.ServiceUnavailable: case EResult.ServiceUnavailable:

View File

@@ -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; }
}
}

View File

@@ -37,6 +37,12 @@ namespace ArchiSteamFarm {
[JsonProperty] [JsonProperty]
internal string assetid { get; set; } internal string assetid { get; set; }
[JsonProperty]
internal string id {
get { return assetid; }
set { assetid = value; }
}
[JsonProperty] [JsonProperty]
internal string currencyid { get; set; } internal string currencyid { get; set; }
@@ -51,5 +57,8 @@ namespace ArchiSteamFarm {
[JsonProperty] [JsonProperty]
internal bool missing { get; set; } internal bool missing { get; set; }
[JsonProperty]
internal int pos { get; set; }
} }
} }

View File

@@ -26,9 +26,9 @@ using Newtonsoft.Json;
using System.Collections.Generic; using System.Collections.Generic;
namespace ArchiSteamFarm { namespace ArchiSteamFarm {
internal class SteamTradeItemList { internal class SteamItemList {
[JsonProperty] [JsonProperty]
internal List<SteamTradeItem> assets { get; set; } = new List<SteamTradeItem>(); internal List<SteamItem> assets { get; set; } = new List<SteamItem>();
[JsonProperty] [JsonProperty]
internal List<string> currency { get; set; } = new List<string>(); internal List<string> currency { get; set; } = new List<string>();

View File

@@ -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; }
}
}

View File

@@ -33,9 +33,9 @@ namespace ArchiSteamFarm {
internal int version { get; set; } = 2; internal int version { get; set; } = 2;
[JsonProperty] [JsonProperty]
internal SteamTradeItemList me { get; set; } = new SteamTradeItemList(); internal SteamItemList me { get; set; } = new SteamItemList();
[JsonProperty] [JsonProperty]
internal SteamTradeItemList them { get; set; } = new SteamTradeItemList(); internal SteamItemList them { get; set; } = new SteamItemList();
} }
} }

View File

@@ -13,6 +13,7 @@
<!-- Type of the property is a tip for you that defines what values you can use --> <!-- Type of the property is a tip for you that defines what values you can use -->
<!-- bool - Boolean value that can be only "true" or "false" --> <!-- bool - Boolean value that can be only "true" or "false" -->
<!-- string - Any sequence of characters, unless stated otherwise (keep in mind escape table above), with special treatment of "null" value --> <!-- string - Any sequence of characters, unless stated otherwise (keep in mind escape table above), with special treatment of "null" value -->
<!-- byte - 8-bit unsigned integer, used mostly for small numbers (0-255) -->
<!-- uint - 32-bit unsigned integer, used mostly for steam appID --> <!-- uint - 32-bit unsigned integer, used mostly for steam appID -->
<!-- ulong - 64-bit unsigned (long) integer, used mostly for representing steamID64 --> <!-- ulong - 64-bit unsigned (long) integer, used mostly for representing steamID64 -->
<!-- HashSet(uint) - Comma-separated list of unique 32-bit unsigned integers --> <!-- HashSet(uint) - Comma-separated list of unique 32-bit unsigned integers -->
@@ -104,22 +105,25 @@
<!-- Personally I suggest leaving it at "false", unless you have a reason to close the process after all bots finished farming --> <!-- Personally I suggest leaving it at "false", unless you have a reason to close the process after all bots finished farming -->
<ShutdownOnFarmingFinished type="bool" value="false"/> <ShutdownOnFarmingFinished type="bool" value="false"/>
<!-- if this switch set to "true",the bot would try to send trade offer with all cards to master after farming is finished --> <!-- This switch defines if bot should send you all the items it farmed after farming is finished -->
<!-- for sucessfull trade offer bot needs SteamMasterID to be set properly --> <!-- Remember that in order to use this feature, SteamMasterID must be defined above -->
<!-- if the master is not a friend of this bot, SteamTradeToken would be needed also --> <!-- If SteamMasterID is not a friend of this bot, SteamTradeToken will also be needed to set below -->
<SendOnFarmingFinished type="bool" value="false"/> <SendOnFarmingFinished type="bool" value="false"/>
<!-- If you bot has a lot of cards to farm, and you don't want to wait till it farm them all, you can use this parameter --> <!-- This is a SteamTradeToken of SteamMasterID, which is required if bot doesn't have SteamMasterID on friend list -->
<!-- this setting is the time period of auto-sending bot->master trades in hours--> <!-- You can get the token here: http://steamcommunity.com/id/me/tradeoffers/privacy while being logged in as SteamMasterID -->
<!-- for example, if you want bot to send you trade offers once a day, set this to 24 --> <!-- The token has 8 characters and is written in the last part of trade URL link, starting after "&token=" -->
<!-- if value is "0" no automatic trade offers would be sent -->
<SendTradePeriod type="uint" value="0"/>
<!-- This is needed to send bot->master trades, only if master is not a friend of bot -->
<!-- To get this token go (as master!) here: http://steamcommunity.com/id/ryzhehvost/tradeoffers/privacy -->
<!-- the token is last part of link in the field "TradeURL", starting after "&token=" -->
<SteamTradeToken type="string" value="null"/> <SteamTradeToken type="string" value="null"/>
<!-- This switch defines if bot should send you trade offer with all farmed cards on regular basis -->
<!-- This can become useful if you have lots of games to farm and you don't want to wait for all of them to be farmed -->
<!-- However, if you have many bots running, it may become a bit spammy/intrusive, so it's not enabled by default -->
<!-- Remember that there is also "SendOnFarmingFinished" switch above, which is far less intrusive and can be used instead -->
<!-- This property defines how often bot should send you a trade offer, in hours -->
<!-- For example, setting this to "24" will result in a trade offer being sent once per day (24 hours) -->
<!-- Default value of "0" disables that feature -->
<SendTradePeriod type="byte" value="0"/>
<!-- This is comma-separated list of IDs that should not be considered for farming --> <!-- This is comma-separated list of IDs that should not be considered for farming -->
<!-- Default value includes appIDs that are wrongly appearing on the profile, e.g. Summer Sale, Winter Sale or Monster Summer Game --> <!-- Default value includes appIDs that are wrongly appearing on the profile, e.g. Summer Sale, Winter Sale or Monster Summer Game -->
<!-- In addition to blacklist defined here, ASF also has global blacklist, which is being updated on as-needed basis, so you don't need to update this entry --> <!-- In addition to blacklist defined here, ASF also has global blacklist, which is being updated on as-needed basis, so you don't need to update this entry -->