Advertisement
NovaYoshi

bot.nut

Apr 7th, 2017
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. AddonInfo <- {
  2. "Name":"bot.nut"
  3. "Summary":"Bot framework"
  4. "Version":"0.01"
  5. "Author":"NovaSquirrel"
  6. };
  7.  
  8. const Prefix = "sb.";
  9.  
  10. function CommandWatch(Type, P, Context) {
  11. P = api.DecodeJSON(P);
  12. if(startswith(P.Text, Prefix)) {
  13. local ReplyWith = "say";
  14. local WithoutPrefix = P.Text.slice(Prefix.len());
  15. local Split = api.TextParamSplit(WithoutPrefix);
  16.  
  17. // Don't send an argument if there is none
  18. if(Split[0][0] != WithoutPrefix)
  19. api.Event("bot command", {"Nick":P.Nick, "Cmd":Split[0][0], "Arg":Split[1][1], "Say":"contextsay", "SayArg":Context+" "}, Context);
  20. else
  21. api.Event("bot command", {"Nick":P.Nick, "Cmd":Split[0][0], "Arg":"", "Say":"contextsay", "SayArg":Context+" "}, Context);
  22. }
  23. return EventReturn.NORMAL;
  24. }
  25.  
  26. function BadCmd(Type, Params, Context) {
  27. // api.Command("say", "Unrecognized command", Context);
  28. return EventReturn.DELETE;
  29. }
  30.  
  31. // register hooks
  32. foreach(T in ["user message", "user message hilight"])
  33. api.AddEventHook(T, CommandWatch, Priority.NORMAL, 0, 0, 0);
  34. api.AddEventHook("bot command", BadCmd, Priority.LOWEST, 0, 0, 0);
  35.  
  36. function SayCmd(T, P, C) {
  37. P = api.TextParamSplit(P);
  38. local Context = P[0][0];
  39. local Text = P[1][1];
  40. api.Command("say", Text, Context);
  41. return EventReturn.HANDLED;
  42. }
  43. api.AddCommandHook("contextsay", SayCmd, Priority.NORMAL, null, null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement