The abstract base class for users of SteamBot that will allow a user to extend the functionality of the Bot.
Exemplo n.º 1
0
        public async void ChatAsync(UserHandler user, string msg)
        {
            if (pendingMessages.Contains(user.OtherSID)) // don't let them chat if they didn't get a response yet
            {
                return;
            }

            AddPending(user.OtherSID);

            try
            {
                string response = await ThinkAsync(msg);

                if (user.GetState() != EPersonaState.Offline) // in case they disconnected
                {
                    user.SendChatMessage(response);
                }
            }
            catch (System.Net.WebException ex)
            {
                user.Bot.Log.Error("WebException occured in ChatSession: {0}", ex.Message);
            }

            RemovePending(user.OtherSID);
        }
Exemplo n.º 2
0
        public static bool RunCommand(string cmdName, List<string> args, UserHandler handler)
        {
            foreach (IChatCommand cmd in ChatCommands)
            {
                if (cmd.CommandName == cmdName.ToLower())
                {
                    if (!handler.IsAdmin && cmd.IsAdminOnly)
                    {
                        sendChatMessage(handler, "Sorry, but that command is reserved for admins.");
                        handler.Log.Warn("User {0} attempted to use admin command '{1}'.",
                            handler.OtherSID.ToString(), cmd.CommandName);
                        return false;
                    }

                    handler.Log.Info("User {0} started command '{1}'.",
                        handler.OtherSID.ToString(), cmd.CommandName);
                    return cmd.RunCommand(args, handler, (msg) => sendChatMessage(handler, msg));
                }
            }

            handler.Log.Warn("User {0} attempted to use nonexistent command '{1}'.",
                handler.OtherSID.ToString(), cmdName);
            sendChatMessage(handler, "I'm sorry, but that command is not recognized. " +
                "Type 'help' for a full list of commands.");
            return false;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Unsubscribes all listeners of this from the current trade.
 /// </summary>
 public void UnsubscribeTrade(UserHandler handler, Trade trade)
 {
     trade.OnSuccess -= handler.OnTradeSuccess;
     trade.OnAwaitingEmailConfirmation -= handler.OnTradeAwaitingEmailConfirmation;
     trade.OnClose -= handler.OnTradeClose;
     trade.OnError -= handler.OnTradeError;
     trade.OnStatusError -= handler.OnStatusError;
     //Trade.OnTimeout -= OnTradeTimeout;
     trade.OnAfterInit -= handler.OnTradeInit;
     trade.OnUserAddItem -= handler.OnTradeAddItem;
     trade.OnUserRemoveItem -= handler.OnTradeRemoveItem;
     trade.OnMessage -= handler.OnTradeMessageHandler;
     trade.OnUserSetReady -= handler.OnTradeReadyHandler;
     trade.OnUserAccept -= handler.OnTradeAcceptHandler;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Subscribes all listeners of this to the trade.
 /// </summary>
 public void SubscribeTrade(Trade trade, UserHandler handler)
 {
     trade.OnSuccess += handler.OnTradeSuccess;
     trade.OnAwaitingEmailConfirmation += handler.OnTradeAwaitingEmailConfirmation;
     trade.OnClose += handler.OnTradeClose;
     trade.OnError += handler.OnTradeError;
     trade.OnStatusError += handler.OnStatusError;
     //trade.OnTimeout += OnTradeTimeout;
     trade.OnAfterInit += handler.OnTradeInit;
     trade.OnUserAddItem += handler.OnTradeAddItem;
     trade.OnUserRemoveItem += handler.OnTradeRemoveItem;
     trade.OnMessage += handler.OnTradeMessageHandler;
     trade.OnUserSetReady += handler.OnTradeReadyHandler;
     trade.OnUserAccept += handler.OnTradeAcceptHandler;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Unsubscribes all listeners of this from the current trade.
 /// </summary>
 public void UnsubscribeTrade(UserHandler handler, Trade trade)
 {
     trade.OnClose -= handler.OnTradeClose;
     trade.OnError -= handler.OnTradeError;
     //Trade.OnTimeout -= OnTradeTimeout;
     trade.OnAfterInit -= handler.OnTradeInit;
     trade.OnUserAddItem -= handler.OnTradeAddItem;
     trade.OnUserRemoveItem -= handler.OnTradeRemoveItem;
     trade.OnMessage -= handler.OnTradeMessage;
     trade.OnUserSetReady -= handler.OnTradeReady;
     trade.OnUserAccept -= handler.OnTradeAccept;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Subscribes all listeners of this to the trade.
 /// </summary>
 public void SubscribeTrade(Trade trade, UserHandler handler)
 {
     trade.OnClose += handler.OnTradeClose;
     trade.OnError += handler.OnTradeError;
     //trade.OnTimeout += OnTradeTimeout;
     trade.OnAfterInit += handler.OnTradeInit;
     trade.OnUserAddItem += handler.OnTradeAddItem;
     trade.OnUserRemoveItem += handler.OnTradeRemoveItem;
     trade.OnMessage += handler.OnTradeMessage;
     trade.OnUserSetReady += handler.OnTradeReady;
     trade.OnUserAccept += handler.OnTradeAccept;
 }
Exemplo n.º 7
0
        public bool? TradeOfferMatches(UserHandler handler, TradeOffer offer)
        {
            handler.GetOtherInventory();
            handler.Bot.GetInventory();

            if (handler.OtherInventory == null)
            {
                handler.Log.Error("Inventory retrieval failed. Ignoring trade.");
                return null;
            }

            if (IsBuyOrder)
            {
                TF2Value paying = TF2Value.Zero;
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paying += TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paying += TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paying += TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paying += TF2Value.Key;
                    else
                        return false; // I only pay in pure if it's a buy order.
                }
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.Trade.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paying -= TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paying -= TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paying -= TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paying -= TF2Value.Key;
                }

                if (paying > Price)
                {
                    return false;
                }

                bool hasWantedStuff = false;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (!MatchesItem(item))
                    {
                        continue;
                    }

                    hasWantedStuff = true;
                    break;
                }

                return hasWantedStuff;
            }
            else
            {
                TF2Value paid = TF2Value.Zero;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paid += TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paid += TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paid += TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paid += TF2Value.Key;
                }
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paid -= TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paid -= TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paid -= TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paid -= TF2Value.Key;
                }

                if (paid < Price)
                {
                    return false;
                }

                var myAssets = offer.Items.GetMyItems();
                if (myAssets.Count == 1)
                {
                    var asset = myAssets.First();
                    Inventory.Item item = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    return MatchesItem(item);
                }
                return false;
            }
        }
