Jump to content

Code tutorials

Recommended Posts

  • Administrators

Making your own command processor


In this function:

  function Receive(u, j) {


  if(j.action == 'message')
    doCommands(j.elements.t, u);

then add something like this:

  doCommands(u, m)
    let i,id
    if(!m) return; // ignore blank messages
    if(m.charAt(0) != '@') return; // first character must be @
    m = m.toLowerCase().substr(1).split(' '); // Split the command line into an array
      case 'start' :
        main(); // call game main to restart
      case "add":
      case 'invite' :
        if(m[1] == 'off') { delete this.bot.invited; return; } // turn off invite mode
        if(!this.bot.invited) this.bot.invited = {}; // invited mode on
        id = this.xInt(m[1]);
        if(id && this.bot.users[id]) { this.bot.invited[id] = true; return; }
        id = m[1].toLowerCase();
        for(i in this.bot.users)
          if(id == this.bot.users[i].regname) { this.bot.invited[i] = true; return; }
        this.bot.sendMessage(m[1].replace(/[^A-Za-z0-9_]/g, '')+' not in the chat');
      case "remove":
      case "uninvite":
        if(!this.bot.invited) return;
        id = this.xInt(m[1]);
        if(id && this.bot.invited[id]) { delete this.bot.invited[id]; return; }
        id = m[1].toLowerCase();
        for(i in this.bot.users)
          if(id == this.bot.users[i].regname) { delete this.bot.invited[i]; return; }
      case "list":
        let cMsg = '';
          cMsg = "Invites are off";
          for(id in this.bot.invited)
            cMsg += (this.bot.users[id].regname ? this.bot.users[id].regname : id)+' ';
            cMsg = "Invited users: "+cMsg;
            cMsg = "No invited users";

This is a basic command manager. You can add commands if you want or change the messages.


You could also add 

if(u != 42) // Only allow 42 to control this game
  bot.sendMessage("You need to know the answer to xat, the universe and everything to control this game!");

Note do not use


or the library will handle commands for you

  • Award 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.