Advertisement
Guest User

SteamBot Cant send trade offer

a guest
Aug 6th, 2018
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.03 KB | None | 0 0
  1. public override void OnMessage (string message, EChatEntryType type)
  2. {
  3.     if (message.StartsWith("@") && IsAdmin) // interpret commands (from admins only for now)
  4.     {
  5.         string[] messargs = message.Split(' ');
  6.  
  7.         switch (messargs[0])
  8.         {
  9.             case ("@help"):
  10.                 SendChatMessage("@help - Displays this help message");
  11.                 SendChatMessage("@buy [key-amount] - Sends you a trade offer for purchasing a Mann Co. Supply Crate Key.");
  12.                 SendChatMessage("@sell [key-amount] - Sends you a trade offer for selling a Mann Co. Supply Crate Key.");
  13.                 break;
  14.             case ("@buy"): // they wanna buy my keys!
  15.                 SendChatMessage("ALLOW ME TO PROCESS YOUR ORDER.");
  16.                 RefreshKeyRefVals();
  17.  
  18.                 if (messargs.Length < 2)
  19.                 {
  20.                     SendChatMessage("SORRY! PLEASE SPECIFY HOW MANY KEYS YOU WANT TO BUY.");
  21.                     Log.Info("They ({0}) wants NULL key(s).", OtherSID.ConvertToUInt64());
  22.                     break;
  23.                 }
  24.  
  25.                 UInt16 keyAmount = 1;
  26.                 if (UInt16.TryParse(messargs[1], out keyAmount))
  27.                 {
  28.                     if (keyAmount > NumOfKey)
  29.                     {
  30.                         SendChatMessage("SORRY! I DON'T HAVE THAT MANY KEYS.");
  31.                         break;
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     SendChatMessage("SORRY! I CAN'T GIVE YOU '{0}' KEYS.", messargs[1]);
  37.                     break;
  38.                 }
  39.                
  40.                 Log.Info("They ({0}) wants to buy {1} key(s) for {2}.", OtherSID.ConvertToUInt64(), keyAmount, Bot.SellKeysFor * keyAmount);
  41.                 SendChatMessage("YOU WILL GET {0} key(s) FOR {1}", keyAmount, Bot.SellKeysFor * keyAmount);
  42.  
  43.                 List<long> contextId = new List<long>(); contextId.Add(1);
  44.                 TradeOffer offer = Bot.NewTradeOffer(OtherSID);
  45.  
  46.                 UInt16 keysAdded = 0;
  47.                 Bot.GetInventory();
  48.                 foreach (var a in Bot.MyInventory.GetItemsByDefindex(5021))
  49.                 {
  50.                     offer.Items.AddMyItem(440, 1, (long) a.Id);
  51.                     keysAdded++;
  52.                     if (keysAdded == keyAmount)
  53.                         break;
  54.                 }
  55.  
  56.                 TF2Value metalAdded = TF2Value.Zero;
  57.                 GetOtherInventory();
  58.                 foreach (var a in OtherInventory.GetItemsByDefindex(5002)) // ref
  59.                 {
  60.                     if (metalAdded + TF2Value.Refined <= Bot.SellKeysFor * keysAdded)
  61.                     {
  62.                         offer.Items.AddMyItem(440, 1, (long)a.Id);
  63.                         metalAdded += TF2Value.Refined;
  64.                     }
  65.                     else
  66.                         break;
  67.                 }
  68.                 foreach (var a in OtherInventory.GetItemsByDefindex(5001)) // reclm
  69.                 {
  70.                     if (metalAdded + TF2Value.Reclaimed <= Bot.SellKeysFor * keysAdded)
  71.                     {
  72.                         offer.Items.AddMyItem(440, 1, (long)a.Id);
  73.                         metalAdded += TF2Value.Reclaimed;
  74.                     }
  75.                     else
  76.                         break;
  77.                 }
  78.                 foreach (var a in OtherInventory.GetItemsByDefindex(5000)) // scrap
  79.                 {
  80.                     if (metalAdded + TF2Value.Scrap <= Bot.SellKeysFor * keysAdded)
  81.                     {
  82.                         offer.Items.AddMyItem(440, 1, (long)a.Id);
  83.                         metalAdded += TF2Value.Scrap;
  84.                     }
  85.                     else
  86.                         break;
  87.                 }
  88.  
  89.                 if (metalAdded < Bot.SellKeysFor * keysAdded)
  90.                 {
  91.                     SendChatMessage("SORRY! YOU DON'T HAVE ENOUGH PURE METAL.");
  92.                     if (!IsAdmin)
  93.                     {
  94.                         offer = null;
  95.                         break;
  96.                     }
  97.                     else
  98.                         SendChatMessage("but who cares youre an admin");
  99.                 }
  100.  
  101.                 SendChatMessage("PREPARING TO SEND TRADE OFFER.");
  102.                 string offerID = "";
  103.                 string myinfo = "IF THERE WAS AN ISSUE WITH YOUR TRADE, LET MY MANAGER KNOW: https://steamcommunity.com/profiles/76561198132899910";
  104.                 bool offersent = false;
  105.                 for (int i = 0; i < 20; i++) // keep trying until it succeeds (BUT IT NEVER DOES!)
  106.                 {
  107.                     try { offersent = offer.Send(out offerID, myinfo); }
  108.                     catch { }
  109.  
  110.                     if (offersent) break;
  111.                 }
  112.  
  113.                 if (offersent)
  114.                 {
  115.                     Log.Info("Sent trade to {0}. OfferID: {1}", OtherSID.ConvertToUInt64(), offerID);
  116.                 }
  117.                 else
  118.                 {
  119.                     SendChatMessage("SORRY! I COULDN'T SEND THE TRADE OFFER. THIS IS PROBABLY A PROBLEM WITH STEAM, PLEASE TRY AGAIN LATER.");
  120.                 }
  121.  
  122.                 break;
  123.             case ("@sell"): // they wanna GET RID OF their keys!
  124.                 if (message == "@sell tf2key") { }
  125.                 break;
  126.             default:
  127.                 SendChatMessage("UNKOWN COMMAND! PLEASE TYPE `@help` FOR A LIST OF COMMANDS");
  128.                 break;
  129.         }
  130.     }
  131.     else
  132.         SendChatMessage("SORRY, THIS BOT IS NOT CURRENTLY AVAILABLE FOR PUBLIC USE. SEE YOU SOON!");
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement