Skip to content

Code Module: friends.js

Michael Barrett edited this page Jun 1, 2018 · 7 revisions
const friends = require('../../core/friends.js');

console.log(friends.idOf('twisterghost'));

The friends.js module gives access to the friends list, messaging and friend management. It exposes a cornucopia of helpful functions:

friends.nameOf(id)

Returns the current known steam name of the given user id.

friends.idOf(name [, fuzzy])

Returns the steam ID of the given steam name. Set fuzzy to true to use fuzzy search.

friends.isAdmin(id)

Returns true if the given userid is listed as an administrator in data/config.json

friends.set(id, property, value)

Sets an arbitrary property on the user with the given id.

friends.get(id, property)

Gets an arbitrary property from the user with the given id. Returns undefined if the property was not found.

friends.getAllFriends()

Returns the entire friends list object. Be gentle.

friends.getMute(id)

Returns true if the user with the given ID has set Jankbot to mute.

friends.setMute(id, mute)

Sets the mute status for the given user to on (true) or off (false).

friends.messageUser(id, message)

Messages the user with the given id the given message.

friends.broadcast(id, message)

Broadcasts a message to every user except the user with the given ID. Returns true when the broadcast was sent, and false if it was prevented by spam protection. A user cannot broadcast more than once every 10 minutes unless they are an administrator. If you are making a module that requires a broadcast to be sent more often than once per 10 minutes, you can still manually send messages to each user with friends.forEach().

friends.forEach(callback)

Runs the given callback for each friend, passing in the friend ID:

friends.forEach(function(friend) {
  friends.set(friend, 'somekey', 'somevalue');
});