Advertisement
NovaYoshi

crappy bridge

Jan 28th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. AddonInfo <- {
  2. "Name":"Bridge"
  3. "Summary":"Connects channels together"
  4. "Version":"0.01"
  5. "Author":"NovaSquirrel"
  6. };
  7.  
  8. function IsActionMy(Text) {
  9. if(Text.len() < 2) return " ";
  10. if(Text.slice(0,2)=="'s") return "";
  11. return " ";
  12. }
  13.  
  14. function EventString(T, P, C) {
  15. const IsAction = "* ";
  16. const IsNotice = "- ";
  17.  
  18. switch(T) { // important: don't capitalize event names, they won't match here
  19. case "user change nick":
  20. return IsNotice+P.Nick+ " is now known as "+P.NewNick;
  21.  
  22. case "user message":
  23. return "<"+P.Nick+"> "+P.Text;
  24. case "user action":
  25. return IsAction+P.Nick+IsActionMy(P.Text)+P.Text;
  26.  
  27. case "channel ban+":
  28. if("Timeout" in P)
  29. return IsNotice+P.Nick+" has banned "+P.Target+" for "+P.Timeout+" minutes";
  30. else
  31. return IsNotice+P.Nick+" has banned "+P.Target;
  32. case "channel ban-":
  33. return IsNotice+P.Nick+" has unbanned "+P.Target;
  34.  
  35. case "channel join":
  36. if("Host" in P)
  37. return IsNotice+P.Nick+" ("+P.Host+") has joined "+api.TabGetInfo(C, "Channel");
  38. else
  39. return IsNotice+P.Nick+" has joined "+api.TabGetInfo(C, "Channel");
  40.  
  41. case "channel kick":
  42. if("Text" in P)
  43. return IsNotice+P.Nick+" has kicked "+P.Target+" ("+P.Text+")";
  44. else
  45. return IsNotice+P.Nick+" has kicked "+P.Target;
  46.  
  47. case "channel part":
  48. if("Text" in P)
  49. return IsNotice+P.Nick+" has left ("+P.Text+")";
  50. else
  51. return IsNotice+P.Nick+" has left";
  52.  
  53. case "channel status+":
  54. if("Nick" in P)
  55. return IsNotice+P.Nick+" gives \""+P.Status+"\" status to "+P.Target;
  56. else
  57. return IsNotice+"Someone gives \""+P.Status+"\" status to "+P.Target;
  58. case "channel status-":
  59. if("Nick" in P)
  60. return IsNotice+P.Nick+" removes \""+P.Status+"\" status from "+P.Target;
  61. else
  62. return IsNotice+"Someone removes \""+P.Status+"\" status from "+P.Target;
  63.  
  64. case "channel mode+":
  65. return IsNotice+P.Nick+" sets modes "+P.Mode;
  66. case "channel mode-":
  67. return IsNotice+P.Nick+" removes modes "+P.Mode;
  68.  
  69. default:
  70. return EventReturn.NORMAL;
  71. }
  72. }
  73.  
  74. local Links = [];
  75.  
  76. function TrimChannelId(Context) {
  77. local Split = split(Context, "/");
  78. local Channel = split(Split[1], ":");
  79. return Split[0]+"/"+Channel[0];
  80. }
  81.  
  82. function ShowEvent(Type, Params, Context) {
  83. Context = TrimChannelId(Context);
  84. if(Links.find(Context) != null) {
  85. Params = api.DecodeJSON(Params);
  86. local Message = EventString(Type, Params, Context);
  87. if(typeof(Message) != "string")
  88. return EventReturn.NORMAL;
  89. print(Message);
  90. foreach(Channel in Links)
  91. if(Channel != Context)
  92. api.Command("say", Message, Channel);
  93. }
  94. return EventReturn.NORMAL;
  95. }
  96.  
  97. function AddBridgeCmd(Type, Params, Context) {
  98. Context = TrimChannelId(Context);
  99. if(Links.find(Context) == null) {
  100. print("Added "+Context+" to linked channels");
  101. Links.append(Context);
  102. } else {
  103. print("Already linked");
  104. }
  105. return EventReturn.HANDLED;
  106. }
  107.  
  108. foreach(Type in ["you *", "user *", "channel *"])
  109. api.AddEventHook(Type, ShowEvent, Priority.LOW, 0, 0, 0);
  110.  
  111. api.AddCommandHook("addbridge", AddBridgeCmd, Priority.NORMAL, null, null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement