Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SteamTrade;
- using SteamKit2;
- using System.Timers;
- using System.IO;
- using System.Windows.Forms;
- using System.Management;
- using System.Net.Mail;
- using System.Net;
- using System.Threading.Tasks;
- namespace SteamBot
- {
- public class CustomBot : UserHandler
- {
- #region "Universal Variables"
- BotSettings mySettings;
- bool invalidSettings = false;
- public int chatMode = 0;
- public const int STEAMCHAT = 0;
- public const int TRADECHAT = 1;
- Schema currentSchema;
- string botBasics = "AfredoBot All items";
- #endregion
- #region "SteamChat Variables"
- //Used in On Friend Add
- string welcomeMessage = "Welcome to a automated trading experience! I buy kits.Type 'Stock' to see my metal in stock. And 'owner' to see who my owner is.";
- bool autoSendTradeRequest = false;
- static int inviteTimerInterval = 2000;
- System.Timers.Timer inviteMsgTimer = new System.Timers.Timer(inviteTimerInterval);
- //Used in Messages
- public int mode = 0;
- public const int HELPMODE = 0;
- public const int BUYMODE = 1;
- public const int SELLMODE = 2;
- public const int TESTMODE = 3;
- public const int ADMINMODE = 4;
- public bool passcodeMode = false;
- string ownerInfoMessage = "Here's a link to my owner's profile http://steamcommunity.com/profiles/76561198024335163/ ";
- int priceSwitch = 0;
- int removalSwitch = 0;
- int currentItemDefindex;
- string currentItemName;
- double currentItemSellPrice;
- double currentItemBuyPrice;
- #endregion
- #region "Trade Variables"
- bool isThinking;
- bool buyHats;
- bool remove;
- string tradeStartMessage = "Follow the instructions: Type 'buy' to start buying items. Type the name of an item to get its current price. Type 'stock' to see how much metal I have and 'price' to see the price of all of my items.";
- string tradeSuccessMessage = "Trade was successful! Please join our group http://steamcommunity.com/groups/MindlessTradeBots I frequently empty my friends list so it will make it easy to find me again.";
- int UserMetalAdded, UserScrapAdded, UserRecAdded, UserRefAdded, UserKeysAdded, BotKeysAdded, BotMetalAdded, BotScrapAdded, BotRecAdded, BotRefAdded, InventoryMetal, InventoryScrap, InventoryRec, InventoryRef, InventoryKeys, OverpayNumKeys, ExcessInScrap, PreviousKeys, WhileLoop, InvalidItem = 0;
- double ExcessRefined = 0.0;
- decimal userOwed;
- bool overPay = false, tooMuchOffered = false, InGroupChat, TimerEnabled, HasRun, HasErrorRun, buyingItems, ChooseDonate, AskOverpay, IsOverpaying, HasCounted = false;
- SteamID currentSID;
- List<Schema.Item> myOffer;
- List<Inventory.Item> userOffer;
- #endregion
- public CustomBot(Bot bot, SteamID sid) : base(bot, sid) { }
- #region "Bot_Operations"
- #region "SteamChat"
- public override bool OnFriendAdd()
- {
- Bot.log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " (" + OtherSID.ToString() + ") added me!");
- inviteMsgTimer.Interval = inviteTimerInterval;
- inviteMsgTimer.Elapsed += (sender, e) => OnInviteTimerElapsed(sender, e, EChatEntryType.ChatMsg);
- inviteMsgTimer.Enabled = true;
- return true;
- }
- public override void OnLoginCompleted()
- {
- mySettings = new BotSettings();
- mySettings = null;
- if (File.Exists(Directory.GetCurrentDirectory() + "//botSettings.xml"))
- {
- try
- {
- mySettings = new BotSettings();
- mySettings = mySettings.loadBotSettings();
- }
- catch
- {
- mySettings = null;
- }
- }
- }
- public override void OnChatRoomMessage(SteamID chatID, SteamID sender, string message)
- {
- }
- public override void OnFriendRemove() { }
- public override void OnMessage(string message, EChatEntryType type)
- {
- if (currentSchema == null)
- {
- currentSchema = new Schema();
- currentSchema = Schema.FetchSchema(Bot.apiKey);
- }
- message = message.ToLower();
- if (message == "reset all settings")
- {
- mySettings = new BotSettings();
- mySettings = mySettings.generateBotSettings("s3cr3t", 7, new List<BotSettings.Item>());
- }
- if (mySettings == null)
- {
- try
- {
- mySettings = new BotSettings();
- mySettings = mySettings.loadBotSettings();
- }
- catch
- {
- invalidSettings = true;
- if (IsAdmin)
- {
- sendChatMessage("ERROR: Something is wrong with the BotSettings file. I will not open trades until this is fixed");
- sendChatMessage("Generate valid settings with the command 'reset all settings'");
- }
- else
- {
- sendChatMessage("This bot is not yet configured to trade items. Contact my owner for more info!");
- }
- }
- }
- if (message.Equals("self.restart"))
- {
- if (IsAdmin)
- {
- var filename = System.Reflection.Assembly.GetExecutingAssembly().Location;
- System.Diagnostics.Process.Start(filename);
- Environment.Exit(0);
- }
- }
- else if (message.Equals("exit") || message.Equals("main menu") || message.Equals("menu") || message.Equals("Exit") || message.Equals("Home") || message.Equals("home"))
- {
- mode = HELPMODE;
- passcodeMode = false;
- }
- if (passcodeMode) //switch for if you are trying to login as an admin
- {
- if (message.Equals(mySettings.adminPassword)) //If the password is valid go to admin mode
- {
- mode = ADMINMODE;
- passcodeMode = false;
- priceSwitch = 0;
- removalSwitch = 0;
- sendChatMessage("You are now in admin mode. Valid commands include: set price, set password [newpassword] [confirmnewpassword], remove item, set key [price of keys in scrap], remove friends, craft scrap, craft rec, craft ref, block craft");
- }
- else
- {
- sendChatMessage("Sorry that passcode was invalid, please either try again or use 'menu' to get back to the main menu");
- return;
- }
- }
- switch (mode)
- {
- case HELPMODE:
- switch (message)
- {
- case "admin":
- case "administrator":
- case "login":
- if (IsAdmin)
- {
- sendChatMessage("Enter your admin passcode");
- passcodeMode = true;
- }
- else
- {
- sendChatMessage("Sorry, this steamID has not been added to the administrators list");
- }
- break;
- case "purchase":
- case "buy":
- case "sell":
- case "sale":
- case "prices":
- mySettings = new BotSettings();
- mySettings = mySettings.loadBotSettings();
- priceResponse(STEAMCHAT);
- break;
- case "test":
- mySettings = new BotSettings();
- mySettings = mySettings.loadBotSettings();
- sendChatMessage("Entering secret test mode, do your shiz");
- mode = TESTMODE;
- break;
- case "owner":
- sendChatMessage(ownerInfoMessage);
- break;
- case "stock":
- case "inventory":
- case "stocks":
- stockResponse(STEAMCHAT);
- break;
- default:
- mode = HELPMODE;
- sendChatMessage("Send me a trade request to start trading");
- sendChatMessage("Valid chat commands are: stock, owner");
- if (IsAdmin)
- {
- sendChatMessage("Psst. I noticed you are a registered admin. Type 'login' to access admin features.");
- }
- break;
- }
- break;
- case ADMINMODE:
- adminResponse(message);
- break;
- case TESTMODE:
- testResponse(message);
- break;
- default:
- mode = HELPMODE;
- sendChatMessage("Send me a trade request to start trading");
- sendChatMessage("Valid chat commands are: stock, owner");
- if (IsAdmin)
- {
- sendChatMessage("Psst. I noticed you are a registered admin. Type 'login' to access admin features.");
- }
- break;
- }
- }
- #endregion
- #region "Trade"
- public override bool OnTradeRequest()
- {
- if (currentSchema == null)
- {
- currentSchema = new Schema();
- currentSchema = Schema.FetchSchema(Bot.apiKey);
- }
- if (mySettings == null)
- {
- try
- {
- mySettings = new BotSettings();
- mySettings = mySettings.loadBotSettings();
- }
- catch
- {
- invalidSettings = true;
- if (IsAdmin)
- {
- sendChatMessage("ERROR: Something is wrong with the BotSettings file. I will not open trades until this is fixed");
- sendChatMessage("Generate valid settings with the command 'reset all settings'");
- }
- else
- {
- sendChatMessage("This bot is not yet configured to trade items. Contact my owner for more info!");
- }
- return false;
- }
- }
- return true;
- }
- public override void OnTradeError(string error)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID,
- EChatEntryType.ChatMsg,
- "Error: " + error + "."
- );
- Bot.log.Warn(error);
- if (!HasErrorRun)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "It looks like there was a error! Please check here steam might be down http://steamgaug.es/ ! Here is a link to my owner if you continue to have problems http://steamcommunity.com/profiles/76561198024335163 Please go to my profile and see FAQ for help before adding my owner!");
- HasErrorRun = true;
- }
- Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
- }
- public override void OnTradeTimeout()
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg,
- "Sorry, but you were either AFK or took too long and the trade was canceled.");
- Bot.log.Warn("User was kicked because he was AFK.");
- Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
- }
- public override void OnTradeInit()
- {
- ReInit();
- TradeCountInventory(false);
- Bot.SteamFriends.SetPersonaState(EPersonaState.Busy);
- Trade.SendMessage("Welcome to ALFREDO's Mindless BOT.");
- Trade.SendMessage("Add your kit and I will add metal automatically.");
- }
- public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
- {
- if (IsAdmin && mode == ADMINMODE)
- {
- Trade.SendMessage("Warning - I don't pay for items if you are in admin mode!");
- return;
- }
- if (!ChooseDonate)
- {
- Trade.SendMessage("You have added an item!");
- if (inventoryItem.AppId == 440)
- {
- userOffer.Add(inventoryItem);
- }
- else
- {
- Trade.SendMessage("That's an item from the wrong game. Remove it or I'll end up treating it like a donation since I don't know what it is!");
- }
- doPayment(buyingItems);
- }
- }
- public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) {
- if (IsAdmin && mode == ADMINMODE)
- {
- return;
- }
- isThinking = true;
- if (inventoryItem.AppId == 440){
- userOffer.Remove(inventoryItem);
- Trade.SendMessage("You have removed an item! Recalculating offer value");
- Bot.log.Warn("User removed " + schemaItem.ItemName);
- }
- doPayment(buyingItems);
- isThinking = false;
- }
- bool quantitySwitch = false;
- int tradeBuySwitch = 0;
- int tradeGame;
- int tradeCard;
- string orderedItem = null;
- int itemID = 0;
- Dictionary<int, string> orders = new Dictionary<int, string>();
- public override void OnTradeMessage(string message)
- {
- message = message.ToLower();
- if (IsAdmin && mode == ADMINMODE) //Admins can do whatever to the bot, but only when they have logged in to their password
- {
- switch (message)
- {
- case "metal":
- case "dump metal":
- case "get metal":
- dumpMetal(); //lets you collect all of the bot's metal
- break;
- }
- switch (message)
- {
- case "items":
- case "dump items":
- case "get items":
- dumpItems(); //lets you collect all of the bot's items (by items, it means things on your list, not random weapons and crap you might be storing in the bot's inventory
- break;
- default:
- Trade.SendMessage("You are currently in admin mode. Normal trade operations are suspended. Any trade you make will be acceptable to the bot, use 'dump metal' to get all of the bot's currency and 'dump hats' to get all of the bot's hats");
- break;
- }
- return;
- }
- if (message == "exit")
- {
- tradeBuySwitch = 0;
- }
- else if (tradeBuySwitch > 0)
- {
- switch(tradeBuySwitch)
- {
- case 1:
- itemID = getItemId(message, TRADECHAT);
- Bot.log.Info("User is searching for " + getItemName(itemID));
- if (itemID != null && itemID > 0)
- {
- Trade.SendMessage("How many of " + getItemName(itemID) + " do you want to buy?");
- tradeBuySwitch = tradeBuySwitch + 1;
- return;
- }
- else
- {
- Trade.SendMessage("Please check your spelling. Go to my profile for help if needed.");
- return;
- }
- case 2:
- if (!IsNumeric(message))
- {
- Trade.SendMessage("Please enter a whole number only.");
- return;
- }
- else
- {
- if (Trade.AddAllItemsByDefindex(itemID, (uint)Int32.Parse(message)) < (uint)Int32.Parse(message))
- {
- Trade.SendMessage("Added as many of that item as I can.");
- }
- Trade.SendMessage("Added " + evaluateMyOffer(myOffer) + " scrap worth of items.");
- Trade.SendMessage("Done adding the requested items. Request another item now.");
- tradeBuySwitch = 1;
- itemID = 0;
- }
- return;
- }
- }
- else if (message == "prices")
- {
- priceResponse(TRADECHAT);
- }
- else if (message == "stock")
- {
- stockResponse(TRADECHAT);
- }
- else if (message == "donate")
- {
- Trade.SendMessage("Thanks for donating, just put up your items to donate!");
- foreach (var item in Trade.MyInventory.Items) //so people can't use donate mode to trade
- {
- Trade.RemoveItem(item.Id);
- }
- myOffer = new List<Schema.Item>();
- ChooseDonate = true;
- return;
- }
- else if (message.Equals("continue"))
- {
- overPay = true;
- Trade.SendMessage("You have just enabled overpaying - if you set yourself as ready to trade while offering too much I will treat it as a donation. To disable this function use 'reset trade'");
- return;
- }
- else if (message.Equals("reset trade"))
- {
- if (overPay)
- {
- Trade.SendMessage("You have disabled overpaying. If you would like to overpay use 'overpay on'");
- overPay = false;
- }
- foreach (var item in Trade.MyInventory.Items) //so people can't use donate mode to trade
- {
- Trade.RemoveItem(item.Id);
- }
- myOffer = new List<Schema.Item>();
- Trade.SendMessage("Trade has been reset");
- return;
- }
- else if (message.Equals("help"))
- {
- if (buyHats)
- {
- Trade.SendMessage("You are currently in buy mode. Type the names of items you want to buy separated by comas or on different lines for me to add them to trade! Type '/info' to get information about prices");
- }
- else
- {
- Trade.SendMessage("Type 'buy' to enter buy mode.");
- Trade.SendMessage("Type 'stock' to see what metal I have and type 'prices' to see all of my prices and hats. Type donate if you want to donate items.");
- }
- }
- else if (message.Equals("buy"))
- {
- tradeBuySwitch++;
- Trade.SendMessage("You are now in buy mode. To exit buy mode type 'exit' (without the quotes).");
- Trade.SendMessage("Enter part of the item name you want to buy");
- }
- }
- public override void OnTradeReady(bool ready)
- {
- Trade.Poll();
- if (!ready)
- {
- Trade.SetReady(false);
- }
- else
- {
- if (isThinking)
- {
- Trade.SendMessage("Sorry, I need to reprocess your trade, uncheck trade ready to continue");
- return;
- }
- Bot.log.Success("User is ready to trade!");
- if ((Validate() && !isThinking && evaluateUserOffer(userOffer) > 0) || (IsAdmin && mode == ADMINMODE) || (ChooseDonate)) //check that the trade is fair, only allow unfair trades if in admin mode
- {
- Trade.SetReady(true);
- }
- else if (tooMuchOffered)
- {
- Trade.SendMessage("You have offered too much, use 'continue' and resend your trade requesti if you want to overpay");
- }
- else //if somethings up just recheck everything
- {
- Trade.SendMessage("Sorry, something about this trade is not right let me recheck everything real quick");
- doPayment(buyingItems);
- }
- }
- }
- public override void OnTradeAccept()
- {
- bool didSomething = false;
- if ((Validate()) || (IsAdmin && mode == ADMINMODE) || ChooseDonate)
- {
- bool success = Trade.AcceptTrade();
- if (success) //makes sure trades were successfull, steam's a bitch about this and will still pretend the trade failed on some large trades, but everyone will get paid
- {
- Log.Success("Trade was successful!");
- sendChatMessage(tradeSuccessMessage);
- Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
- }
- else
- {
- Log.Warn("Trade might have failed.");
- Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
- }
- }
- OnTradeClose();
- if (InventoryScrap < 9)
- {
- ulong[] smelt = new ulong[1];
- Bot.SetGamePlaying(440);
- Bot.GetInventory();
- Inventory myInventory = Bot.MyInventory;
- foreach (Inventory.Item item in myInventory.Items)
- {
- if (item.Defindex == 5001)
- {
- smelt[0] = item.Id;
- SteamBot.TF2GC.Crafting.CraftItems(Bot, smelt);
- didSomething = true;
- break;
- }
- }
- if (!didSomething)
- {
- foreach (Inventory.Item item in Bot.MyInventory.Items)
- {
- if (item.Defindex == 5002)
- {
- smelt[0] = item.Id;
- SteamBot.TF2GC.Crafting.CraftItems(Bot, smelt);
- didSomething = true;
- break;
- }
- }
- }
- }
- Bot.SetGamePlaying(0);
- }
- public bool Validate()
- {
- List<Inventory.Item> hypoOffer = new List<Inventory.Item>(); //hypothetical offer, let's check everything they offered again as if it were a new offer
- if (InvalidItem > 0)
- {
- Trade.SendMessage("You have invalid items, please remove them to complete the trade, scroll up to see which items they were.");
- return false;
- }
- foreach (ulong id in Trade.OtherOfferedItems)
- {
- hypoOffer.Add(Trade.OtherInventory.GetItem(id));
- }
- if (!overPay)
- {
- if (evaluateMyOffer(myOffer) == evaluateUserOffer(userOffer)) //if we are paying the right amount
- {
- if (evaluateUserOffer(userOffer) == evaluateUserOffer(hypoOffer)) //and they are giving the right amount of stuff
- {
- return true;
- }
- }
- else if (evaluateMyOffer(myOffer) < evaluateUserOffer(userOffer))
- {
- if (evaluateUserOffer(userOffer) == evaluateUserOffer(hypoOffer)) //and they are giving the right amount of stuff
- {
- tooMuchOffered = true;
- }
- }
- }
- if (overPay)
- {
- if (evaluateMyOffer(myOffer) <= evaluateUserOffer(userOffer)) //if our offer is less than theirs but they are overpaying than who cares
- {
- if (evaluateUserOffer(userOffer) == evaluateUserOffer(hypoOffer))//but be sure they aren't lying
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #endregion
- #region "Payment Operations"
- public void ReInit()
- {
- UserMetalAdded = 0;
- UserRefAdded = 0;
- UserRecAdded = 0;
- UserScrapAdded = 0;
- UserKeysAdded = 0;
- BotKeysAdded = 0;
- BotMetalAdded = 0;
- BotRefAdded = 0;
- BotRecAdded = 0;
- BotScrapAdded = 0;
- ExcessRefined = 0.0;
- WhileLoop = 0;
- InvalidItem = 0;
- HasErrorRun = false;
- OverpayNumKeys = 0;
- PreviousKeys = 0;
- ExcessInScrap = 0;
- ChooseDonate = false;
- AskOverpay = false;
- IsOverpaying = false;
- HasCounted = false;
- currentSID = OtherSID;
- buyingItems = false;
- userOwed = 0;
- userOffer = new List<Inventory.Item>();
- myOffer = new List<Schema.Item>();
- isThinking = false;
- tooMuchOffered = false;
- buyHats = false;
- remove = false;
- Bot.GetInventory();
- Bot.GetOtherInventory(OtherSID);
- }
- public void TradeCountInventory(bool message)
- {
- // Let's count our inventory
- Inventory.Item[] inventory = Trade.MyInventory.Items;
- InventoryMetal = 0;
- InventoryKeys = 0;
- InventoryRef = 0;
- InventoryRec = 0;
- InventoryScrap = 0;
- foreach (Inventory.Item item in inventory)
- {
- var schemaItem = Trade.CurrentSchema.GetItem(item.Defindex);
- if (item.Defindex == 5000)
- {
- InventoryMetal++;
- InventoryScrap++;
- }
- else if (item.Defindex == 5001)
- {
- InventoryMetal += 3;
- InventoryRec++;
- }
- else if (item.Defindex == 5002)
- {
- InventoryMetal += 9;
- InventoryRef++;
- }
- else if (item.Defindex == 5021)
- {
- InventoryKeys++;
- }
- }
- if (message)
- {
- double MetalToRef = (InventoryMetal / 9.0) - 0.01;
- string refined = string.Format("{0:N2}", MetalToRef);
- Trade.SendMessage("I have " + refined + " ref (" + InventoryRef + " ref, " + InventoryRec + " rec, and " + InventoryScrap + " scrap) and " + InventoryKeys + " key(s) in my backpack.");
- Bot.log.Success("Current stock: I have " + refined + " ref (" + InventoryRef + " ref, " + InventoryRec + " rec, and " + InventoryScrap + " scrap) and " + InventoryKeys + " key(s) in my backpack.");
- }
- HasCounted = true;
- }
- public double evaluateMyOffer(List<Schema.Item> offer)
- {
- double totalValue = 0;
- if (mySettings == null)
- {
- mySettings.loadBotSettings();
- }
- foreach (ulong itemID in Trade.MyOfferedItems)
- {
- Inventory.Item item = Bot.MyInventory.GetItem(itemID);
- bool gotPrice = false;
- if (item.Defindex == 5021)
- {
- totalValue = totalValue + mySettings.scrapPerKey;
- gotPrice = true;
- }
- else if (item.Defindex == 5000)
- {
- totalValue = totalValue + 1;
- gotPrice = true;
- }
- else if (item.Defindex == 5001)
- {
- totalValue = totalValue + 3;
- gotPrice = true;
- }
- else if (item.Defindex == 5002)
- {
- totalValue = totalValue + 9;
- gotPrice = true;
- }
- else
- {
- foreach (BotSettings.Item price in mySettings.items)
- {
- if (price.defindex == item.Defindex)
- {
- gotPrice = true;
- totalValue = totalValue + price.sellPrice;
- }
- }
- }
- if (gotPrice == false)
- {
- if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && (currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
- {
- totalValue = totalValue + .5;
- gotPrice = true;
- }
- else
- {
- Bot.log.Info("Added an Item I don't recognize");
- }
- // Trade.SendMessage("I will not pay for " + item.Name + " right now. Either remove or donate it.");
- }
- }
- Bot.log.Info("Eavluate: My offer is worth " + totalValue + " scrap");
- return totalValue;
- }
- public double evaluateUserOffer(List<Inventory.Item> offer)
- {
- InvalidItem = 0;
- double totalValue = 0;
- if (Bot.OtherInventory == null)
- {
- Bot.GetOtherInventory(OtherSID);
- }
- List<string> invalidItemName = new List<string>();
- foreach (ulong itemID in Trade.OtherOfferedItems)
- {
- Inventory.Item item = Bot.OtherInventory.GetItem(itemID);
- if (item.AppId == 440)
- {
- bool gotPrice = false;
- if (item.Defindex == 5021 && mySettings.scrapPerKey > 0)
- {
- totalValue = totalValue + mySettings.scrapPerKey;
- gotPrice = true;
- }
- if (item.Defindex == 5000)
- {
- totalValue = totalValue + 1;
- gotPrice = true;
- }
- if (item.Defindex == 5001)
- {
- totalValue = totalValue + 3;
- gotPrice = true;
- }
- if (item.Defindex == 5002)
- {
- totalValue = totalValue + 9;
- gotPrice = true;
- }
- else
- {
- try
- {
- if (!tooMuch(item.Defindex)) //this was the line I used to use to check for craft hats
- if (!isGifted(item)) //and it hasn't been gifted
- {
- foreach (BotSettings.Item match in mySettings.items)
- {
- if (match.defindex == item.Defindex)
- {
- if (!item.IsNotCraftable && currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && (currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
- {
- totalValue = totalValue + match.buyPrice;
- gotPrice = true;
- }
- else if (!(currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
- {
- totalValue = totalValue + match.buyPrice;
- gotPrice = true;
- }
- else
- {
- Trade.SendMessage("I only accept craftable items!");
- }
- }
- }
- }
- else
- {
- Trade.SendMessage("I don't accept gifted items.");
- }
- }
- catch
- {
- }
- if (gotPrice == false)
- {
- if ((!item.IsNotCraftable && !isGifted(item)) && (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).ItemSlot == "melee" || currentSchema.GetItem(item.Defindex).ItemSlot == "primary" || currentSchema.GetItem(item.Defindex).ItemSlot == "secondary" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
- {
- totalValue = totalValue + .5;
- gotPrice = true;
- }
- else
- {
- InvalidItem++;
- invalidItemName.Add(currentSchema.GetItem(item.Defindex).Name);
- }
- }
- }
- }
- else
- {
- Trade.SendMessage("You have items from a game which is not tf2. Please remove them.");
- }
- }
- if (invalidItemName.Count == 1)
- {
- Trade.SendMessage("I am not buying " + invalidItemName[0] + " right now, please remove it or I will treat it as a donation.");
- }
- else if (invalidItemName.Count > 1)
- {
- Trade.SendMessage("I am not buying the following items. Please remove them or I will treat them as donations:");
- foreach (string itemName in invalidItemName)
- {
- Trade.SendMessage("...." + itemName);
- }
- }
- Bot.log.Info("User has made an offer worth " + totalValue + " scrap");
- return totalValue;
- }
- public void doPayment(bool buyingItems)
- {
- int loopCount = 0;
- TradeCountInventory(false);
- double userOfferValue = evaluateUserOffer(userOffer);
- double myOfferValue = evaluateMyOffer(myOffer);
- Log.Info("My current offer value is " + myOfferValue + " scrap.");
- //actually pay
- if (myOfferValue > userOfferValue)
- {
- bool DoneAddingMetal = false;
- while (!DoneAddingMetal)
- {
- double BotValueAdded = evaluateMyOffer(myOffer);
- if (BotValueAdded - mySettings.scrapPerKey >= userOfferValue && Trade.RemoveItemByDefindex(5021))
- {
- Log.Warn("I removed a key");
- BotValueAdded = BotValueAdded - mySettings.scrapPerKey;
- myOffer.Remove(currentSchema.GetItem(5021));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- }
- else if (BotValueAdded - 9 >= userOfferValue && Trade.RemoveItemByDefindex(5002))
- {
- Log.Warn("I removed a ref");
- BotValueAdded = BotValueAdded - 9;
- myOffer.Remove(currentSchema.GetItem(5002));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- }
- else if (BotValueAdded - 3 >= userOfferValue && Trade.RemoveItemByDefindex(5001))
- {
- Log.Warn("I removed a rec");
- BotValueAdded = BotValueAdded - 3;
- myOffer.Remove(currentSchema.GetItem(5001));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- }
- else if (BotValueAdded -1 >= userOfferValue && Trade.RemoveItemByDefindex(5000))
- {
- Log.Warn("I removed a scrap");
- BotValueAdded = BotValueAdded - 1;
- myOffer.Remove(currentSchema.GetItem(5000));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- }
- else if (BotValueAdded - .5 >= userOfferValue && removeWeapon())
- {
- Log.Warn("I removed a weapon");
- BotValueAdded = BotValueAdded - .5;
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- }
- if (BotValueAdded == userOfferValue)
- {
- consolidateOffer();
- Trade.SendMessage("Successfully matched offer value");
- Bot.log.Info("My offer is now worth " + BotValueAdded);
- return;
- }
- loopCount++;
- if (loopCount > 40)
- {
- if (BotValueAdded - .5 <= userOfferValue && removeWeapon())
- {
- Log.Warn("I removed a weapon");
- BotValueAdded = BotValueAdded - .5;
- Bot.log.Info("My offer is now worth " + BotValueAdded);
- }
- else if (BotValueAdded - 1 <= userOfferValue && Trade.RemoveItemByDefindex(5000))
- {
- Log.Warn("I removed a scrap");
- BotValueAdded = BotValueAdded - 1;
- myOffer.Remove(currentSchema.GetItem(5000));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- break;
- }
- else if (BotValueAdded - 3 <= userOfferValue && Trade.RemoveItemByDefindex(5001))
- {
- Log.Warn("I removed a rec");
- BotValueAdded = BotValueAdded - 3;
- myOffer.Remove(currentSchema.GetItem(5001));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- break;
- }
- else if (BotValueAdded - 9 <= userOfferValue && Trade.RemoveItemByDefindex(5002))
- {
- Log.Warn("I removed a ref");
- BotValueAdded = BotValueAdded - 9;
- myOffer.Remove(currentSchema.GetItem(5002));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- break;
- }
- else if (BotValueAdded - mySettings.scrapPerKey <= userOfferValue && Trade.RemoveItemByDefindex(5021))
- {
- Log.Warn("I removed a key");
- BotValueAdded = BotValueAdded - mySettings.scrapPerKey;
- myOffer.Remove(currentSchema.GetItem(5021));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- break;
- }
- }
- if (loopCount > 80)
- {
- break;
- }
- }
- }
- myOfferValue = evaluateMyOffer(myOffer);
- if(myOfferValue < userOfferValue)
- {
- removeCurrency();
- bool DoneAddingMetal = false;
- while(!DoneAddingMetal)
- {
- double BotValueAdded = evaluateMyOffer(myOffer);
- if((mySettings.scrapPerKey > 0) && BotValueAdded + mySettings.scrapPerKey <= userOfferValue && Trade.AddItemByDefindex(5021)){
- Log.Warn("I added a key");
- BotValueAdded = BotValueAdded + mySettings.scrapPerKey;
- myOffer.Add(currentSchema.GetItem(5021));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- }
- else if(BotValueAdded + 9 <= userOfferValue && Trade.AddItemByDefindex(5002)){
- Log.Warn("I added a ref");
- BotValueAdded = BotValueAdded + 9;
- myOffer.Add(currentSchema.GetItem(5002));
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- }
- else if(BotValueAdded + 3 <= userOfferValue && Trade.AddItemByDefindex(5001)){
- Log.Warn("I add a rec");
- BotValueAdded = BotValueAdded + 3;
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- myOffer.Add(currentSchema.GetItem(5001));
- }
- else if(BotValueAdded + 1 <= userOfferValue && Trade.AddItemByDefindex(5000)){
- Log.Warn("I added a scrap");
- BotValueAdded = BotValueAdded + 1;
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- myOffer.Add(currentSchema.GetItem(5000));
- }
- else if (BotValueAdded + .5 <= userOfferValue && addWeapon())
- {
- Log.Warn("I added a weapon");
- BotValueAdded = BotValueAdded + .5;
- }
- if(BotValueAdded == userOfferValue){
- Trade.SendMessage("Successfully matched offer value");
- Bot.log.Info("MY offer is now worth " + BotValueAdded);
- return;
- }
- loopCount++;
- if(loopCount > 40){
- Trade.SendMessage("Sorry, I cannot match that offer exactly, please remove some items");
- return;
- }
- }
- }
- }
- public bool addWeapon()
- {
- foreach (Inventory.Item item in Bot.MyInventory.Items)
- {
- if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && ((currentSchema.GetItem(item.Defindex).CraftClass == "weapon") || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
- {
- bool product = false;
- foreach (BotSettings.Item name in mySettings.items)
- {
- if (name.defindex == item.Defindex)
- {
- product = true;
- }
- }
- if (!product && Trade.AddItemByDefindex(item.Defindex))
- {
- return true;
- }
- }
- }
- return false;
- }
- public bool removeWeapon()
- {
- foreach (ulong itemID in Trade.MyOfferedSteamItems)
- {
- Schema.Item item = currentSchema.GetItem(Bot.MyInventory.GetItem(itemID).Defindex);
- if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && ((currentSchema.GetItem(item.Defindex).CraftClass == "weapon") || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
- {
- bool product = false;
- foreach (BotSettings.Item name in mySettings.items)
- {
- if (name.defindex == item.Defindex)
- {
- product = true;
- }
- }
- if (!product && Trade.RemoveItemByDefindex(item.Defindex))
- {
- return true;
- }
- }
- }
- return false;
- }
- public void removeCurrency()
- {
- Trade.RemoveAllItemsByDefindex(5000);
- Trade.RemoveAllItemsByDefindex(5001);
- Trade.RemoveAllItemsByDefindex(5002);
- List<int> weaponDefindexes = new List<int>();
- foreach (ulong itemID in Trade.MyOfferedSteamItems)
- {
- Schema.Item item = currentSchema.GetItem(Bot.MyInventory.GetItem(itemID).Defindex);
- bool product = false;
- foreach (BotSettings.Item name in mySettings.items)
- {
- if (name.defindex == item.Defindex)
- {
- product = true;
- }
- }
- if (!product && Trade.AddItemByDefindex(item.Defindex))
- {
- if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && (currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
- {
- weaponDefindexes.Add(item.Defindex);
- }
- }
- }
- foreach (int defindex in weaponDefindexes)
- {
- Trade.RemoveAllItemsByDefindex(defindex);
- }
- }
- public void consolidateOffer()
- {
- }
- public bool isGifted(Inventory.Item item)
- {
- bool isGifted = false;
- try
- {
- foreach (Inventory.ItemAttribute attribute in item.Attributes)
- {
- if (attribute.Defindex == 186)
- {
- isGifted = true;
- }
- }
- }
- catch
- {
- isGifted = false;
- }
- return isGifted;
- }
- public bool tooMuch(int defindex)
- {
- foreach (BotSettings.Item item in mySettings.items)
- {
- if (item.defindex == defindex)
- {
- if (Bot.MyInventory == null)
- {
- Bot.GetInventory();
- }
- if (Bot.MyInventory.GetItemsByDefindex(defindex).Count >= item.maxAmount || item.maxAmount == 0)
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region "Message Handling"
- #region "Universal"
- //Sends a message via steam chat
- public void sendChatMessage(string message)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, message);
- }
- public bool IsNumeric(System.Object Expression)
- {
- if (Expression == null || Expression is DateTime)
- return false;
- if (Expression is Int16 || Expression is Int32 || Expression is Int64 || (((Expression is Double)) && (mode == ADMINMODE))/*|| Expression is Decimal|| Expression is Single /|| Expression is Double || Expression is Boolean*/)
- return true;
- try
- {
- if (Expression is string)
- Int64.Parse(Expression as string);
- else
- Int64.Parse(Expression.ToString());
- return true;
- }
- catch { } // just dismiss errors but return false
- return false;
- }
- //Returns the number of instances of a particular item contained in a backpack with a particular item ID
- public Int32[] getNumericItemInfo(string message, EChatEntryType type)
- {
- Int32[] itemCount = new int[3];
- Int32 usualCount = 0;
- Bot.GetInventory();
- foreach (Inventory.Item item in Bot.MyInventory.Items)
- {
- if (item.Defindex == Int32.Parse(message))
- {
- itemCount[0] = usualCount + 1;
- }
- }
- return itemCount;
- }
- public int getItemId(string message, int messageMode)
- {
- if (mode == ADMINMODE)
- {
- try
- {
- List<int> itemIds = new List<int>();
- int itemId;
- message = message.ToLower();
- Bot.GetInventory();
- Schema currentSchema = Schema.FetchSchema(Bot.apiKey);
- foreach (Schema.Item item in currentSchema.GetItems())
- {
- string itemname = item.Name.ToLower();
- if (itemname.Contains(message))
- {
- itemId = item.Defindex;
- itemIds.Add(itemId);
- }
- if (itemname.Equals(message))
- {
- return item.Defindex;
- }
- }
- if (itemIds.Count() > 1)
- {
- if (messageMode == STEAMCHAT)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Found multiple matches for " + message + ", be more specific");
- }
- else
- {
- Trade.SendMessage("Found multiple matches for " + message + ", be more specific");
- }
- return -1;
- }
- else
- {
- try
- {
- return itemIds[0];
- }
- catch
- {
- if (messageMode == STEAMCHAT)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed.");
- }
- else
- {
- Trade.SendMessage("Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed. ");
- }
- return -1;
- }
- }
- }
- catch (NullReferenceException ex)
- {
- List<int> itemIds = new List<int>();
- return -1;
- }
- }
- else
- {
- try
- {
- List<int> itemIds = new List<int>();
- int itemId;
- message = message.ToLower();
- Bot.GetInventory();
- if (mySettings == null)
- {
- mySettings.loadBotSettings();
- }
- foreach (BotSettings.Item itemSetting in mySettings.items)
- {
- string itemname = itemSetting.itemName.ToLower();
- if (itemname.Contains(message))
- {
- itemId = itemSetting.defindex;
- itemIds.Add(itemId);
- }
- if (itemname.Equals(message))
- {
- return itemSetting.defindex;
- }
- }
- if (itemIds.Count() > 1)
- {
- if (messageMode == STEAMCHAT)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Found multiple matches for " + message + ", be more specific");
- }
- else
- {
- Trade.SendMessage("Found multiple matches for " + message + ", be more specific");
- }
- return -1;
- }
- else
- {
- try
- {
- return itemIds[0];
- }
- catch
- {
- if (messageMode == STEAMCHAT)
- {
- Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed. ");
- }
- else
- {
- Trade.SendMessage("Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed.");
- }
- return -1;
- }
- }
- }
- catch (NullReferenceException ex)
- {
- List<int> itemIds = new List<int>();
- return -1;
- }
- }
- }
- //gets the name of an item from its defindex
- public string getItemName(int itemId)
- {
- if (mode == ADMINMODE)
- {
- try
- {
- Schema currentSchema = Schema.FetchSchema(Bot.apiKey);
- foreach (Schema.Item item in currentSchema.GetItems())
- {
- if ((Int32)item.Defindex == itemId)
- {
- return item.Name;
- }
- }
- return "Error in finding name 2";
- }
- catch
- {
- return "Error in finding name 3";
- }
- }
- else{
- try
- {
- if (mySettings == null)
- {
- mySettings = new BotSettings();
- mySettings.loadBotSettings();
- }
- foreach (BotSettings.Item item in mySettings.items)
- {
- if ((Int32)item.defindex == itemId)
- {
- return item.itemName;
- }
- }
- return "Error in finding name 2";
- }
- catch
- {
- return "Error in finding name 3";
- }
- }
- }
- public void priceResponse(int messageMode)
- {
- foreach (BotSettings.Item itemSetting in mySettings.items)
- {
- decimal SitemPrice = -999999999;
- decimal BitemPrice = -999999999;
- int itemCount = 0;
- int thisItem;
- thisItem = itemSetting.defindex;
- Bot.GetInventory();
- foreach (Inventory.Item item in Bot.MyInventory.Items)
- {
- if (item.Defindex == thisItem)
- {
- itemCount++;
- }
- }
- SitemPrice = (decimal)itemSetting.sellPrice;
- BitemPrice = (decimal)itemSetting.buyPrice;
- SitemPrice = Math.Truncate(100 * (SitemPrice / 9)) / 100;
- BitemPrice = Math.Truncate(100 * (BitemPrice / 9)) / 100;
- if (SitemPrice == -999999999)
- {
- }
- else
- {
- if (messageMode == STEAMCHAT)
- {
- sendChatMessage("I will buy " + getItemName(thisItem) + "s " + " at " + BitemPrice + " ref each.");
- sendChatMessage("I have " + itemCount + " " + getItemName(thisItem) + "s " + " which I will sell at " + SitemPrice + " ref each.");
- }
- if(messageMode == TRADECHAT){
- Trade.SendMessage("I will buy " + getItemName(thisItem) + "s " + " at " + BitemPrice + " ref each.");
- Trade.SendMessage("I have " + itemCount + " " + getItemName(thisItem) + "s " + " which I will sell at " + SitemPrice + " ref each.");
- }
- }
- }
- }
- public void stockResponse(int messageMode)
- {
- int keyCount = 0;
- int refCount = 0;
- int recCount = 0;
- int scrapCount = 0;
- int metalCount = 0;
- Bot.GetInventory();
- foreach(Inventory.Item item in Bot.MyInventory.Items)
- {
- if (item.Defindex == 5000)
- {
- scrapCount++;
- metalCount++;
- }
- else if(item.Defindex == 5001){
- recCount++;
- metalCount = metalCount + 3;
- }
- else if(item.Defindex == 5002){
- refCount++;
- metalCount = metalCount + 9;
- }
- else if (item.Defindex == 5021)
- {
- keyCount++;
- }
- }
- double MetalToRef = (metalCount / 9.0) - 0.01;
- string refined = string.Format("{0:N2}", MetalToRef);
- if (messageMode == STEAMCHAT)
- {
- sendChatMessage("I have " + refined + " ref (" + refCount + " ref, " + recCount + " rec, and " + scrapCount + " scrap) and " + keyCount + " key(s) in my backpack.");
- }
- else
- {
- Trade.SendMessage("I have " + refined + " ref (" + refCount + " ref, " + recCount + " rec, and " + scrapCount + " scrap) and " + keyCount + " key(s) in my backpack.");
- }
- }
- public void dumpMetal()
- {
- foreach (var item in Trade.MyInventory.Items)
- {
- if ((item.Defindex == 5021 || item.Defindex == 5000 || item.Defindex == 5001 || item.Defindex == 5002 || item.Defindex == 5003))
- {
- Trade.AddItemByDefindex(item.Defindex);
- }
- }
- }
- public void dumpItems()
- {
- foreach (var item in Trade.MyInventory.Items)
- {
- try
- {
- if (Trade.CurrentSchema.GetItem(item.Defindex).ItemSlot.Equals("head") || Trade.CurrentSchema.GetItem(item.Defindex).ItemSlot.Equals("misc"))
- {
- Trade.AddItemByDefindex(item.Defindex);
- }
- }
- catch { }
- }
- }
- #endregion
- #region "Add Friend"
- private void OnInviteTimerElapsed(object source, ElapsedEventArgs e, EChatEntryType type)
- {
- sendChatMessage(welcomeMessage);
- Bot.log.Success("Sent welcome message.");
- if (autoSendTradeRequest)
- {
- Bot.OpenTrade(OtherSID);
- }
- Bot.log.Success("Sent trade invite.");
- inviteMsgTimer.Enabled = false;
- inviteMsgTimer.Stop();
- }
- #endregion
- #region "Steam Message"
- public void testResponse(string message) //If you ever want to test code do it here
- {
- return;
- }
- bool craftSwitch = false;
- bool refSwitch = false;
- bool recSwitch = false;
- bool blockSwitch = false;
- int currentItemMax = 0;
- public void adminResponse(string message)
- {
- message = message.ToLower();
- if (message.Equals("set price") || priceSwitch > 0)
- {
- switch (priceSwitch)
- {
- case 0:
- sendChatMessage("Enter the defindex or name of the item you are trying to price. Type 'exit' to cancel");
- priceSwitch++;
- break;
- case 1:
- if (IsNumeric(message))
- {
- currentItemDefindex = Int32.Parse(message);
- currentItemName = getItemName(currentItemDefindex);
- if (currentItemName == null)
- {
- sendChatMessage("Could not find an item with that defindex, please try again or use 'restart' to return to the main admin menu");
- return;
- }
- }
- else{
- currentItemDefindex = getItemId(message, STEAMCHAT);
- if (currentItemDefindex == -1)
- {
- sendChatMessage("Couldn't find a specific match for that item");
- return;
- }
- currentItemName = getItemName(currentItemDefindex);
- }
- sendChatMessage("Now enter the price in scrap that you would like the bot to pay for that item.");
- priceSwitch++;
- return;
- case 2:
- try
- {
- currentItemBuyPrice = Int32.Parse(message);
- }
- catch
- {
- try {
- currentItemBuyPrice = Double.Parse(message);
- }
- catch
- {
- sendChatMessage("Something is wrong with that price, please try again.");
- return;
- }
- }
- sendChatMessage("Finally enter the price in scrap at which you want to sell the item.");
- priceSwitch++;
- return;
- case 3:
- try
- {
- currentItemSellPrice = Int32.Parse(message);
- }
- catch
- {
- try {
- currentItemSellPrice = Double.Parse(message);
- }
- catch
- {
- sendChatMessage("Something is wrong with that price, please try again.");
- return;
- }
- }
- sendChatMessage("What is the maximum number of that item you want in your backpack, type 0 to allow infinite");
- priceSwitch++;
- return;
- case 4:
- try
- {
- currentItemMax = Int32.Parse(message);
- }
- catch
- {
- sendChatMessage("Sorry, please only type positive whole integers");
- }
- sendChatMessage("I have you wanting to add an entry for " + currentItemName + " at a buy price of " + currentItemBuyPrice + " and a sell price of " + currentItemSellPrice + " and a limit of " + currentItemMax +". If this is correct type 'yes' otherwise type 'no'");
- priceSwitch++;
- return;
- case 5:
- if (message.ToLower().Equals("yes"))
- {
- List<BotSettings.Item> copy = new List<BotSettings.Item>();
- copy = mySettings.items.ToList<BotSettings.Item>();
- foreach (BotSettings.Item item in copy)
- {
- if (item.defindex == currentItemDefindex)
- {
- sendChatMessage("Previous Entry Removed");
- mySettings.items.Remove(item);
- }
- }
- mySettings.addItem(currentItemName, currentItemDefindex, currentItemBuyPrice, currentItemSellPrice, currentItemMax);
- priceSwitch = 0;
- sendChatMessage("Price set.");
- return;
- }
- else if (message.ToLower().Equals("no"))
- {
- sendChatMessage("Use 'add item' to start over");
- priceSwitch = 0;
- return;
- }
- else
- {
- sendChatMessage("Please respond with either 'yes' or 'no'");
- }
- break;
- default:
- priceSwitch = 0;
- break;
- }
- }
- else if (message.Contains("set password"))
- {
- parsePassword(message);
- mySettings.saveBotSettings(mySettings);
- }
- else if (message.Equals("remove friends"))
- {
- int i = 0;
- while (true)
- {
- try
- {
- SteamID toRemove = Bot.SteamFriends.GetFriendByIndex(i);
- if (toRemove == OtherSID || Bot.Admins.Contains(toRemove.ConvertToUInt64()))
- {
- }
- else
- {
- Bot.SteamFriends.RemoveFriend(toRemove);
- if (toRemove.ConvertToUInt64() != 0)
- {
- Bot.log.Info("I removed " + toRemove.ConvertToUInt64() + " from my friend list");
- }
- }
- i++;
- }
- catch { i++; }
- if (i > 250)
- {
- break;
- }
- }
- sendChatMessage("All non-admin steam friends removed");
- Bot.log.Info("Current friend count " + Bot.SteamFriends.GetFriendCount());
- }
- else if (message.Contains("craft scrap") || craftSwitch)
- {
- if (craftSwitch)
- {
- if (IsNumeric(message))
- {
- int weaponsCrafted = Bot.craftAllWeapons(Int32.Parse(message));
- sendChatMessage("I was able to craft a total of: " + weaponsCrafted + " scrap.");
- craftSwitch = false;
- }
- else
- {
- sendChatMessage("Type the maximum number of scrap you want to craft");
- }
- }
- else
- {
- sendChatMessage("Type the maximum number of scrap you want to craft. Type '0' (without quotes) if you want to craft all weapons into scrap.");
- craftSwitch = true;
- }
- }
- else if (message.Contains("craft rec" )|| recSwitch)
- {
- if (recSwitch)
- {
- if (IsNumeric(message))
- {
- int recCrafted = Bot.craftRec(Int32.Parse(message));
- sendChatMessage("I was able to craft a total of: " + recCrafted + " rec.");
- recSwitch = false;
- }
- else
- {
- sendChatMessage("Type the maximum number of rec you want to craft");
- }
- }
- else
- {
- sendChatMessage("Type the maximum number of rec you want to craft. Type '0' (without quotes) if you want to craft all scrap into rec.");
- recSwitch = true;
- }
- }
- else if (message.Contains("craft ref") || refSwitch)
- {
- if (refSwitch)
- {
- if (IsNumeric(message))
- {
- int refCrafted = Bot.craftRef(Int32.Parse(message));
- sendChatMessage("I was able to craft a total of: " + refCrafted + " ref.");
- refSwitch = false;
- }
- else
- {
- sendChatMessage("Type the maximum number of scrap you want to craft");
- }
- }
- else
- {
- sendChatMessage("Type the maximum number of ref you want to craft. Type '0' (without quotes) if you want to craft all rec into ref.");
- refSwitch = true;
- }
- }
- else if(message.Contains("block craft") || blockSwitch){
- if(blockSwitch){
- if (IsNumeric(message))
- {
- int defindex = Int32.Parse(message);
- if (currentItemName == null)
- {
- sendChatMessage("Could not find an item with that defindex, please try again or use 'restart' to return to the main admin menu");
- return;
- }
- else{
- mySettings.noCraft.Add(currentItemDefindex);
- mySettings.saveBotSettings(mySettings);
- blockSwitch = false;
- }
- }
- else
- {
- int defindex = getItemId(message, STEAMCHAT);
- if (defindex == -1)
- {
- sendChatMessage("Couldn't find a specific match for that item");
- return;
- }
- else{
- mySettings.noCraft.Add(currentItemDefindex);
- mySettings.saveBotSettings(mySettings);
- blockSwitch = false;
- }
- }
- }
- else{
- sendChatMessage("Type the name or defindex of the item you want to block from being crafted");
- blockSwitch = true;
- }
- }
- else if (message.Equals("remove item") || removalSwitch > 0)
- {
- switch (removalSwitch)
- {
- case 0:
- sendChatMessage("Enter the name or defindex of the item you'd like to remove from the price settings");
- removalSwitch++;
- break;
- case 1:
- if (IsNumeric(message))
- {
- currentItemDefindex = Int32.Parse(message);
- currentItemName = getItemName(currentItemDefindex);
- if (currentItemName == null)
- {
- sendChatMessage("Could not find an item with that defindex, please try again or use 'restart' to return to the main admin menu");
- return;
- }
- }
- else
- {
- currentItemDefindex = getItemId(message, STEAMCHAT);
- if (currentItemDefindex == -1)
- {
- sendChatMessage("Couldn't find a specific match for that item");
- return;
- }
- currentItemName = getItemName(currentItemDefindex);
- }
- bool removedItem = false;
- List<BotSettings.Item> copy = new List<BotSettings.Item>();
- copy = mySettings.items.ToList<BotSettings.Item>();
- foreach (BotSettings.Item item in copy)
- {
- if (item.defindex == currentItemDefindex)
- {
- sendChatMessage("Item Removed");
- mySettings.items.Remove(item);
- removedItem = true;
- }
- }
- if (!removedItem)
- {
- sendChatMessage("Could not remove that item try a different name");
- return;
- }
- mySettings.saveBotSettings(mySettings);
- removalSwitch = 0;
- break;
- default:
- //lol
- break;
- }
- }
- else if (message.Contains("set key"))
- {
- try
- {
- parseKeyPrice(message);
- mySettings.saveBotSettings(mySettings);
- }
- catch
- {
- sendChatMessage("SYNTAX ERROR: be sure that you are including the proper spacing and that the price is in *scrap* (there should be no decimals in your input");
- }
- }
- else
- {
- sendChatMessage("Valid commands include: set price, set password [newpassword] [confirmnewpassword], remove item, set key [price of keys in scrap], remove friends, craft scrap");
- sendChatMessage("Use 'exit' to leave admin mode");
- }
- }
- public void parsePassword(string message) //lets you change your admin password
- {
- string[] codes = message.Split(' ');
- if (codes.Length > 4)
- {
- sendChatMessage("Remember, you cannot use spaces in your passwords");
- }
- if (codes.Length < 4)
- {
- sendChatMessage("You need to enter your new password followed by a space followed by your new password again");
- }
- else
- {
- if (codes[2] == codes[3])
- {
- mySettings.adminPassword = codes[3];
- }
- else
- {
- sendChatMessage("The two passwords didn't match");
- }
- }
- }
- public void parseKeyPrice(string message) //when you try to config the key price
- {
- int thisPrice;
- string priceInfo = message.Substring(8);
- if (IsNumeric(priceInfo))
- {
- thisPrice = Int32.Parse(priceInfo);
- mySettings.scrapPerKey = thisPrice;
- }
- else
- {
- sendChatMessage("Sorry, I only understand numeric prices.");
- thisPrice = -1;
- return;
- }
- }
- #endregion
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement