/*************** Example anope fantasy !commands module template Use this to code your own. Scroll down to find the parts to modify. Examples here are !badger !hello !throw and !roll Template module by Lakitu7 Lakitu7@dorksnet.org aim:lakitu7 irc.dorksnet.org It would not have been possible without generous help from Certus and Rob, members of the most genuinely helpful and friendly development team I've ever seen. Changelog: 1.0 Initial release 1.1 Optimization + Fixed a nasty bug that would segfault services when someone started a line with a space :[ Below is a reference of the variables used in the example !commands variable explanations for example string: !test 1 2 3 4 5 6 7 8 text = !test 1 2 3 4 5 6 7 8 cmd = !test params = 1 2 3 4 5 6 7 8 param1 = 1 param2 = 2 param3 = 3 etc. ci->name = #channel ci->bi->nick = nickname of bot in that channel u->nick = nickname who said the command ***************/ #include "module.h" #define AUTHOR "Lakitu7, with generous help from Certus and Rob" #define VERSION "1.1" int my_privmsg(char *source, int ac, char **av); int mynewmsg(User * u, ChannelInfo * ci); char *mod_current_buffer = NULL; char *text=NULL; void AnopeInit(void){ Message *msg = NULL; int status; msg = createMessage("PRIVMSG", my_privmsg); status = moduleAddMessage(msg, MOD_HEAD); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); alog("FantasyTemplate: Fantasy !Commands Module Template loaded, message status [%d]", status); srand(time(NULL)); //for random functions used in !roll example. You can remove this if not using any random numbers in your !commands } void AnopeFini(void) { } int my_privmsg(char *source, int ac, char **av) { User *u; ChannelInfo *ci; if (ac != 2) /* First, some basic checks */ return MOD_CONT; if (!(u = finduser(source))) { /* make sure the source is a user*/ return MOD_CONT; } if (*av[0] == '#') { /* make sure it's being said in a channel*/ if (s_BotServ && (ci = cs_findchan(av[0]))) if (!(ci->flags & CI_VERBOTEN) && ci->c && ci->bi) if (mod_current_buffer) { //these three lines optimize by skipping text = mod_current_buffer; //more stuff if the line does not start with ! if(text[0]=='!') //If you want to make commands that don't, remove them. mynewmsg(u, ci); /* This is the function we call on every channelmsg */ }} return MOD_CONT; } int mynewmsg(User * u, ChannelInfo *ci) //called every channel message said in a channel where a bot is assigned { char *cmd=NULL; //initialize everything char *text=NULL; char *param1=NULL; char *param2=NULL; char *param3=NULL; char *param4=NULL; char *param5=NULL; char *params=NULL; char dilim = ' '; //get the info we need if (mod_current_buffer) { text = mod_current_buffer; } cmd = myStrGetToken(text, dilim, 0); param1 = myStrGetToken(text, dilim, 1); param2 = myStrGetToken(text, dilim, 2); param3 = myStrGetToken(text, dilim, 3); param4 = myStrGetToken(text, dilim, 4); param5 = myStrGetToken(text, dilim, 5); params = moduleGetLastBuffer(); //debug function below outputs ALL channel text to a log/logchannel. Don't use this. //alog("%s: User: %s Channel: %s %s %s %s %s %s %s", s_BotServ,u->nick, ci->name,cmd, param1,param2,param3,param4,param5); if(!cmd) //if there is no first word (when the line starts with a space), stop to prevent crash. return MOD_CONT; /*********modify under here to create your own commands*********************/ //example IF command to check for access level checks //if (check_access(u, ci, CA_SAY)) //verify that user has at least "say" level access in the channel. //use !strcmp instead of !stricmp if you need case sensitivity if((ci->botflags & BS_FANTASY)&& check_access(u, ci, CA_FANTASIA)) { //verify that FANTASY is turned on and user has access to its commands if (!stricmp(cmd, "!badger")) send_cmd(ci->bi->nick, "PRIVMSG %s :BADGER BADGER BADGER!", ci->name); else if (!stricmp(cmd, "!hello")) if(param1) //if no parameters given, say an alternate message instead of having "(null)" send_cmd(ci->bi->nick, "PRIVMSG %s :Hello %s!", ci->name, params); else send_cmd(ci->bi->nick, "PRIVMSG %s :Hello %s!", ci->name, u->nick); else if (!stricmp(cmd, "!throw")) if(param1 && param2) send_cmd(ci->bi->nick, "PRIVMSG %s :%cACTION throws a %s at %s %c", ci->name, 1, param1, param2, 1); else if(param1) send_cmd(ci->bi->nick, "PRIVMSG %s :%cACTION throws a %s%c", ci->name, 1, param1, 1); else send_cmd(ci->bi->nick, "PRIVMSG %s :%cACTION throws a fit%c", ci->name, 1, 1); else if(!strcmp(cmd, "!roll")) //rolls a 6 sided die send_cmd(ci->bi->nick, "PRIVMSG %s :%d", ci->name, (rand()%6)+1); } //end ******************STOP MODIFYING HERE********************* if (!cmd) return MOD_CONT; return MOD_CONT; }