Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override void OnMessage (string message, EChatEntryType type)
- {
- if (message.StartsWith("@") && IsAdmin) // interpret commands (from admins only for now)
- {
- string[] messargs = message.Split(' ');
- switch (messargs[0])
- {
- case ("@help"):
- SendChatMessage("@help - Displays this help message");
- SendChatMessage("@buy [key-amount] - Sends you a trade offer for purchasing a Mann Co. Supply Crate Key.");
- SendChatMessage("@sell [key-amount] - Sends you a trade offer for selling a Mann Co. Supply Crate Key.");
- break;
- case ("@buy"): // they wanna buy my keys!
- SendChatMessage("ALLOW ME TO PROCESS YOUR ORDER.");
- RefreshKeyRefVals();
- if (messargs.Length < 2)
- {
- SendChatMessage("SORRY! PLEASE SPECIFY HOW MANY KEYS YOU WANT TO BUY.");
- Log.Info("They ({0}) wants NULL key(s).", OtherSID.ConvertToUInt64());
- break;
- }
- UInt16 keyAmount = 1;
- if (UInt16.TryParse(messargs[1], out keyAmount))
- {
- if (keyAmount > NumOfKey)
- {
- SendChatMessage("SORRY! I DON'T HAVE THAT MANY KEYS.");
- break;
- }
- }
- else
- {
- SendChatMessage("SORRY! I CAN'T GIVE YOU '{0}' KEYS.", messargs[1]);
- break;
- }
- Log.Info("They ({0}) wants to buy {1} key(s) for {2}.", OtherSID.ConvertToUInt64(), keyAmount, Bot.SellKeysFor * keyAmount);
- SendChatMessage("YOU WILL GET {0} key(s) FOR {1}", keyAmount, Bot.SellKeysFor * keyAmount);
- List<long> contextId = new List<long>(); contextId.Add(1);
- TradeOffer offer = Bot.NewTradeOffer(OtherSID);
- UInt16 keysAdded = 0;
- Bot.GetInventory();
- foreach (var a in Bot.MyInventory.GetItemsByDefindex(5021))
- {
- offer.Items.AddMyItem(440, 1, (long) a.Id);
- keysAdded++;
- if (keysAdded == keyAmount)
- break;
- }
- TF2Value metalAdded = TF2Value.Zero;
- GetOtherInventory();
- foreach (var a in OtherInventory.GetItemsByDefindex(5002)) // ref
- {
- if (metalAdded + TF2Value.Refined <= Bot.SellKeysFor * keysAdded)
- {
- offer.Items.AddMyItem(440, 1, (long)a.Id);
- metalAdded += TF2Value.Refined;
- }
- else
- break;
- }
- foreach (var a in OtherInventory.GetItemsByDefindex(5001)) // reclm
- {
- if (metalAdded + TF2Value.Reclaimed <= Bot.SellKeysFor * keysAdded)
- {
- offer.Items.AddMyItem(440, 1, (long)a.Id);
- metalAdded += TF2Value.Reclaimed;
- }
- else
- break;
- }
- foreach (var a in OtherInventory.GetItemsByDefindex(5000)) // scrap
- {
- if (metalAdded + TF2Value.Scrap <= Bot.SellKeysFor * keysAdded)
- {
- offer.Items.AddMyItem(440, 1, (long)a.Id);
- metalAdded += TF2Value.Scrap;
- }
- else
- break;
- }
- if (metalAdded < Bot.SellKeysFor * keysAdded)
- {
- SendChatMessage("SORRY! YOU DON'T HAVE ENOUGH PURE METAL.");
- if (!IsAdmin)
- {
- offer = null;
- break;
- }
- else
- SendChatMessage("but who cares youre an admin");
- }
- SendChatMessage("PREPARING TO SEND TRADE OFFER.");
- string offerID = "";
- string myinfo = "IF THERE WAS AN ISSUE WITH YOUR TRADE, LET MY MANAGER KNOW: https://steamcommunity.com/profiles/76561198132899910";
- bool offersent = false;
- for (int i = 0; i < 20; i++) // keep trying until it succeeds (BUT IT NEVER DOES!)
- {
- try { offersent = offer.Send(out offerID, myinfo); }
- catch { }
- if (offersent) break;
- }
- if (offersent)
- {
- Log.Info("Sent trade to {0}. OfferID: {1}", OtherSID.ConvertToUInt64(), offerID);
- }
- else
- {
- SendChatMessage("SORRY! I COULDN'T SEND THE TRADE OFFER. THIS IS PROBABLY A PROBLEM WITH STEAM, PLEASE TRY AGAIN LATER.");
- }
- break;
- case ("@sell"): // they wanna GET RID OF their keys!
- if (message == "@sell tf2key") { }
- break;
- default:
- SendChatMessage("UNKOWN COMMAND! PLEASE TYPE `@help` FOR A LIST OF COMMANDS");
- break;
- }
- }
- else
- SendChatMessage("SORRY, THIS BOT IS NOT CURRENTLY AVAILABLE FOR PUBLIC USE. SEE YOU SOON!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement