Skip to content

Latest commit

 

History

History
381 lines (302 loc) · 12.6 KB

API.md

File metadata and controls

381 lines (302 loc) · 12.6 KB

Classes

API
Utils

API

Kind: global class
Properties

Name Type Description
pluginName string Name of the plugin which uses this specific API instance.
data Object Data object that is passed to API instance via Vapor.use method.

new API(vapor, pluginName, data)

API class constructor.

Instance of this class is passed to plugins exported function as the only argument.

Param Type Description
vapor Vapor Vapor instance.
pluginName string Specific plugin name which uses this API instance.
data Object Data object that is passed to API instance.

api.connect(codes)

Connect to Steam network.

You can provide optional authentication codes.

Kind: instance method of API

Param Type Description
codes Object Optional object with authentication codes.
codes.authCode string Auth code received by e-mail.
codes.twoFactorCode string Auth code from mobile app.

api.disconnect()

Disconnect from Steam network.

Kind: instance method of API

api.getClient() ⇒ SteamClient

Returns active Steam client used by Vapor.

Kind: instance method of API
Returns: SteamClient - Active Steam client.

api.getHandler(handler) ⇒ Object

Returns active Steam handler used by Vapor.

Kind: instance method of API
Returns: Object - Active Steam handler.

Param Type Description
handler string Can be either steamUser, steamFriends, steamTrading or steamGroups.

api.getUtils() ⇒ Utils

Returns instance of Utils class.

Kind: instance method of API
Returns: Utils - Instantiated Utils class.

api.getSteam() ⇒ Steam

Returns Steam object.

This is especially useful for all the ESomething enums.

Kind: instance method of API
Returns: Steam - Steam.

api.getConfig() ⇒ Object

Returns Vapor config object.

Kind: instance method of API
Returns: Object - Config object.

api.getPlugins() ⇒ Array.<string>

Returns array of names of loaded plugins.

Kind: instance method of API
Returns: Array.<string> - Array of plugin names.

api.emitEvent(event, ...args)

Allows plugin to emit custom events via Vapor's event emitter.

This function allows to pass multiple data arguments.

Also see registerHandler.

Kind: instance method of API

Param Type Description
event string Event name.
...args * Data arguments.

Example

API.emitEvent('myCustomPluginEvent', someString, someObject);

api.registerHandler(options, callback)

Allows plugin to register custom handler for any event.

Also see emitEvent.

Kind: instance method of API

Param Type Description
options Object Options object.
options.emitter string Can be either vapor, client, steamUser, steamFriends, steamTrading, plugin or * (which stands for 'any').
options.plugin string If emitter is plugin, this is plugin's name. Use * for any.
options.event string Event name.
callback function Callback function.

Example

// Listen to 'friendMsg' event emitted by 'steamFriends'
API.registerHandler({
  emitter: 'steamFriends',
  event: 'friendMsg'
}, function(user, message, type) {
  if(type === Steam.EChatEntryType.ChatMsg) {
    console.log(user + " says: " + message);
  }
});

// Listen to another plugin's custom event
API.registerHandler({
  emitter: 'plugin',
  plugin: 'another-plugin-name'
  event: 'myCustomPluginEvent'
}, function(someString, someObject) {
  console.log(someString, someObject);
});

// Listen to 'debug' event emitted by anything
API.registerHandler({
  emitter: '*',
  event: 'debug'
}, function() {
  console.log(arguments);
});

// Listen to 'debug' event emitted by any plugin
API.registerHandler({
  emitter: 'plugin',
  plugin: '*',
  event: 'debug'
}, function() {
  console.log(arguments);
});

api.hasHandler(options)

Returns true if there is at least one handler for the given event, false otherwise.

Kind: instance method of API

Param Type Description
options Object | string Options object or event name.
options.emitter string Can be either vapor, client, steamUser, steamFriends, steamTrading, plugin or * (which stands for 'any').
options.plugin string If emitter is plugin, this is plugin's name. Use * for any.
options.event string Event name.

Example

if(API.hasHandler({emitter: 'steamFriends', event: 'friendMsg'})) {
  // do something ...
}

if(API.hasHandler('readFile')) {
  // we can safely emit this event to read a file
}

api.removeAllHandlers(options)

Allows plugin to remove all handlers for a specific event.

Kind: instance method of API

Param Type Description
options Object Options object.
options.emitter string Can be either vapor, client, steamUser, steamFriends, steamTrading, plugin or * (which stands for 'any').
options.plugin string If emitter is plugin, this is plugin's name. Use * for any.
options.event string Event name.

api.getLogger() ⇒ Object

Returns wrapper for emitting 'message:*' events prefixed with plugin's name.

Available levels:

  • log.debug
  • log.info
  • log.warn
  • log.error

Kind: instance method of API
Returns: Object - Logger.
Example

var log = VaporAPI.getLogger();

log.info('This is a regular info message...');
log.warn('...and this is a warning message.');
log.debug('String %s works too!', 'formatting');

api.webLogOn()

Calls Vapor's internal webLogOn method.

Listen to cookies event to receive new array of cookies and sessionid.

You should call this function ONLY if you believe cookies have expired, e.g. you logged into your account from another IP / browser and you are getting HTTP 403 etc.

You do NOT have to call this method on startup as it's automatically called by Vapor after successfully logging in.

Kind: instance method of API

Utils

Kind: global class

new Utils(Vapor)

Utils class constructor. Instance of this class is available via getUtils.

Param Type Description
Vapor Object Vapor instance.

utils.isAdmin(steamID) ⇒ Boolean

Deprecated

Returns whether a user is admin or not.

This method will be removed in the next major version. Use built-in plugin 'admins' instead.

Kind: instance method of Utils
Returns: Boolean - Result.

Param Type Description
steamID string User's Steam ID.

utils.getUserDescription(steamID, format) ⇒ string

Returns easy-to-read user description.

Format allows placeholders:

  • %username - for Steam username
  • %steamid64 - for 64 bit SteamID
  • %accountid - for account ID

Kind: instance method of Utils
Returns: string - User's description.

Param Type Description
steamID string User's Steam ID.
format string Format string.

utils.stringToEnum(string, enumList) ⇒ number

Returns first enum value that contains the given string.

Kind: instance method of Utils
Returns: number - Enum value or null if not found.

Param Type Description
string string Enum name.
enumList Object List of enums from the Steam object.

Example

// returns 5, which is equal to Steam.EPersonaState.LookingToTrade
var tradeState = utils.stringToEnum("trade", Steam.EPersonaState);
steamFriends.setPersonaState(tradeState);

utils.enumToString(value, enumList) ⇒ string

Returns string description for the given enum value.

Kind: instance method of Utils
Returns: string - Enum string description or null if not found.

Param Type Description
value number Enum value.
enumList Object List of enums from the Steam object.

Example

// returns "LookingToTrade"
var stateDescription = utils.stringToEnum(5, Steam.EPersonaState);

utils.accountIDToSteamID(accountID) ⇒ string

Converts account ID to 64 bit SteamID string.

Kind: instance method of Utils
Returns: string - Converted 64 bit SteamID.

Param Type Description
accountID number User's account ID.

utils.steamIDToAccountID(steamID) ⇒ number

Converts 64 bit SteamID string to account ID.

Kind: instance method of Utils
Returns: number - Account ID.

Param Type Description
steamID string 64 bit SteamID.

utils.getTimestamp(unixTimestamp, format) ⇒ string

Converts unix timestamp into formatted timestamp.

Kind: instance method of Utils
Returns: string - Formatted timestamp.

Param Type Description
unixTimestamp number Unix timestamp.
format string Timestamp format.