-
Notifications
You must be signed in to change notification settings - Fork 17
05. Customizing Your Bot
Each bot is powered by a UserHandler (set in settings.json
), which tells the bot what to do when a user interacts with it.
Each UserHandler you create must override all the necessary functions from the base UserHandler
class.
The default TradeOfferUserHandler
class is a good example of which callbacks are available for you to handle (i.e. the functions that start with On______()
), with some example code for each callback. You can choose to make a copy of this UserHandler (and rename the class name and file name), or you can simply edit/add your own code to the callbacks.
This page assumes you are using the TradeOfferUserHandler
.
It is worth noting that a unique instance of the UserHandler is created for every unique user that interacts with the bot. To get the SteamID
of the user, simply access the OtherSID
variable in the UserHandler. OtherSID
is a variable of type SteamID
, which has helper functions that lets you manipulate the object, such as OtherSID.ConvertToUInt64()
which gives you the SteamID64 of the user.
The Bot
class is accessible from within your UserHandler, by accessing the Bot
variable. From this, you can get info (such as your bot's API key by calling Bot.ApiKey
) and do Steam-related actions via the SteamKit2
project (via the variables Bot.SteamFriends
, from which you can perform actions such as sending chat messages to Steam friends, or Bot.SteamClient
, from which you can retrieve information about the bot such as its SteamID, etc.).
In the TradeOfferUserHandler
, there are the expected callbacks for interacting with Trade Offers, such as OnTradeOfferReceived()
, OnTradeOfferAccepted/Declined/Canceled()
, and a few others. There are also callbacks for other things unrelated to Trade Offers, such as OnMessage()
, and OnFriendAdd()
, which are self-explanatory. You can always refer to the examples in each callback of TradeOfferUserHandler
if you'd like more information.
Each UserHandler has access to the TradeOffers
variable, which gives you the ability to manipulate trade offers (such as creating then sending a trade offer, or accepting/declining/canceling). It is always useful to inspect the code for yourself if you want to see which functions are available for you to use. The TradeOffers
class is well-documented and should be self-explanatory.
Most of these callbacks and functions will either give you, or require, a TradeOffer
object, from which you can get information about a trade offer. See the TradeOffer
class for which properties are available for you to use.
SteamTradeOffersBot has a GenericInventory
class which allows you to get information about items, which is the same type of data as if you visted /id/user/inventory/
in a browser. You can do this by calling and assigning var inventories = FetchInventories(OtherSID);
to load all the inventories that the user has, and then accessing a specific inventory with the App ID and Context ID by calling inventories.GetInventory(appId, contextId)
. You can then iterate through the inventory to get information about each item. An example is provided for you in the TradeOfferUserHandler
class here.
Sometimes, you'll need data for items that the generic Steam inventory interface does not provide, such as wear values for CS:GO items. You can get the wear value via the GetPlayerItem
API. An interface for this is provided for you in SteamTradeOffersBot. Simply call CSGOInventory.FetchInventory(OtherSID, Bot.ApiKey, Bot.SteamWeb)
. The CSGOInventory
class inherits from the base Inventory
class, from which you can iterate through items, check if the inventory is private, or use one of the helper functions. Reading through the documentation or even just the code is always an important step in understanding how to use SteamTradeOffersBot to its full potential, so if you need more information on this subject, have a look at Inventory.cs
.
The TradeOfferUserHandler
class provides brief examples for each callback which should be a good starting point for you. If you aren't quite sure how to accomplish something, most of the time you just need to read the documentation within the code, or the code itself, to figure it out.
If you are still stuck, /r/SteamBot will often have people willing to help, as long as you've proven that you have tried to figure things out yourself first. Be warned, if your question is something that can be answered by looking through the code yourself, it may end up being deleted. You can also join the #steamtradeoffersbot
channel on the subreddit's Discord server for live chat assistance.