Exemplo n.º 8
0
 static void sendChatMessage(UserHandler handler, string message)
 {
     handler.Bot.SteamFriends.SendChatMessage(handler.OtherSID, EChatEntryType.ChatMsg, message);
     handler.Log.Debug("Sent chat message to user {0}: {1}.", handler.OtherSID, message);
 }
Exemplo n.º 9
0
        public bool?TradeOfferMatches(UserHandler handler, TradeOffer offer)
        {
            handler.GetOtherInventory();
            handler.Bot.GetInventory();

            if (handler.OtherInventory == null)
            {
                handler.Log.Error("Inventory retrieval failed. Ignoring trade.");
                return(null);
            }

            if (IsBuyOrder)
            {
                TF2Value paying = TF2Value.Zero;
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paying += TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paying += TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paying += TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paying += TF2Value.Key;
                    }
                    else
                    {
                        return(false);                        // I only pay in pure if it's a buy order.
                    }
                }
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.Trade.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paying -= TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paying -= TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paying -= TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paying -= TF2Value.Key;
                    }
                }

                if (paying > Price)
                {
                    return(false);
                }

                bool hasWantedStuff = false;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (!MatchesItem(item))
                    {
                        continue;
                    }

                    hasWantedStuff = true;
                    break;
                }

                return(hasWantedStuff);
            }
            else
            {
                TF2Value paid = TF2Value.Zero;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paid += TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paid += TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paid += TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paid += TF2Value.Key;
                    }
                }
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paid -= TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paid -= TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paid -= TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paid -= TF2Value.Key;
                    }
                }

                if (paid < Price)
                {
                    return(false);
                }

                var myAssets = offer.Items.GetMyItems();
                if (myAssets.Count == 1)
                {
                    var            asset = myAssets.First();
                    Inventory.Item item  = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    return(MatchesItem(item));
                }
                return(false);
            }
        }
Exemplo n.º 10
0
 static void sendChatMessage(UserHandler handler, string message)
 {
     handler.Bot.SteamFriends.SendChatMessage(handler.OtherSID, EChatEntryType.ChatMsg, message);
     handler.Log.Debug("Sent chat message to user {0}: {1}.", handler.OtherSID, message);
 }