-
Notifications
You must be signed in to change notification settings - Fork 2
API methods
The following methods can be accessed via Stem.api
Posts a comment to a users Steam profile. Note that you will have to wait until the communityReady
event has been emitted from Stem
or the bot has been logged into the Steam Community.
Arguments
-
steamID
(String) - The SteamID of the user to post the comment to. -
comment
(String) - The comment to post. -
callback(err, commentPosted)
- Callback function-
err
(Error) - Error encountered during the process -
commentPosted
(Bool) - Whether or not the comment was posted. Failure can indicate that the request was not yet authenticated.
-
Example
Stem.api.postComment('76561198042819371', 'Thanks for using our service!', function (err, commentPosted) {
if (err)
return Stem.log.error(err.stack);
Stem.log.info('Was comment posted:', commentPosted);
});
Returns the given SteamID's admin status as a Boolean by checking if the SteamID exists in the admins
array in the users config.
Arguments
-
steamID
(String) - The SteamID to check
Example
Stem.config.admins = ['76561198042819371'];
Stem.api.isAdmin('76561198042819371'); // Returns true
Stem.api.isAdmin('76561198007932547'); // Returns false
Returns true if the given steamID is a valid 64 bit SteamID and false otherwise.
Arguments
-
steamID
(String) - SteamID to validate
Example
Stem.api.validateSteamID('76561198042819371'); // Returns true
Stem.api.validateSteamID('invalidID'); // Returns false
Checks if the items tracked from the trade events (Stem.trade.eventItems
) matches the real items placed into the trade from the user (Stem.botTrade.themAssets
). This should be called on the ready
event to make sure there was no 'quickswitch' attempt and that the trade is valid.
Example
ready
event handler
module.exports = function () {
var Stem = this,
isTradeValid = Stem.api.validateTrade();
// Items don't match up, cancel trade
if (!isTradeValid) {
Stem.bot.sendMessage(Stem.trade.client, 'There was an error validating the trade, please try again.')
return Stem.botTrade.cancel();
}
};
Sets up the request object in Stem.api.request
with the provided cookies. This is called by Stem once the webSession
event is emitted.
Arguments
-
cookies
(Array) - The cookies to use to setup the request object. These can be obtained by callingStem.bot.webLogOn
.
Example
webSession
event handler
module.exports = function (sessionID) {
var Stem = this;
// Login to Steam Community
Stem.bot.webLogOn(function (cookies) {
// Setup the request object in `Stem.api.request`
Stem.api.setupRequest(cookies);
});
};
Adds a command that can be called by messaging the bot.
Arguments
-
command
(Regex) - The command to listen for. -
commandHandler(steamID, args)
(Function) - The callback to use when the command is called.-
steamID
(String) - The SteamID of the user who called the command. -
command
(Object) - An object with the only property beingmatch
which is an array of the string that matched the given command Regex.
-
-
commandOptions
(Object) - Options to pass when listening for the given Regex command.-
eventType
The event the bot will listen for this command on.-
trade
- The bot will listen for the command on trade chat messages -
group
- The bot will listen for the command on group chat messages -
message
- The bot will listen on regular messages to it (default)
-
-
permission
Limit the command to this permission scope-
admin
- Only steamID's instem.config.admins
will be able to call this command -
normal
- Anyone can call this command (default)
-
-
Example
// Create a public `help` command
Stem.api.addCommand(/^help/, function (steamID, command) {
console.dir(command);
// Respond to the person who called the command
return Stem.bot.sendMessage(steamID, 'No help available');
});
// Create a `admin help` command for admins
Stem.api.addCommand(/^admin help/, function (steamID, command) {
console.dir(args);
// Respond to the person who called the command
return Stem.bot.sendMessage(steamID, 'No admin help available');
}, { permission: 'admin' });
This will attach a function to an event while passing Stem
as this
.
Event emitters:
-
Stem.bot
- https://github.com/seishun/node-steam#events -
Stem.botTrade
- https://github.com/seishun/node-steam-trade#events
Arguments
-
eventType
(String) - The event emitter to attach to. Can be one of the following:bot
,botTrade
orstem
-
eventName
(String) - The event name to listen for. Event names for each module can be found on their Github repo. -
eventHandler
(Function) - The function that will execute when the event is emitted.
Example
// Attach a event listener for `Stem.bot` that listens for the `tradeProposed` event.
Stem.api.addHandler('bot', 'tradeProposed', function (tradeID, steamID) {
// `Stem` is binded to `this`
var Stem = this;
// Deny trade request if user is not an admin
if (!Stem.api.isAdmin(steamID))
return Stem.bot.respondToTrade(tradeID, false);
return Stem.bot.respondToTrade(tradeID, true);
});
This is just a wrapper around the request
module that can make authenticated requests once cookies are setup.
Arguments
- See here
Example
// Fetch recently completed market transactions
Stem.api.request('http://steamcommunity.com/market/recentcompleted', function (err, response body) {
});