Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using SteamKit2;
- using SteamTrade;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace SteamBot
- {
- public class FileWatcher
- {
- private FileSystemWatcher fileSystemWatcher;
- private string FileToWatch = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "TradeRequests";
- private Bot Bot;
- private Log Log;
- private SteamWeb SteamWeb;
- public FileWatcher(Bot Bot, Log Log, SteamWeb SteamWeb)
- {
- this.Bot = Bot;
- this.Log = Log;
- this.SteamWeb = SteamWeb;
- fileSystemWatcher = new FileSystemWatcher(FileToWatch);
- fileSystemWatcher.EnableRaisingEvents = true;
- // Instruct the file system watcher to call the FileCreated method
- // when there are files created at the folder.
- fileSystemWatcher.Created += new FileSystemEventHandler(FileCreated);
- }
- public void FileCreated(Object Sender, FileSystemEventArgs Event)
- {
- if (Event.Name.StartsWith("Trade-Request-"))
- {
- SteamBot.TradeRequest.TradeRequestOffer Trade = JsonConvert.DeserializeObject<SteamBot.TradeRequest.TradeRequestOffer>(File.ReadAllText(Event.FullPath));
- Console.WriteLine(Trade.SteamID);
- // creating a new trade offer with token
- SteamID TradeUser = new SteamID(Trade.SteamID);
- var TradeOffer = Bot.NewTradeOffer(TradeUser);
- //offer.Items.AddMyItem(0, 0, 0);
- List<long> contextId = new List<long>();
- contextId.Add(2);
- GenericInventory TradeInventory = new GenericInventory(SteamWeb);
- TradeInventory.load(730, contextId, Trade.SteamID);
- List<ulong> itemsWanted = new List<ulong>();
- foreach (int assetId in Trade.ItemIDs)
- {
- itemsWanted.Add(Convert.ToUInt64(assetId));
- }
- foreach (GenericInventory.Item Item in TradeInventory.items.Values)
- {
- if (itemsWanted.Contains(Item.assetid)) {
- TradeOffer.Items.AddTheirItem(730, 2, Convert.ToInt64(Item.assetid));
- Log.Warn("Added item: " + TradeInventory.getDescription(Item.assetid).name);
- }
- }
- Log.Warn("Finished adding items...");
- if (TradeOffer.Items.NewVersion)
- {
- string newOfferId;
- Log.Warn("Created offer id.");
- // "token" should be replaced with the actual token from the other user
- if (TradeOffer.SendWithToken(out newOfferId, Trade.SteamToken))
- {
- Log.Success("Trade offer sent : Offer ID " + newOfferId);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement