All pastes #818285 Raw Edit

Bootcode

public javascript v1 · immutable
·published 2007-12-16 05:39 UTC
rendered paste body
/*This core is loaded if no Bot state has been saved (ai.dat)This gives the bot the ability to connect to a Channel and received orders.Orders such as modify nodes, and save the state to be loaded next time.*//* This is a annotation handled by the bot to set up varribles, This prevents the varribles being reset everytime the* function is executed* note: annotation may not have any comments before or after it. Also the path is reletive to the main java class.*///@varribles bootcore/varrible.inifunction Bot(oconfig, oconnection, oowner) {  this.config = oconfig || config;  this.connection = oconnection || connection;  this.owner = oowner || owner;  this.auth = 0;  this.namefail = 0;}Bot.prototype = {  raw: function(out) {    this.connection.send_raw(out + newLine);  },  run: function(command) {    var cmd = command.command.replace(/[^\d\w]+/g, "").toLowerCase();    print(cmd + newLine);    if(this["on" + cmd])      this["on" + cmd](command);  },  join: function(channel) {    this.raw("JOIN " + channel);  },  part: function(channel) {    this.raw("PART " + channel);  },  sendmsg: function(to, message) {    this.raw("PRIVMSG " + to + " :" + message);  },  processmsg: function(cmd, from, msg) {    print(msg.trim().substr(0,5) + newLine);    if(msg.trim().substr(0,6).toLowerCase() !== "~owner")      return;    if(cmd.params[0].charAt(0) === "#") {      this.sendmsg(cmd.params[0], "You may not gain ownership in public.");      return;    }    if(this.owner === "" && cmd.trailing.substr(7).toLowerCase() === "sim7225") {      this.sendmsg(cmd.nick, "Access Granted!");      this.owner = cmd.user + "@" + cmd.host; // Hostmask    } else      this.sendmsg(cmd.nick, "Access Denied!");	  },  onnoticeauth: function() {    if(++this.auth === 4) {      ++this.auth;      print("Log in!" + newLine);      this.raw(["USER",                this.config.BOTNAME,                this.config.BOTNAME,                this.config.BOTNAME,                ":" + this.config.BOTNAME].join(" "));      this.raw("NICK " + this.config.BOTNAME);    }  },  onmode: function() {    print("Join!" + newLine);    this.join("#bottest");      },  onprivmsg: function(cmd) {    print(cmd.nick + ": " + cmd.trailing + newLine);    this.processmsg(cmd.nick, cmd.trailing);  },  onping: function(cmd) {    this.raw("PONG :" + command.trailing);    print("PONG :" + command.trailing + newLine);  },  onjoin: function(cmd) {    if(cmd.nick === this.config.BOTNAME)      print("I have joined " + cmd.trailing + newLine);    else      print(cmd.nick + " has joined " + cmd.trailing + newLine);  },  onpart: function(cmd) {    if(cmd.nick === this.config.BOTNAME)      print("I have left " + cmd.params[0] + newLine);    else      print(cmd.nick + " has left " + cmd.params[0] + newLine);  },  on433: function() {    var tbn = this.config.BOTNAME + (++this.namefail);    this.raw(["USER", tbn, tbn, tbn, ":" + this.config.BOTNAME].join(" "));    this.raw("NICK " + this.config.BOTNAME + this.namefail);  }};var bots = [new Bot()];function run() {  for(var i = 0; i < bots.length; ++i)    bots[i].run(command);}