Jump to content
McKay Development

SnaBe

Member
  • Posts

    43
  • Joined

  • Last visited

Community Answers

  1. SnaBe's post in Chat messages with some specific input (multiple lines) was marked as the answer   
    Yes, it's possible to have "inputs" in a message or command. 
     
    To do so, you'll have to learn about regex.
     
    Here's an example:
    //Act on chat messages & commands client.on('friendMessage', (steamID, message) => { //Command place holder var cmd; //Does the message match our buy command if(cmd = message.match(/^!buy (\d+) (\D+)/i)) { //The amount to buy (input string to number) var amount = Number(cmd[1]); //The item to buy (input string) var item = cmd[2]; //Log the regex values console.log(`User ${steamID} would like to purchase ${amount} of ${item}`); //Call your function that takes these two values as arguments. sellItem(steamID, amount, item); } }); In the example above we're looking for a buy command match. The string has to start with !buy, contain a number & a set of characters. For numbers only we use 'd' & for characters we use 'D'. The number is the amount of an item to buy, while the charaters is the item's name. We can access these values by using the following notation cmd[1]. Here 1 is the first regex match & cmd[2] is the second one.
     
    The (), \ & + all have different uses, escpeially when it comes to matching something from a string using regex. You can read more about those used in the example above here.
     
    I hope this helps! 
  2. SnaBe's post in Trying to make a bot. was marked as the answer   
    Here's how I would do it.
    const config = require('./config.json'); const SteamUser = require('steam-user'); const SteamCommunity = require('steamcommunity'); const client = new SteamUser(); const community = new SteamCommunity(); const user = "76561198089922529"; const message = "Hey bud."; //Our account details const logOnOptions = { accountName: config.account.username, password: config.account.password }; //Try to log on client.logOn(logOnOptions); //We logged on client.on('loggedOn', function(details) { console.log('Bot ' + client.steamID.getSteamID64() + ' successfully logged into Steam!'); client.setPersona(SteamUser.Steam.EPersonaState.LookingToTrade, config.bot.displayName); client.gamesPlayed(config.tf2.ID); }); //Error login to Steam client.on('error', function(err) { console.log('Error: ' + err); }); //Got web session and cookies client.on('webSession', function(sessionID, cookies) { console.log('Got web session from Steam.'); community.setCookies(cookies); //We can now post a comment commentOnUserProfile(user, message); }); //Custom function to post and log comments on steam profiles function commentOnUserProfile(steamID, message) { community.postUserComment(steamID, message, function(err) { if(err) { console.log(err); } else { console.log('Successfully commented: ' + message) } }); }
×
×
  • Create New...