Skip to content
Snippets Groups Projects
Commit 16f6428d authored by mcmlxxix's avatar mcmlxxix
Browse files

Sample "dice rolling" IRC bot module (Must be added to ctrl/ircbot.ini to use)

parent 06e91224
No related branches found
No related tags found
No related merge requests found
/*
IRC bot module - by Matt Johnson (MCMLXXIX) - 2010
This is a sample IRC bot module to demonstrate how such modules work.
More than one module can be loaded into the main IRC bot at a time,
but be careful when setting your bot commands (in '<botname>_commands.js')
if there are duplicate command names, they will be superseded in the order
in which they are loaded (in the order they are listed in ircbot.ini).
*/
var working_dir=this.dir;
/* This method is executed by the IRCBot during its "save_everything()" cycle */
this.save=function()
{
//var s_file=new File(working_dir + "file.ini");
//if(!s_file.open(file_exists(s_file.name)?"r+":"w+")) return false;
/*
do some work, save some data.....
*/
//s_file.close();
}
/* This method is executed by the IRCBot during its "main()" loop, once per cycle (DO NOT MAKE A LOOP) */
this.main=function(srv)
{
/* Do some work here.
You can use a timer to time events or process scores.
You have access to server methods and properties. */
}
/* Module objects here: Everything here is loaded within the context of the "Modules()" object */
\ No newline at end of file
this.Bot_Commands["ROLL"] = new Bot_Command(0,false,false);
this.Bot_Commands["ROLL"].usage =
get_cmd_prefix() + "ROLL <num_dice>d<num_sides>";
this.Bot_Commands["ROLL"].help =
"This is the command used to roll dice.";
this.Bot_Commands["ROLL"].command = function (target,onick,ouh,srv,lvl,cmd) {
cmd.shift();
var num_dice;
var sides_per_die;
if(!cmd[0]) {
/* If no arguments are supplied, assume a roll of two six-sided dice. */
num_dice=2;
sides_per_die=6;
} else {
var args=cmd[0].toUpperCase().split("D");
num_dice=args[0];
sides_per_die=args[1];
}
if(!num_dice>0 || !sides_per_die>0) {
srv.o(target,"Invalid arguments.");
return;
}
var total=roll_them_dice(num_dice,sides_per_die);
srv.o(target,onick + " rolled: " + total);
return;
}
this.Bot_Commands["DICE"] = new Bot_Command(0,false,false);
this.Bot_Commands["DICE"].help =
"To roll some dice, type '" + get_cmd_prefix() + "ROLL <num_dice>d<num_sides>'. " +
"For a full list of commands, type '" + get_cmd_prefix() + "HELP'.";
this.Bot_Commands["DICE"].command = function (target,onick,ouh,srv,lvl,cmd) {
srv.o(target,"Help: " + this.help);
return;
}
/* IRC Bot Module - Server Commands
You would place all of your module functions in this file. */
this.Server_command=function(srv,cmdline,onick,ouh)
{
var cmd=IRC_parsecommand(cmdline);
switch (cmd[0]) {
case "JOIN":
if (onick == srv.curnick) break;
// Someone else joining? Let's send them a private welcome message!
srv.o(onick,"Welcome to the DiceBot show!");
srv.o(onick,"This is a module for IRCBot - by Cyan");
break;
case "PRIVMSG":
if ((cmd[1][0] == "#") || (cmd[1][0] == "&")) {
var chan = srv.channel[cmd[1].toUpperCase()];
if (!chan)
break;
if (!chan.is_joined)
break;
if(srv.users[onick.toUpperCase()]) {
/* You can do special command processing here, if you like.
This is currently set up to parse public room messages for
things like trivia answers, or other responses that
are inconvenient for users to submit with a command prefix */
}
}
break;
default:
break;
}
}
function roll_them_dice(num_dice,num_sides)
{
var total=0;
for(var d=0;d<num_dice;d++) {
total+=random(num_sides)+1;
}
return total;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment