public bool RunCommand(List <string> args, UserHandler handler, Action <string> sendChatMessage) { TF2Value total = TF2Value.Zero; try { handler.Bot.GetInventory(); Inventory inv = handler.Bot.MyInventory; List <Inventory.Item> keys = inv.GetItemsByDefindex(TF2Value.KEY_DEFINDEX); List <Inventory.Item> refi = inv.GetItemsByDefindex(TF2Value.REFINED_DEFINDEX); List <Inventory.Item> rec = inv.GetItemsByDefindex(TF2Value.RECLAIMED_DEFINDEX); List <Inventory.Item> scrap = inv.GetItemsByDefindex(TF2Value.SCRAP_DEFINDEX); total += TF2Value.Key * keys.Count; total += TF2Value.Refined * refi.Count; total += TF2Value.Reclaimed * rec.Count; total += TF2Value.Scrap * scrap.Count; } catch (Exception e) { handler.Log.Error("An error occurred during the {0} command: {1}", CommandName, e.Message); return(false); } sendChatMessage(string.Format("I currently have {0} in pure.", total.ToRefString())); return(true); }
public bool RunCommand(List <string> args, UserHandler handler, Action <string> sendChatMessage) { try { handler.Bot.GetInventory(); TF2Value total = TF2Value.Zero; foreach (Inventory.Item item in handler.Bot.MyInventory.Items) { if (item.IsNotTradeable) { continue; } if (item.Defindex == TF2Value.KEY_DEFINDEX) { total += TF2Value.Key; } if (item.Defindex == TF2Value.REFINED_DEFINDEX) { total += TF2Value.Refined; } if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX) { total += TF2Value.Reclaimed; } if (item.Defindex == TF2Value.SCRAP_DEFINDEX) { total += TF2Value.Scrap; } Order order = handler.Bot.Orders.SellOrders.FirstOrDefault((o) => o.MatchesItem(item)); if (order != null) { total += order.Price; continue; } } sendChatMessage("Net worth: " + total.ToRefString()); return(true); } catch (Exception e) { handler.Log.Error("An error occurred during the {0} command: {1}", CommandName, e.Message); return(false); } }
public override void OnMessage(string message, EChatEntryType type) { message = message.ToLower(); if (message == "price") { SendChatMessage("I buy keys for " + BuyPricePerKey.ToRefString() + ", and sell keys for " + SellPricePerKey.ToRefString() + "."); } else if ((message.Contains("love") || message.Contains("luv") || message.Contains("<3")) && (message.Contains("y") || message.Contains("u"))) { if (message.Contains("do")) { SendChatMessage("I love you lots. <3"); } else { SendChatMessage("I love you too!"); } } else if (message.Contains("<3")) { SendChatMessage("<3"); } else if (message.Contains("thank")) { SendChatMessage("You're welcome!"); } else if (message == "donate") { SendChatMessage("Please type that command into the trade window. And thanks!"); } else if (message == "buy") { SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info."); } else if (message == "sell") { SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info."); } else if (message == "trade") { SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info."); } else if (message.Contains("stupid") || message.Contains("f**k") || message.Contains("can't") || message.Contains("cant") || message.Contains("what")) { SendChatMessage("Hey, do you need help? Type \"help\" for more info. Or else, are trades failing? Chances are that Steam is having the issues -- not me!"); } else if (message.Contains("help")) { SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Then trade me, and put up your keys or metal and I will add my keys or exact price in metal automatically. You MUST put up exact metal if buying keys. Not having a private inventory is often helpful when trades fail. I also accept donations of either keys or metal. To donate, type \"donate\" in the trade window!"); } else if (message == "commands") { SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Type \"info\" for more information on this bot via a link to the bot's TF2Outpost page. Type \"help\" for a guide on how to trade with the bot. To donate, type \"donate\" in the trade window!"); } else if (message == "info") { SendChatMessage("More information about this bot can be found here: http://www.tf2outpost.com/trade/25788259 ."); } else if (message == "stock" || message == "inventory") { HasNonTradeCounted = false; CountInventory(true); if (NonTradeInventoryKeys == 0 && HasNonTradeCounted) { SendChatMessage("I don't have any keys to sell at the moment."); SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each."); } else if (NonTradeInventoryKeys > 0 && HasNonTradeCounted) { if (NonTradeInventoryMetal < BuyPricePerKey) { SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each, but unfortunately I can not afford to buy keys from you at this time."); } else { SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each."); SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each."); } } else if (InventoryFailed) { SendChatMessage("Unable to check inventory due to being unable to get it from Steam. You can probably try again in a few moments if you like."); Bot.Log.Warn("Bot notified user of failure to count inventory due to failed Web Request."); } else { SendChatMessage("Oh no, I'm broke!"); } if (NonTradeKeysCanBuy > 0 && BuyPricePerKey.ScrapPart > NonTradeScrap && BuyPricePerKey.ReclaimedPart > NonTradeReclaimed + (NonTradeScrap - BuyPricePerKey.ScrapPart) / 3) { SendChatMessage("I do not have exact change! Open and close a trade with me if you'd like me to make scrap/rec for you."); Bot.Log.Warn("Bot warned a user of a lack of scrap or rec during a stock request."); } } else if (IsAdmin) { if (message.StartsWith(".sell")) { double NewSellPrice = 0.0; SendChatMessage("Current selling price: " + SellPricePerKey.ToRefString() + "."); SellPricePerKey = TF2Value.Zero; if (message.Length >= 6) { double.TryParse(message.Substring(5), out NewSellPrice); Bot.Log.Success("Admin has requested that I set the new selling price to " + NewSellPrice + " ref."); SellPricePerKey = TF2Value.FromRef(NewSellPrice); SendChatMessage("Setting new selling price to: " + SellPricePerKey.ToRefString() + "."); Bot.Log.Success("Successfully set new price."); } else { SendChatMessage("I need more arguments. Current selling price: " + SellPricePerKey.ToRefString() + "."); } } else if (message.StartsWith(".buy")) { double NewBuyPrice = 0.0; SendChatMessage("Current buying price: " + BuyPricePerKey.ToRefString() + "."); BuyPricePerKey = TF2Value.Zero; if (message.Length >= 5) { double.TryParse(message.Substring(4), out NewBuyPrice); Bot.Log.Success("Admin has requested that I set the new buying price to " + NewBuyPrice + " ref."); BuyPricePerKey = TF2Value.FromRef(NewBuyPrice); SendChatMessage("Setting new buying price to: " + BuyPricePerKey.ToRefString() + "."); Bot.Log.Success("Successfully set new price."); } else { SendChatMessage("I need more arguments. Current buying price: " + BuyPricePerKey.ToRefString() + "."); } } else if (message.StartsWith(".play")) { if (message.Length >= 7) { if (message.Substring(6) == "tf2") { Bot.SetGamePlaying(440); Bot.Log.Success("Successfully simulated in-game status for TF2."); } Bot.SetGamePlaying(0); Bot.Log.Success("Exited game simulation."); } } if (message.StartsWith(".removefriend")) { if (message.Substring(14) == "all") { int friendCount = Bot.SteamFriends.GetFriendCount(); for (int x = 0; x < friendCount; x++) { SteamID DeletingFriendID = Bot.SteamFriends.GetFriendByIndex(x); if (!Bot.Admins.Contains(DeletingFriendID)) { Bot.SteamFriends.RemoveFriend(DeletingFriendID); } else { Bot.Log.Success("Skipped Admin " + Bot.SteamFriends.GetFriendPersonaName(DeletingFriendID) + "."); } } Bot.Log.Success("Deleted all friends."); } else { var EnteredID = Convert.ToUInt64(message.Substring(14)); var DeleteID = new SteamID(EnteredID); if (InFriendsList(DeleteID)) { Bot.SteamFriends.RemoveFriend(DeleteID); Bot.Log.Success("Deleted " + Bot.SteamFriends.GetFriendPersonaName(DeleteID) + "."); } else { Bot.Log.Error("Failed to remove friend. You typed " + EnteredID + "."); } } } else if (message == ".canceltrade") { if (Bot.CurrentTrade != null) { SteamID LastTradedSID = Trade.OtherSID; Trade.CancelTrade(); Bot.SteamFriends.SendChatMessage(LastTradedSID, EChatEntryType.ChatMsg, "Trade forcefully closed. Please retry as soon as you are ready to trade instead of whatever you were doing."); Bot.Log.Warn("Trade with " + Bot.SteamFriends.GetFriendPersonaName(LastTradedSID) + " cancelled."); Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade); } SendChatMessage("There is no current trade to cancel."); } } else { SendChatMessage(Bot.ChatResponse); } }
public bool Validate() { List <string> errors = new List <string>(); TF2Value? diff = null; if (ActiveOrder == null) { if (Trade.OtherOfferedItems.Count() == 0) { errors.Add("There is nothing you are offering."); } else { errors.Add("I am currently not buying any of those items."); } } else { // in buy orders, assume the bot calculates the pricing correctly. if (!ActiveOrder.IsBuyOrder) { if (HasNonPureInTrade()) { errors.Add("You have non-pure items in payment."); } if (AmountAdded < ActiveOrder.Price) { errors.Add(string.Format("You have only paid {0}. You still have {2} to go to reach the price of {1}.", AmountAdded.ToRefString(), ActiveOrder.Price.ToRefString(), (ActiveOrder.Price - AmountAdded).ToRefString())); } else if (AmountAdded > ActiveOrder.Price) { diff = AmountAdded - ActiveOrder.Price; } else if (AmountAdded > ActiveOrder.Price + TF2Value.FromRef(1)) { errors.Add(string.Format("You are paying too much. The price is {0}, but you have paid {1}.", ActiveOrder.Price.ToRefString(), AmountAdded.ToRefString())); } } else if (Trade.OtherOfferedItems.Count() > 1) { errors.Add("You have other items in your trade besides the one I am buying."); } } if (errors.Count > 0) { SendTradeMessage("There were problems with your trade:"); foreach (string e in errors) { SendTradeMessage("> " + e); } } if (errors.Count == 0 && diff != null) { SendTradeMessage("Adding change..."); AddPure(diff.Value); } return(errors.Count == 0); }
public void AddPure(TF2Value orderPayment) { if (ActiveOrder == null) { Log.Error("Trade with user #{0}: SimpleUserHandler.ActiveOrder == null.", OtherSID.ToString()); Trade.CancelTrade(); SendChatMessage("I have encountered an error. Please send the trade again."); return; } SendTradeMessage("Removing items from previous trades..."); Trade.RemoveAllItems(); SendTradeMessage("Adding payment for this trade..."); TF2Value myPayment = TF2Value.Zero; TF2Value currentIteration = TF2Value.Key; while (myPayment + currentIteration <= orderPayment) { if (!Trade.AddItemByDefindex(TF2Value.KEY_DEFINDEX)) { //Log.Warn("[TRADE-BUY] No more keys found. Moving on to refined metal."); break; } Log.Debug("Added key in trade with user {0}.", OtherSID.ToString()); myPayment += currentIteration; } currentIteration = TF2Value.Refined; while (myPayment + currentIteration <= orderPayment) { if (!Trade.AddItemByDefindex(TF2Value.REFINED_DEFINDEX)) { //Log.Warn("[TRADE-BUY] No more refined metal found. Moving on to reclaimed metal."); break; } Log.Debug("Added refined metal in trade with user {0}.", OtherSID.ToString()); myPayment += currentIteration; } currentIteration = TF2Value.Reclaimed; while (myPayment + currentIteration <= orderPayment) { if (!Trade.AddItemByDefindex(TF2Value.RECLAIMED_DEFINDEX)) { //Log.Warn("[TRADE-BUY] No more reclaimed metal found. Moving on to scrap metal."); break; } Log.Debug("Added reclaimed metal in trade with user {0}.", OtherSID.ToString()); myPayment += currentIteration; } currentIteration = TF2Value.Scrap; while (myPayment + currentIteration <= orderPayment) { if (!Trade.AddItemByDefindex(TF2Value.SCRAP_DEFINDEX)) { Log.Warn("[PAYMENT] No more scrap metal found."); break; } Log.Debug("Added scrap metal in trade with user {0}.", OtherSID.ToString()); myPayment += currentIteration; } if (myPayment != orderPayment) { Log.Error("Could not add correct amount of {0}. Instead added {1}.", ActiveOrder.Price.ToRefString(), myPayment.ToRefString()); Trade.CancelTrade(); SendChatMessage("I have encountered an error. Please send the trade again."); } SendTradeMessage("Finished paying {0}.", myPayment.ToRefString()); }
public override void OnMessage(string message, EChatEntryType type) { message = message.ToLower(); if (message == "price") { SendChatMessage("I buy keys for " + BuyPricePerKey.ToRefString() + ", and sell keys for " + SellPricePerKey.ToRefString() + "."); } else if ((message.Contains("love") || message.Contains("luv") || message.Contains("<3")) && (message.Contains("y") || message.Contains("u"))) { if (message.Contains("do")) { SendChatMessage("I love you lots. <3"); } else { SendChatMessage("I love you too!"); } } else if (message.Contains("<3")) { SendChatMessage("<3"); } else if (message.Contains("thank")) { SendChatMessage("You're welcome!"); } else if (message == "donate") { SendChatMessage("Please type that command into the trade window. And thanks!"); } else if (message == "buy") { SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info."); } else if (message == "sell") { SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info."); } else if (message == "trade") { SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info."); } else if (message.Contains("stupid") || message.Contains("f**k") || message.Contains("can't") || message.Contains("cant") || message.Contains("what")) { SendChatMessage("Hey, do you need help? Type \"help\" for more info. Or else, are trades failing? Chances are that Steam is having the issues -- not me!"); } else if (message.Contains("help")) { SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Then trade me, and put up your keys or metal and I will add my keys or exact price in metal automatically. Type \"commands\" for a list of commands."); } else if (message == "commands") { SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Type \"confirm\" to have your trades confirmed if the bot does not do so. Type \"info\" for more information on this bot via a link to the bot's TF2Outpost page. Type \"help\" for a guide on how to trade with the bot. Type \"group\" to be invited to the group (WIP). To donate, type \"donate\" in the trade window!"); } else if (message == "info") { SendChatMessage("More information about this bot can be found here: http://steamcommunity.com/groups/NarthsBots ."); } else if (message == "group") { SendChatMessage("Coming soon...invite to group feature. But here is the group: http://steamcommunity.com/groups/NarthsBots ."); } else if (message == "confirm") { Bot.AcceptAllMobileTradeConfirmations(); SendChatMessage("Confirming all my trades. Message from owner: If this does not work, Steam failed to send a confirmation. Redo your trade. This is out of my control."); } else if (message == "stock" || message == "inventory") { HasNonTradeCounted = false; CountInventory(true); if (InventoryFailed) { SendChatMessage("I failed to start your trade because Steam is down. Try again later when Steam is working."); Bot.Log.Warn("I notified user of failure to count inventory due to failed Web Request."); } if (NonTradeInventoryKeys == 0 && HasNonTradeCounted) { SendChatMessage("I don't have any keys to sell at the moment."); SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each."); } else if (NonTradeInventoryKeys > 0 && HasNonTradeCounted) { if (NonTradeInventoryMetal < BuyPricePerKey) { SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each, but unfortunately I can not afford to buy keys from you at this time."); } else { SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each."); SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each."); } } else { SendChatMessage("Oh no, I'm broke!"); } if (NonTradeKeysCanBuy > 0 && BuyPricePerKey.ScrapPart > NonTradeScrap && BuyPricePerKey.ReclaimedPart > NonTradeReclaimed + (NonTradeScrap - BuyPricePerKey.ScrapPart) / 3) { SendChatMessage("I do not have exact change! Open and close a trade with me if you'd like me to make scrap/rec for you."); Bot.Log.Warn("I warned a user of a lack of scrap or rec during a stock request."); } } else if (IsAdmin) { if (message.StartsWith(".sell")) { double NewSellPrice = 0.0; SendChatMessage("Current selling price: " + SellPricePerKey.ToRefString() + "."); SellPricePerKey = TF2Value.Zero; if (message.Length >= 6) { double.TryParse(message.Substring(5), out NewSellPrice); Bot.Log.Success("Admin has requested that I set the new selling price to " + NewSellPrice + " ref."); SellPricePerKey = TF2Value.FromRef(NewSellPrice); SendChatMessage("Setting new selling price to: " + SellPricePerKey.ToRefString() + "."); Bot.Log.Success("Successfully set new price."); } else { SendChatMessage("I need more arguments. Current selling price: " + SellPricePerKey.ToRefString() + "."); } } else if (message.StartsWith(".buy")) { double NewBuyPrice = 0.0; SendChatMessage("Current buying price: " + BuyPricePerKey.ToRefString() + "."); BuyPricePerKey = TF2Value.Zero; if (message.Length >= 5) { double.TryParse(message.Substring(4), out NewBuyPrice); Bot.Log.Success("Admin has requested that I set the new buying price to " + NewBuyPrice + " ref."); BuyPricePerKey = TF2Value.FromRef(NewBuyPrice); SendChatMessage("Setting new buying price to: " + BuyPricePerKey.ToRefString() + "."); Bot.Log.Success("Successfully set new price."); } else { SendChatMessage("I need more arguments. Current buying price: " + BuyPricePerKey.ToRefString() + "."); } } else if (message.StartsWith(".play")) { if (message.Length >= 7) { if (message.Substring(6) == "tf2") { Bot.SetGamePlaying(440); Bot.Log.Success("Successfully simulated in-game status for TF2."); } Bot.SetGamePlaying(0); Bot.Log.Success("Exited game simulation."); } } else if (message.StartsWith(".removefriend") || message.StartsWith(".deletefriend")) { if (message.Substring(14) == "all") { int friendCount = Bot.SteamFriends.GetFriendCount(); for (int x = 0; x < friendCount; x++) { SteamID DeletingFriendID = Bot.SteamFriends.GetFriendByIndex(x); if (!Bot.Admins.Contains(DeletingFriendID)) { Bot.SteamFriends.RemoveFriend(DeletingFriendID); } else { Bot.Log.Success("Skipped Admin " + Bot.SteamFriends.GetFriendPersonaName(DeletingFriendID) + "."); } } Bot.Log.Success("Deleting all friends."); } else { string FriendID; FriendID = message.Substring(14); FriendDelete(FriendID); } } else if (message == ".canceltrade") { if (Bot.CurrentTrade != null) { SteamID LastTradedSID = Trade.OtherSID; Trade.CancelTrade(); Bot.SteamFriends.SendChatMessage(LastTradedSID, EChatEntryType.ChatMsg, "Trade forcefully closed. Please retry as soon as you are ready to trade instead of whatever you were doing."); Bot.Log.Warn("Trade with " + Bot.SteamFriends.GetFriendPersonaName(LastTradedSID) + " cancelled."); IgnoringBot += 4; Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade); } else { SendChatMessage("There is no current trade to cancel."); } } else if (message == ".auth") { Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, Bot.SteamGuardAccount.GenerateSteamGuardCode()); Bot.Log.Warn("Generated code:" + Bot.SteamGuardAccount.GenerateSteamGuardCode() + "."); } } else { SendChatMessage(Bot.ChatResponse); } }