AddonInfo <- { "Name":"bot.nut" "Summary":"Bot framework" "Version":"0.01" "Author":"NovaSquirrel" }; const Prefix = "sb."; function CommandWatch(Type, P, Context) { P = api.DecodeJSON(P); if(startswith(P.Text, Prefix)) { local ReplyWith = "say"; local WithoutPrefix = P.Text.slice(Prefix.len()); local Split = api.TextParamSplit(WithoutPrefix); // Don't send an argument if there is none if(Split[0][0] != WithoutPrefix) api.Event("bot command", {"Nick":P.Nick, "Cmd":Split[0][0], "Arg":Split[1][1], "Say":"contextsay", "SayArg":Context+" "}, Context); else api.Event("bot command", {"Nick":P.Nick, "Cmd":Split[0][0], "Arg":"", "Say":"contextsay", "SayArg":Context+" "}, Context); } return EventReturn.NORMAL; } function BadCmd(Type, Params, Context) { // api.Command("say", "Unrecognized command", Context); return EventReturn.DELETE; } // register hooks foreach(T in ["user message", "user message hilight"]) api.AddEventHook(T, CommandWatch, Priority.NORMAL, 0, 0, 0); api.AddEventHook("bot command", BadCmd, Priority.LOWEST, 0, 0, 0); function SayCmd(T, P, C) { P = api.TextParamSplit(P); local Context = P[0][0]; local Text = P[1][1]; api.Command("say", Text, Context); return EventReturn.HANDLED; } api.AddCommandHook("contextsay", SayCmd, Priority.NORMAL, null, null);