Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "xchat-plugin.h"
- // Config settings
- #define MyNick "NovaYoshi"
- #define Enable_System 1
- #define Enable_Direct 1
- #define BITLBEE_SERVER "im.bitlbee.org"
- #define PLUGIN_IPC_NAME "NovaBotBase"
- #include <string.h>
- #include <stdio.h>
- #include <time.h>
- #include <ctype.h>
- #include <stdlib.h>
- #define PNAME "NovaBotBase"
- #define PDESC "8====D~~~~~~"
- #define PVERSION "5.0.6b"
- #define BotOwnerListSize 8
- #define SpawnListSize 64
- static xchat_plugin *ph; /* plugin handle, needed for any XChat call */
- static unsigned int PowerTildeLock = 1;
- static int PrepOkay;
- struct SpawnInfo {
- int Slot;
- int TriggerOnClear;
- int TimeAmount;
- char User[64];
- char Command[1024];
- char Server[256];
- char Channel[256];
- xchat_context *Context; // if NULL, have to find it using two above fields
- };
- static xchat_hook *SpawnHook[SpawnListSize] = {[0 ... SpawnListSize-1] = NULL};
- static struct SpawnInfo *SpawnInfos[SpawnListSize];
- static int spawntimer_cb(void *userdata) {
- struct SpawnInfo *Spawn = (struct SpawnInfo *)userdata;
- if(Spawn) {
- if(xchat_set_context(ph,Spawn->Context))
- xchat_command(ph, Spawn->Command);
- else
- xchat_printf(ph, "Context switch failed for spawn %i \n", Spawn->Slot);
- SpawnHook[Spawn->Slot]=NULL;
- free(Spawn);
- }
- return 0;
- }
- static int ClearSpawns(char *User) {
- int Freed = 0; int Slot;
- for(Slot=0;Slot<SpawnListSize;Slot++)
- if(SpawnHook[Slot]!=NULL) {
- if(User != NULL && strcasecmp(User, SpawnInfos[Slot]->User))
- continue;
- struct SpawnInfo *FreeMe = xchat_unhook(ph, SpawnHook[Slot]);
- if(FreeMe != NULL) {
- if(FreeMe->TriggerOnClear)
- free(FreeMe);
- }
- SpawnHook[Slot]=NULL;
- Freed++;
- }
- return(Freed);
- }
- static int SpawnTimeCalc(char *Amount, char *Unit) {
- double Time = strtod(Amount, NULL);
- switch(*Unit) {
- case 'd':
- Time*=24;
- case 'h':
- Time*=60;
- case 'm':
- Time*=60;
- case 's':
- Time*=1000;
- }
- return Time;
- }
- static struct SpawnInfo* CreateSpawn(int Time, char *Command) {
- struct SpawnInfo *Spawn = (struct SpawnInfo*)malloc(sizeof(struct SpawnInfo));
- if(Spawn == NULL) return NULL;
- int Slot;
- for(Slot = 0; Slot<16; Slot++)
- if(SpawnHook[Slot] == NULL)
- if(Spawn != NULL) {
- strcpy(Spawn->Command, Command);
- strcpy(Spawn->User, "$");
- strcpy(Spawn->Channel, xchat_get_info(ph, "channel"));
- Spawn->TriggerOnClear = 0;
- Spawn->Context = xchat_get_context(ph);
- Spawn->Slot = Slot;
- SpawnHook[Slot] = xchat_hook_timer(ph, Time, spawntimer_cb, Spawn);
- SpawnInfos[Slot] = Spawn;
- return(Spawn);
- }
- xchat_printf(ph, "Could not find a free spawn slot\n");
- free(Spawn);
- return NULL;
- }
- // Config strings
- static char HelpSite[256] = "http://www.smwiki.net/wiki/NovaBot";
- static char BotNick[64] = "NovaBot";
- static char BotOwner[BotOwnerListSize][64] = {"NovaYoshi","NovaChakat","NovaRooey","NovaPony","","","",""};
- static char BotPrefix[16] = "nb.";
- // Config flags
- static char BridgeEnabled = 0;
- static char ErrorOnBadCommand = 1;
- static char RandomFunnyStuff = 1;
- static char NoticeCommands = 1;
- static char BlockExec = 1;
- static char ErrorOnNoCmdPM = 1;
- static char AllowSetProfiles = 1;
- static char AllowGetProfiles = 1;
- static char AllowNickFix = 1;
- static char AllowMiscCommands = 1;
- static char JoinOnInvite = 1;
- static char ShowPluginIPC = 0;
- enum ConfigTypes {
- CONFIG_STRING,
- CONFIG_BOOLEAN,
- CONFIG_INTEGER,
- };
- struct {
- char *Name; // Name to recognize the option by
- void *Data; // Pointer to the data OR a function pointer
- char Type; // Data type. Set it to something in ConfigTypes
- short Len; // String length, so there aren't any overflows
- const char *Desc; // A description that isn't used anywhere!
- } ConfigOptions[] = {
- {"Nick", BotNick, CONFIG_STRING, 64, "When 'nickfix' is used, the bot will change to this"},
- {"Owner1", BotOwner[0], CONFIG_STRING, 64, "1st nick allowed to use /notice commands"},
- {"Owner2", BotOwner[1], CONFIG_STRING, 64, "2nd nick allowed to use /notice commands"},
- {"Owner3", BotOwner[2], CONFIG_STRING, 64, "3rd nick allowed to use /notice commands"},
- {"Owner4", BotOwner[3], CONFIG_STRING, 64, "4th nick allowed to use /notice commands"},
- {"Prefix", BotPrefix, CONFIG_STRING, 16, "Prefix used for all bot commands"},
- {"HelpSite", HelpSite, CONFIG_STRING, 256, "Site for the 'help' command"},
- {"Bridge", &BridgeEnabled, CONFIG_BOOLEAN, 0, "If ON, bot will bridge identically named channels"},
- {"ErrOnBadCmd", &ErrorOnBadCommand, CONFIG_BOOLEAN, 0, "If ON, bot will give a link to the help site if nothing traps a command"},
- {"FunnyStuff", &RandomFunnyStuff, CONFIG_BOOLEAN, 0, "If ON, bot will do various stupid things"},
- {"NoticeCmds", &NoticeCommands, CONFIG_BOOLEAN, 0 ,"If ON, bot will allow /notice admin commands to be used"},
- {"BlockExec", &BlockExec, CONFIG_BOOLEAN, 0, "If ON, bot will trap and stop /exec"},
- {"ErrOnNoCmdPM", &ErrorOnNoCmdPM, CONFIG_BOOLEAN, 0, "If ON, bot will complain when people PM it something that isn't a command"},
- {"AllowFurGet", &AllowGetProfiles, CONFIG_BOOLEAN, 0, "If ON, users can use the 'furget' command"},
- {"AllowFurSet", &AllowSetProfiles, CONFIG_BOOLEAN, 0, "If ON, users can use the 'furset' command"},
- {"AllowMiscCmd", &AllowMiscCommands, CONFIG_BOOLEAN, 0, "If ON, users can use the various built-in commands"},
- {"AllowNickFix", &AllowNickFix, CONFIG_BOOLEAN, 0, "If ON, users can use the 'nickfix' command"},
- {"JoinOnInvite", &JoinOnInvite, CONFIG_BOOLEAN, 0, "If ON, bot will join channels it is invited to"},
- {"ShowPluginIPC", &ShowPluginIPC, CONFIG_BOOLEAN, 0, "If ON, plugin IPC messages will be shown"},
- {NULL}, // <-- end marker
- };
- // returns NULL if okay, otherwise it returns an error message
- char *SetConfigByName(char *Item, char *Value) {
- int i;
- char *CharPointer;
- for(i=0;ConfigOptions[i].Name != NULL;i++) {
- if(!strcasecmp(Item, ConfigOptions[i].Name)) {
- if(ConfigOptions[i].Data == NULL)
- return "Config item points to NULL";
- switch(ConfigOptions[i].Type) {
- case CONFIG_STRING:
- if(strlen(Value) < ConfigOptions[i].Len) {
- strcpy((char*)ConfigOptions[i].Data, Value);
- return NULL;
- }
- else
- return "String's too long";
- case CONFIG_BOOLEAN:
- CharPointer = ConfigOptions[i].Data;
- if(!strcasecmp(Value, "on"))
- *CharPointer=1;
- else if(!strcasecmp(Value, "off"))
- *CharPointer=0;
- else
- return "Must be \"on\" or \"off\"";
- return NULL;
- default:
- return "Unknown type?";
- }
- }
- }
- return "No options by that name?";
- }
- int GetConfigByName(char *Item, char **Str, int *Int) {
- int i;
- if(Str != NULL)
- *Str = NULL;
- for(i=0;ConfigOptions[i].Name != NULL;i++) {
- if(!strcasecmp(Item, ConfigOptions[i].Name)) {
- if(ConfigOptions[i].Data == NULL)
- return -2;
- switch(ConfigOptions[i].Type) {
- case CONFIG_STRING:
- *Str = (char*)ConfigOptions[i].Data;
- return 1;
- case CONFIG_BOOLEAN:
- *Int = *(char*)ConfigOptions[i].Data;
- return 3;
- default:
- return -3;
- }
- }
- }
- return -1;
- }
- // Create a pointer to someone's database entry
- static char *CreateDataPath2(char *Buffer, char *Group, char *Nick, char *FileType) {
- char NickBuf[512];
- int i=0;
- while(1) {
- NickBuf[i]=tolower(Nick[i]);
- if(NickBuf[i]=='/' || NickBuf[i]=='\\')
- NickBuf[i] = '-';
- if(0==Nick[i++])
- break;
- }
- sprintf(Buffer, "%s/NovaBot/data/%s%s%s", xchat_get_info(ph, "xchatdirfs"),Group,NickBuf,FileType);
- return(Buffer);
- }
- // Check if a message starts with a given command, and if so, return the argument
- static int RecognizeCommand(char *Msg, const char *Cmd, char **ArgPtr) {
- if(!memcmp(Msg, Cmd, strlen(Cmd))) {
- if(ArgPtr != NULL)
- *ArgPtr = Msg+strlen(Cmd);
- if(**ArgPtr == 0) return(0);
- return(1);
- }
- return(0);
- }
- // Strips out any colors or text effects, then does a nick comparison
- static int MyNickCmp(char *N1, char *N2) {
- static char *StripName;
- StripName = xchat_strip(ph, N1, -1, 3);
- if(!strcasecmp(StripName, N2)) {
- xchat_free(ph, StripName);
- return 0;
- }
- xchat_free(ph, StripName);
- return 1;
- }
- // Find someone in the bot owner list (-1 if they're not in it)
- static int IsBotOwner(char *Nick, xchat_context *Context) {
- int i;
- for(i=0;i<BotOwnerListSize;i++)
- if(!MyNickCmp(Nick,BotOwner[i]))
- return i;
- return -1;
- }
- // Pretty much the core of NovaBot
- static int ReactGlobalCommand(xchat_context *Context, char *Nick, char *Message, char *ReplyCmd, char *ModeChar) {
- static char Temp[512];
- int already = 0;
- int i;
- xchat_set_context(ph,Context);
- char LowerBuffer[2048]; // big buffer sizes
- char *MkLowPeek = Message;
- char *MkLowPoke = LowerBuffer;
- // Make a useless lowercase version of the message
- while(*MkLowPeek)
- *(MkLowPoke++)=tolower(*(MkLowPeek++));
- *MkLowPoke = 0;
- char *ArgPtr; // pass to RecognizeCommand
- char *MessageNoPF; // pointer to the actual command name past the prefix
- if(!RecognizeCommand(LowerBuffer, BotPrefix, &MessageNoPF)) {
- xchat_print(ph, "???");
- return 0;
- }
- MessageNoPF = MessageNoPF - LowerBuffer + Message;
- if((RecognizeCommand(MessageNoPF, "furget ", &ArgPtr)|| !strcasecmp(MessageNoPF,"furget")) && !already && AllowGetProfiles) {
- if(!strcasecmp(MessageNoPF, "furget")) ArgPtr = Nick;
- char *Trim = strchr(ArgPtr, ' ');
- if(Trim != NULL)
- *Trim = 0;
- CreateDataPath2(Temp, "furprofile/", ArgPtr, ".txt");
- FILE *Profile = fopen(Temp, "rb");
- if(Profile!=NULL) {
- MkLowPoke = Temp;
- for(i=5;i!=EOF;) {
- i=fgetc(Profile);
- *MkLowPoke = i;
- if(i == '`'){*MkLowPoke = 0; break;}
- MkLowPoke++;
- }
- fclose(Profile);
- xchat_commandf(ph, "%s %s is: %s", ReplyCmd, ArgPtr, Temp);
- } else {
- xchat_commandf(ph, "%s I don't think %s has a profile yet. (You can set one for yourself with nb.furset Your Description Here)", ReplyCmd, ArgPtr);
- }
- already = 1;
- }
- if(!strcasecmp(MessageNoPF,"furset") || !strcasecmp(MessageNoPF,"furset ")) {
- xchat_commandf(ph, "%s You have to put text after nb.furset or I'm not going to know what to set your description to", ReplyCmd);
- already = 1;
- }
- if(RecognizeCommand(MessageNoPF, "furset ", &ArgPtr) && !already && AllowSetProfiles) {
- CreateDataPath2(Temp, "furprofile/", Nick, ".txt");
- int Error = 0;
- char *Test;
- FILE *Profile = fopen(Temp, "wb");
- if(Profile!=NULL) {
- sprintf(Temp, "%s ", Nick);
- if(RecognizeCommand(ArgPtr, Temp, &Test)) {
- Error = 1;
- ArgPtr = Test;
- }
- if(RecognizeCommand(ArgPtr, "is ", &Test) || RecognizeCommand(ArgPtr, "Is ", &Test)) {
- Error = 1;
- ArgPtr = Test;
- }
- fprintf(Profile, "%s`", ArgPtr);
- if(!Error)
- xchat_commandf(ph, "%s Saved :3", ReplyCmd);
- else
- xchat_commandf(ph, "%s Saved (Automatically fixed)", ReplyCmd);
- fclose(Profile);
- } else {
- xchat_commandf(ph, "%s Couldn't open your profile", ReplyCmd);
- }
- already = 1;
- }
- if(already) return 2;
- ArgPtr = "";
- strcpy(Temp, MessageNoPF);
- char *Find = strchr(Temp, ' ');
- if(Find != NULL) {
- *Find = 0;
- if(Find[1]) ArgPtr = Find+1;
- }
- xchat_commandf(ph,"NB_ExtCmd \"%s\" \"%s\" \"%s\" \"%s\" -A %s", ReplyCmd, Temp, Nick, ModeChar, ArgPtr);
- return 1;
- }
- // Left over from when NovaBot was a bridgebot and not a yiffbot
- static void Prep() { // Make sure this context is okay
- PrepOkay=0;
- if(xchat_get_info(ph,"channel")==NULL) {
- xchat_print(ph, "Channel returned null! \n"); return;
- }
- if(xchat_get_info(ph,"server")==NULL) {
- xchat_print(ph, "Server returned null! \n"); return;
- }
- if(!BridgeEnabled)
- return;
- PrepOkay=1;
- }
- //Emit the command in every suitable channel but the origin
- static void AllOthers(char *String, const char *Origin, const char *PassServer) {
- xchat_list *list = xchat_list_get(ph, "channels");
- if(list) {
- while(xchat_list_next(ph, list))
- if(!strcasecmp(xchat_list_str(ph, list, "channel"),Origin))
- if( strcasecmp(xchat_list_str(ph, list, "server"),PassServer)) {
- if( xchat_set_context(ph,(xchat_context *)xchat_list_str(ph, list, "context")) == 0)
- xchat_printf(ph,"Oops! Bad context! \n");
- else
- xchat_command(ph, String);
- }
- xchat_list_free(ph, list);
- }
- }
- // Hook for when NovaBot talks, so it can bridge that too
- static int imessage_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- // sloppy check to see if it is a bridged message already
- if(word[2][0] == '*' || word[2][1] == '*') return XCHAT_EAT_NONE;
- if(word[2][0] == ':' || word[2][1] == ':') return XCHAT_EAT_NONE;
- if(word[2][0] == 2 || word[2][1] == 2) return XCHAT_EAT_NONE;
- sprintf(Temp, "NBBSAY \2\2:NovaBot: %s", word[2]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // Hook for when NovaBot yiffs
- static int iaction_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- // sloppy check to see if it is a bridged message already
- if(word[2][0] == '*' || word[2][1] == '*') return XCHAT_EAT_NONE;
- if(word[2][0] == ':' || word[2][1] == ':') return XCHAT_EAT_NONE;
- if(word[2][0] == 2 || word[2][1] == 2) return XCHAT_EAT_NONE;
- sprintf(Temp, "NBBSAY *NovaBot %s", word[2]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // Doesn't do anything yet
- static int ijoin_cb(char *word[], void *userdata) {
- return XCHAT_EAT_NONE;
- }
- // Hook for receiving notices
- static int notice_cb(char *word[], void *userdata) {
- int FindIt;
- FILE *ReadPass;
- if(!NoticeCommands)
- xchat_commandf(ph, "notice %s /notice commands are disabled",word[1]);
- if(!strcasecmp(word[2], "isbot"))
- xchat_commandf(ph, "quote mode %s +B",xchat_get_info(ph,"nick"));
- char SecurityBuff[512];
- int i=0;
- for(i=0;;) {
- SecurityBuff[i]=tolower(word[2][i]);
- if(0==word[2][i++])
- break;
- }
- FindIt=0;
- char *ArgPtr;
- if(-1 != IsBotOwner(word[1], xchat_get_context(ph))) { // Ignore comands if given by someone who isn't me
- if(RecognizeCommand(word[2], "clearallspawn", &ArgPtr)) {
- xchat_commandf(ph, "notice %s Cleared %i spawn slots", word[1], ClearSpawns(NULL));
- }
- if(RecognizeCommand(word[2], "clearspawn ", &ArgPtr)) {
- xchat_commandf(ph, "notice %s Cleared %i spawn slots", word[1], ClearSpawns(ArgPtr));
- }
- if(RecognizeCommand(word[2], "^~", &ArgPtr)) {
- int SkipSecurity=0;
- char *P;
- if(RecognizeCommand(ArgPtr, "rsay ", &P)) SkipSecurity = 1;
- if(RecognizeCommand(ArgPtr, "ract ", &P)) SkipSecurity = 1;
- int ErrSecurity=0;
- if(RecognizeCommand(ArgPtr, "ns ", &P)) ErrSecurity = 1;
- if(RecognizeCommand(ArgPtr, "cs ", &P)) ErrSecurity = 1;
- if(RecognizeCommand(ArgPtr, "msg nickserv ", &P)) ErrSecurity = 1;
- if(RecognizeCommand(ArgPtr, "msg chanserv ", &P)) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"nickserv ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"chanserv ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"botserv ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"memoserv ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"hostserv ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"drop ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"access ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"ms ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"hs ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"bs ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"cs ")) ErrSecurity = 1;
- if(NULL!=strstr(SecurityBuff,"ns ")) ErrSecurity = 1;
- if(!SkipSecurity && (ErrSecurity == 1)) { xchat_commandf(ph, "notice %s driving 125 miles to your house \2right now",word[1]); return XCHAT_EAT_NONE; }
- if(PowerTildeLock == 0)
- xchat_commandf(ph, "notice %s PowerTilde is locked right now",word[1]);
- else
- xchat_commandf(ph, "%s", ArgPtr);
- return XCHAT_EAT_NONE;
- }
- int LockCmd = 0;
- if(!strcasecmp(word[2], "spawnclearall")) {
- xchat_commandf(ph, "notice %s cleared %i spawns", word[1], ClearSpawns(NULL));
- return XCHAT_EAT_NONE;
- }
- if(RecognizeCommand(word[2], "spawnclear ", &ArgPtr)) {
- xchat_commandf(ph, "notice %s cleared %i spawns", word[1], ClearSpawns(ArgPtr));
- return XCHAT_EAT_NONE;
- }
- if(RecognizeCommand(word[2], "lock ", &ArgPtr))
- LockCmd = 1;
- if(RecognizeCommand(word[2], "unlock ", &ArgPtr))
- LockCmd = 2;
- if(LockCmd) {
- char Buffer[512];
- sprintf(Buffer, "%s/NovaBot/tildepass.txt", xchat_get_info(ph, "xchatdirfs"));
- ReadPass = fopen(Buffer,"rb");
- if(ReadPass != NULL) {
- char CheckBuffer[50];
- char *PokePass = CheckBuffer;
- for(i=5;i!=EOF;) {
- i=fgetc(ReadPass);
- *PokePass = i;
- if(i == '~'){*PokePass = 0; break;}
- PokePass++;
- }
- if(!strcasecmp(ArgPtr, CheckBuffer)) {
- PowerTildeLock = LockCmd-1;
- xchat_commandf(ph, "notice %s a winrar is you (%i)", word[1], PowerTildeLock);
- }
- else {
- xchat_commandf(ph, "notice %s That isn't my password", word[1]);
- }
- fclose(ReadPass);
- } else
- xchat_commandf(ph, "notice %s file didn't open", word[1]);
- }
- }
- return XCHAT_EAT_NONE;
- }
- // Handler for when someone joins so we can voice aginas
- static int join_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- sprintf(Temp,"NBBSAY \02%s\x0f has joined this channel on %s", word[1],xchat_get_info(ph,"server"));
- if(RandomFunnyStuff) {
- if((!MyNickCmp(word[1],"Haruto")))
- xchat_commandf(ph, "bssay [Haruto] gotta do the shit ya miss");
- if(NULL !=strstr(word[1],"agina"))
- xchat_commandf(ph, "VOICE %s", word[1]);
- if((!MyNickCmp(word[1],"agina")))
- xchat_commandf(ph, "VOICE agina"); // set mode +v agina
- if((!MyNickCmp(word[1],"irgin")))
- xchat_commandf(ph, "VOICE irgin"); // set mode +v irgin
- if((!MyNickCmp(word[1],"irgin_mobile")))
- xchat_commandf(ph, "VOICE irgin_mobile"); // set mode +v irgin
- if((!MyNickCmp(word[1],"iagra")))
- xchat_commandf(ph, "VOICE iagra"); // set mode +v iagra
- }
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // For when someone leaves
- static int part_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- sprintf(Temp,"NBBSAY \02%s\x0f has left this channel on %s", word[1],xchat_get_info(ph,"server"));
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // For when someone leaves and gives a reason
- static int partr_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- sprintf(Temp,"NBBSAY \02%s\x0f has left this channel on %s (%s)", word[1], xchat_get_info(ph,"server"), word[4]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- /* When the bot gets kicked, this code runs */
- static int kicked_cb(char *word[], void *userdata) {
- if(!strcasecmp(xchat_get_info(ph, "server"),BITLBEE_SERVER))
- xchat_command(ph, "JOIN &bitlbee"); // for taking over old connections
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // Whenever someone uses /me in a channel, this code runs
- static int emote_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- sprintf(Temp,"NBBSAY *%s\x0f %s", word[1],word[2]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // NovaBot should join when invited
- static int invited_cb(char *word[], void *userdata) {
- if(JoinOnInvite)
- if(strcasecmp(word[1],"#dontjoinitsatrap")) {
- xchat_commandf(ph,"join %s",word[1]);
- char Command[512];
- sprintf(Command, "msg %s (invited by %s)", word[1], word[2]);
- CreateSpawn(2000, Command);
- }
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // Is someone PMing the bot?
- static int private_cb(char *word[], void *userdata) {
- if(!strncasecmp(word[2] ,BotPrefix, strlen(BotPrefix))) {
- char ReplyWith[100];
- sprintf(ReplyWith, "msg %s", word[1] );
- ReactGlobalCommand(xchat_get_context(ph), word[1], word[2], ReplyWith, ".");
- return XCHAT_EAT_NONE;
- }
- else
- if(!strcasecmp(BotOwner[0],"NovaYoshi"))
- if(strcasecmp(word[1],"AlcaRobot"))
- if(strcasecmp(word[1],"AlcaRobot_"))
- xchat_commandf(ph,"msg %s Not a valid command. Maybe you were trying to contact NovaYoshi instead? (use MemoServ if you have to)", word[1]);
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // handler for channel messages
- static int message_cb(char *word[], void *userdata) {
- static char Temp[512];
- char LowerBuffer[512];
- char *MkLowPeek = word[2];
- char *MkLowPoke = LowerBuffer;
- int already = 0;
- xchat_context *BackTo = xchat_get_context(ph);
- Prep();
- sprintf(Temp,"NBBSAY \2\2:%c\2\2%s\x0f: %s", word[1][0], word[1]+1,word[2]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- xchat_set_context(ph,BackTo);
- while(*MkLowPeek)
- *(MkLowPoke++)=tolower(*(MkLowPeek++));
- *MkLowPoke = 0;
- if( ( NULL != strstr(LowerBuffer,"lose") || NULL != strstr(LowerBuffer,"lost") ) && NULL != strstr(LowerBuffer," electron") ) xchat_commandf(ph, "SAY Are you sure?"); // Yes I'm positive
- /*
- if(!strcasecmp(xchat_get_info(ph,"channel"),"#novaforest")) {
- if(NULL != strstr(LowerBuffer,"what the fuck")
- || NULL != strstr(LowerBuffer,"what the heck")
- || NULL != strstr(LowerBuffer,"what the hell")
- || NULL != strstr(LowerBuffer,"fucking sucks")
- || NULL != strstr(LowerBuffer,"fuckin sucks")
- || NULL != strstr(LowerBuffer,"wtf")
- ) {
- xchat_commandf(ph, "say Don't worry about it, go back to bed");
- }
- }
- */
- if(!MyNickCmp(word[1], "root")) // Is Bitlbee trying to talk to us?
- { // automatically accept friend requests
- if(NULL != strstr(word[2],"wants to add you to his/her buddy list")
- || NULL != strstr(word[2],"is not in your buddy list yet. Do you want to add him/her now")
- || NULL != strstr(word[2],"Would you like to take over this session?"))
- xchat_commandf(ph, "say yes");
- }
- if(RecognizeCommand(LowerBuffer,BotPrefix, &MkLowPoke)){
- if(!strcasecmp(MkLowPoke,"whatchannelisthis") && !already) {
- sprintf(Temp,"NBBSAY umm, I think this is %s",xchat_get_info(ph,"channel"));
- xchat_command(ph, Temp);
- already=1;
- }
- if(!already)
- ReactGlobalCommand(BackTo, word[1], word[2], "nbsay", word[3]);
- }
- if(RandomFunnyStuff) {
- if(!strcasecmp(word[2],"!help") && !already) {
- xchat_commandf(ph, "KICK %s 8==========D~~~~~~~~~~~~~~~~~", word[1]);
- already=1;
- }
- }
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // Whenever someone gets kicked from the channel, this code runs
- static int kick_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- sprintf(Temp,"NBBSAY \02%s\x0f has been kicked by \02%s\x0f (%s)", word[2],word[1],word[4]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // Whenever someone changes their name, this code runs
- static int nick_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- sprintf(Temp,"NBBSAY \02%s\x0f is now known as \02%s\x0f", word[1],word[2]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- // Whenever someone quits, this code runs
- static int quit_cb(char *word[], void *userdata) {
- static char Temp[512]; Prep();
- if(-1 != IsBotOwner(word[1], xchat_get_context(ph)))
- PowerTildeLock = 0;
- sprintf(Temp,"NBBSAY \02%s\x0f has disconnected from %s, (%s)", word[1],xchat_get_info(ph,"server"),word[2]);
- if(PrepOkay==1)
- AllOthers(Temp,xchat_get_info(ph,"channel"),xchat_get_info(ph,"server"));
- return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
- }
- void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved) {
- *name = PNAME;
- *desc = PDESC;
- *version = PVERSION;
- }
- static int nb_config_cb(char *word[], char *word_eol[], void *userdata) {
- if(word[2] == NULL || word_eol[3] == NULL) return(XCHAT_EAT_ALL);
- xchat_printf(ph,"Setting %s to %s ", word[2], word_eol[3]);
- char *Msg = SetConfigByName(word[2], word_eol[3]);
- if(Msg!=NULL)
- xchat_printf(ph," - %s", Msg);
- xchat_printf(ph,"\n");
- return XCHAT_EAT_ALL;
- }
- static int nb_extcmd_cb(char *word[], char *word_eol[], void *userdata) {
- char Temp[512];
- char *ReplyCmd = word[2];
- char *NBCmd = word[3];
- char *Nick=word[4];
- int i;
- int ArgPtrIndex = -1;
- char *ArgPtr = NULL;
- for(i=4;i<10 && (word[i]!=NULL);i++) {
- if(!strcasecmp(word[i],"-A"))
- if(word[++i]!=NULL)
- if(strcasecmp(word[i],"")) {
- ArgPtr = word_eol[i];
- ArgPtrIndex = i;
- break;
- }
- }
- if(!strcasecmp(NBCmd,"nickfix") && AllowNickFix) {
- xchat_commandf(ph, "nick %s", BotNick);
- return XCHAT_EAT_ALL;
- }
- if(!strcasecmp(NBCmd,"help")) {
- xchat_commandf(ph, "%s Check out %s", ReplyCmd, HelpSite);
- return XCHAT_EAT_ALL;
- }
- if(!strcasecmp(NBCmd,"version")) {
- xchat_commandf(ph,"%s Currently running NovaBot version %s",ReplyCmd,PVERSION);
- return XCHAT_EAT_ALL;
- }
- if(!strcasecmp(NBCmd,"spawnmsg")) { // nb.spawnmsg Time Unit Message
- char *Message = word_eol[ArgPtrIndex+2];
- char *Ptr;
- int Time = SpawnTimeCalc(word[ArgPtrIndex], word[ArgPtrIndex+1]);
- if(RecognizeCommand(Message, "to ", &Ptr))
- sprintf(Temp, "nbsay \2%s\2, time %s", Nick, Message);
- else
- sprintf(Temp, "nbsay \2%s\2, time for %s", Nick, Message);
- struct SpawnInfo *UserSpawn = CreateSpawn(Time, Temp);
- if(UserSpawn == NULL) {
- xchat_commandf(ph,"%s Unable to create spawn (Maybe the list is maxed out)", ReplyCmd);
- return XCHAT_EAT_ALL;
- }
- strcpy(UserSpawn->User, Nick);
- xchat_commandf(ph,"%s Timer set to go off in %is/%fm/%fh",ReplyCmd, Time/1000,(float)Time/1000/60,(float)Time/1000/60/60);
- return XCHAT_EAT_ALL;
- }
- if(!strcasecmp(NBCmd,"spawnclear")) {
- xchat_commandf(ph, "%s Cleared %i spawn slots", ReplyCmd, ClearSpawns(Nick));
- return XCHAT_EAT_ALL;
- }
- xchat_printf(ph, "Unhandled ExtCmd: %s\n", word_eol[1]);
- if(ErrorOnBadCommand)
- if(NULL != word[2])
- xchat_commandf(ph, "%s Doesn't seem to be a valid command. Check %s", ReplyCmd, HelpSite);
- return XCHAT_EAT_ALL;
- }
- static int dangerous_cb(char *word[], char *word_eol[], void *userdata) {
- if(BlockExec)
- return XCHAT_EAT_ALL;
- else
- return XCHAT_EAT_NONE;
- }
- void *GetFuncByName(char *Name) {
- if(!strcasecmp(Name,"SpawnHookList")) return SpawnHook;
- if(!strcasecmp(Name,"SpawnInfoList")) return SpawnInfos;
- if(!strcasecmp(Name,"HelpSite")) return HelpSite;
- if(!strcasecmp(Name,"ph")) return ph;
- if(!strcasecmp(Name,"SetConfigByName")) return SetConfigByName;
- if(!strcasecmp(Name,"GetConfigByName")) return GetConfigByName;
- if(!strcasecmp(Name,"CreateDataPath2")) return CreateDataPath2;
- if(!strcasecmp(Name,"RecognizeCommand")) return RecognizeCommand;
- if(!strcasecmp(Name,"MyNickCmp")) return MyNickCmp;
- if(!strcasecmp(Name,"IsBotOwner")) return IsBotOwner;
- if(!strcasecmp(Name,"ClearSpawns")) return ClearSpawns;
- if(!strcasecmp(Name,"SpawnTimeCalc")) return SpawnTimeCalc;
- if(!strcasecmp(Name,"CreateSpawn")) return CreateSpawn;
- return NULL;
- }
- static int nb_mrequest_cb(char *word[], char *word_eol[], void *userdata) {
- int Type = (int)userdata;
- int Int;
- char *Str;
- if(!strcasecmp(word[2],PLUGIN_IPC_NAME)) { // It's a message for NovaBot! :P
- switch(Type) {
- case 1: // ping
- xchat_commandf(ph, "nb_mPong %s %s", PLUGIN_IPC_NAME, word[3]);
- break;
- case 2: // ptr
- xchat_commandf(ph, "nb_mSayPtr %s %s %p", PLUGIN_IPC_NAME, word[3], GetFuncByName(word[3]));
- break;
- case 3: // inf
- switch(GetConfigByName(word[3], &Str, &Int)) {
- case 0: // fail
- xchat_commandf(ph, "nb_mSayInf %s %s fail", PLUGIN_IPC_NAME, word[3]);
- break;
- case 1: // string
- xchat_commandf(ph, "nb_mSayInf %s %s %s", PLUGIN_IPC_NAME, word[3], Str);
- break;
- case 2: // int
- xchat_commandf(ph, "nb_mSayInf %s %s %i", PLUGIN_IPC_NAME, word[3], Int);
- break;
- case 3: // bool
- xchat_commandf(ph, "nb_mSayInf %s %s %i", PLUGIN_IPC_NAME, word[3], Int);
- break;
- }
- break;
- }
- }
- if(ShowPluginIPC)
- xchat_printf(ph, "NBIPC (%i) %s\n", Type, word_eol[1]);
- return XCHAT_EAT_ALL;
- }
- static int nb_manswer_cb(char *word[], char *word_eol[], void *userdata) {
- int Type = (int)userdata;
- if(ShowPluginIPC)
- xchat_printf(ph, "NBIPC (%i) %s\n", Type, word_eol[1]);
- return XCHAT_EAT_ALL;
- }
- int xchat_plugin_deinit() {
- ClearSpawns(NULL);
- return 1;
- }
- int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name,
- char **plugin_desc, char **plugin_version, char *arg) {
- /* we need to save this for use with any xchat_* functions */
- ph = plugin_handle;
- /* tell xchat our info */
- *plugin_name = PNAME;
- *plugin_desc = PDESC;
- *plugin_version = PVERSION;
- /* If I didn't insist on keeping NovaBot's bridge features I could eliminate a lot of these */
- xchat_hook_print(ph, "Join", XCHAT_PRI_NORM, join_cb, 0);
- xchat_hook_print(ph, "Part", XCHAT_PRI_NORM, part_cb, 0);
- xchat_hook_print(ph, "Part with reason", XCHAT_PRI_NORM, partr_cb, 0);
- xchat_hook_print(ph, "Channel Action", XCHAT_PRI_NORM, emote_cb, 0);
- xchat_hook_print(ph, "Channel Action Highlight", XCHAT_PRI_NORM, emote_cb, 0);
- xchat_hook_print(ph, "Channel Message", XCHAT_PRI_NORM, message_cb, 0);
- xchat_hook_print(ph, "Channel Message Hilight", XCHAT_PRI_NORM, message_cb, 0);
- xchat_hook_print(ph, "Channel Msg Hilight", XCHAT_PRI_NORM, message_cb, 0);
- xchat_hook_print(ph, "Kick", XCHAT_PRI_NORM, kick_cb, 0);
- xchat_hook_print(ph, "Quit", XCHAT_PRI_NORM, quit_cb, 0);
- xchat_hook_print(ph, "Notice", XCHAT_PRI_NORM, notice_cb, 0);
- xchat_hook_print(ph, "Private Message", XCHAT_PRI_NORM, private_cb, 0);
- xchat_hook_print(ph, "Private Message to Dialog", XCHAT_PRI_NORM, private_cb, 0);
- xchat_hook_print(ph, "Change Nick", XCHAT_PRI_NORM, nick_cb, 0);
- xchat_hook_print(ph, "You Kicked", XCHAT_PRI_NORM, kicked_cb, 0);
- xchat_hook_print(ph, "You Join", XCHAT_PRI_NORM, ijoin_cb, 0);
- xchat_hook_print(ph, "You Message", XCHAT_PRI_LOWEST, imessage_cb, 0);
- xchat_hook_print(ph, "You Action", XCHAT_PRI_LOWEST, iaction_cb, 0);
- xchat_hook_print(ph, "Your Message", XCHAT_PRI_LOWEST, imessage_cb, 0);
- xchat_hook_print(ph, "Your Action", XCHAT_PRI_LOWEST, iaction_cb, 0);
- xchat_hook_print(ph, "Invited", XCHAT_PRI_NORM, invited_cb, 0);
- xchat_hook_command(ph, "exec", XCHAT_PRI_HIGH, dangerous_cb, "dangerous", 0);
- xchat_hook_command(ph, "NB_ExtCmd", XCHAT_PRI_LOWEST, nb_extcmd_cb, NULL, 0);
- xchat_hook_command(ph, "NB_Config", XCHAT_PRI_NORM, nb_config_cb, NULL, 0);
- xchat_hook_command(ph, "NB_mPing", XCHAT_PRI_LOWEST, nb_mrequest_cb, NULL, (void*)1);
- xchat_hook_command(ph, "NB_mAskPtr", XCHAT_PRI_LOWEST, nb_mrequest_cb, NULL, (void*)2);
- xchat_hook_command(ph, "NB_mAskInf", XCHAT_PRI_LOWEST, nb_mrequest_cb, NULL, (void*)3);
- xchat_hook_command(ph, "NB_mPong", XCHAT_PRI_LOWEST, nb_manswer_cb, NULL, (void*)1);
- xchat_hook_command(ph, "NB_mSayPtr", XCHAT_PRI_LOWEST, nb_manswer_cb, NULL, (void*)2);
- xchat_hook_command(ph, "NB_mSayInf", XCHAT_PRI_LOWEST, nb_manswer_cb, NULL, (void*)3);
- xchat_hook_command(ph, "NB_mLoaded", XCHAT_PRI_LOWEST, nb_manswer_cb, NULL, (void*)4);
- xchat_hook_command(ph, "NB_mUnload", XCHAT_PRI_LOWEST, nb_manswer_cb, NULL, (void*)5);
- xchat_commandf(ph, "NB_mLoaded %s", PLUGIN_IPC_NAME);
- FILE *Script;
- char Buffer[512];
- sprintf(Buffer, "%s/NovaBot/autoexec.txt", xchat_get_info(ph, "xchatdirfs"));
- int i,j,k;
- Script = fopen(Buffer,"r");
- if(Script != NULL) {
- xchat_print(ph, "Auto-exec script was found");
- for(k=0;!k;i=0) {
- i=0;
- while(1) {
- j = fgetc(Script);
- Buffer[i++]=j;
- if(j == '\n' || j==EOF) {
- Buffer[i-1] = 0;
- if(j==EOF) k=1;
- break;
- }
- }
- xchat_commandf(ph, "%s", Buffer);
- }
- fclose(Script);
- }
- xchat_printf(ph, "Hello from NovaBot %s\n", PVERSION);
- return 1; /* return 1 for success */
- }
Add Comment
Please, Sign In to add comment