NovaYoshi

bot.nut

Jul 22nd, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 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 WithoutPrefix = P.Text.slice(Prefix.len());
  14. local Split = api.TextParamSplit(WithoutPrefix);
  15.  
  16. // Don't send an argument if there is none
  17. if(Split[0][0] != WithoutPrefix)
  18. api.Event("bot command", {"Nick":P.Nick, "Cmd":Split[0][0], "Arg":Split[1][1], "Say":"contextsay", "SayArg":Context+" "}, Context);
  19. else
  20. api.Event("bot command", {"Nick":P.Nick, "Cmd":Split[0][0], "Arg":"", "Say":"contextsay", "SayArg":Context+" "}, Context);
  21. }
  22. return EventReturn.NORMAL;
  23. }
  24.  
  25. function BadCmd(Type, Params, Context) {
  26. api.Command("say", "Unrecognized command", Context);
  27. return EventReturn.DELETE;
  28. }
  29.  
  30. // register hooks
  31. foreach(T in ["user message", "user message hilight"])
  32. api.AddEventHook(T, CommandWatch, Priority.NORMAL, 0, 0, 0);
  33. api.AddEventHook("bot command", BadCmd, Priority.LOWEST, 0, 0, 0);
  34.  
  35. function SayCmd(T, P, C) {
  36. P = api.TextParamSplit(P);
  37. local Context = P[0][0];
  38. local Text = P[1][1];
  39. api.Command("say", Text, Context);
  40. return EventReturn.HANDLED;
  41. }
  42. api.AddCommandHook("contextsay", SayCmd, Priority.NORMAL, null, null);
Add Comment
Please, Sign In to add comment