home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / yagirc-0.51.tar.gz / yagirc-0.51.tar / yagirc-0.51 / irc.pl < prev    next >
Text File  |  1998-05-06  |  16KB  |  289 lines

  1. #
  2. # The yagIRC script prototype + short manual
  3. #
  4. #  Copyright (C) 1998 Jere Sanisalo <jeress@iname.com> and Timo Sirainen
  5.  
  6. # CUSTOM SCRIPTS (use module_name;)
  7. # CUSTOM SCRIPTS
  8.  
  9.  
  10. # Commands (alphabetic order):
  11. #   *** commands marked with !! aren't implemented yet ***
  12. #  ircBind(eventType,eventSpecifier,bindTime,functionName);
  13. #         Binds an event to a SUB-function. The function depends on the
  14. #         event. The bind returns 'yes' is it was successfull (or 'no' if
  15. #         not). The bindTime is the amount of time (in milliseconds) the
  16. #         binding lasts (0 = forever).
  17. #         The callback functions should return 'yes' if they want the yagIRC
  18. #         to process the event also. Note that if many functions have been
  19. #         assigned to an event, then everyone must return 'yes' for yagIRC to
  20. #         process the event.
  21. #         List of all events:
  22. #          CONNECTED - Called when the server connection has been established
  23. #                      (and after the user has been logged on).
  24. #                      The function is in the type of:
  25. #                        functionName(serverId,serverName);
  26. #          CTCP     - Called when someone sends a CTCP-request (eg. a
  27. #                     'VERSION').
  28. #                     The function is in the type of:
  29. #                       functionName(nickName,userHost,destNick,ctcpData);
  30. #          DCCMSG   - Called when a dcc message has been received. The
  31. #                     eventSpecifier notifies the user nick on which to bind
  32. #                     the event (the connection may not necessary be up)..
  33. #                     The function is in the type of:
  34. #                       functionName(nickName,message);
  35. #          DISCONNECTED - Called when the server connection has been
  36. #                         disconnected.
  37. #                         The function is in the type of:
  38. #                           functionName(serverId,serverName);
  39. #          INVITE   - Called when someone invites you to a channel.
  40. #                     The function is in the type of:
  41. #                       functionName(nickName,channelName);
  42. #          IRCJOIN  - Called when someone joins the irc (kind of a notify).
  43. #                     The irc-nick is given in eventSpecifier.
  44. #                     The function is in the type of:
  45. #                       functionName(nickName,userHost);
  46. #          IRCPART  - Called when someone leaves the irc (kind of a notify).
  47. #                     The irc-nick is given in eventSpecifier.
  48. #                     The function is in the type of:
  49. #                       functionName(nickName,userHost);
  50. #          JOIN     - Called when someone joins a channel. The eventSpecifier
  51. #                     notifies the channel on which to bind the event (""
  52. #                     means all channels).
  53. #                     The function is in the type of:
  54. #                       functionName(nickName,userHost,channelName);
  55. #                     NOTE! Here only the channelName has the server info.
  56. #          KICK     - Called when someone is kicked out of a channel you're
  57. #                     on.
  58. #                     The function is in the type of:
  59. #                       functionName(kickerNick,ChannelName,kickedNick,kickedUserHost,kickReason);
  60. #                     NOTE! Here only the channelName has the server info.
  61. #          MODE     - Called when the channel mode has been changed. The
  62. #                     eventSpecifier notifies the channel on which to bind
  63. #                     the event ("" means all channels).
  64. #                     The function is in the type of:
  65. #                       functionName(nickName,userHost,channelName,modeString);
  66. #                     NOTE! The modeString contains the whole mode-string,
  67. #                           ie. '+oo-o john ira turbo'.
  68. #          PART     - Called when someone leaves a channel you're on. The
  69. #                     eventSpecifier notifies the channel on which to bind
  70. #                     the event ("" means all channels).
  71. #                     The function is in the type of:
  72. #                       functionName(nickName,userHost,channelName,leaveMsg);
  73. #          PRGQUIT  - Called upon the program quit (when yagIrc needs to
  74. #                     end the script for some reason).
  75. #                     The function is in the type of:
  76. #                       functionName();
  77. #          PRIVMSG  - Called when a private message is written to you.
  78. #                     The function is in the type of:
  79. #                       functionName(nickName,userHost,message);
  80. #          PUBMSG   - Called when a message is written in a channel. The
  81. #                     eventSpecifier notifies the channel on which to bind
  82. #                     the event ("" means all channels).
  83. #                     The function is in the type of:
  84. #                       functionName(nickName,channelName,message);
  85. #                     NOTE! Here only the channelName has the server info.
  86. #          SERVERMSG - Called when the server sends up some text (ie. motd or
  87. #                      anything, just as long as it's sent by the server).
  88. #                      The function is in the type of:
  89. #                        functionName(serverId,message);
  90. #          TOPIC    - Called when the topic changes on a channel you're on.
  91. #                     The function is in the type of:
  92. #                       functionName(nickName,userHost,channelName,topic);
  93. #          QUIT     - Called when someone who was on one or more of the 
  94. #                     channels you're on quits.
  95. #                     The function is in the type of:
  96. #                       functionName(nickName,userHost,channelNames,leaveMsg);
  97. #                     NOTE! The channelNames is a list of all the channels
  98. #                           you know the user was before quitting, separated
  99. #                           by a space.
  100. #                     NOTE! This is called before IRCPART.
  101. #         RETURN VALUES(S): The event binding id (given by yagIrc), or "" if
  102. #                           there was an error.
  103. #         NOTE! Where 'nickName' (or any nick in general) is the first
  104. #               parameter, then the nick has the server info (and all other
  105. #               nicks/channels do not have it).
  106. #         NOTE! One binding type can only be done once (so no two exactly
  107. #               the same bindings can be done, although even a small
  108. #               difference is enough for the binding to happen)!
  109. #  ircBindCmd(commandName,commandSpecifier,functionName);
  110. #         Binds a local command. For example if you bind "test", then typing
  111. #         '/TEST' in yagIRC would call this function. Everything written
  112. #         after the command on irc will be passed as a single argument to the
  113. #         function.
  114. #         The commandSpecifier depends on commandName. Here's the list of
  115. #         special commandNames:
  116. #          '/JOIN'  -
  117. #          '/PART'  - The eventSpecifier specifies the channel to bind.
  118. #          '/MSG'   - The eventSpecifier specifies the user (dest) to bind.
  119. #         RETURN VALUES(S): The event binding id (given by yagIrc), or "" if
  120. #                           there was an error.
  121. #         NOTE! Each command (type) may be bound only once!
  122. #         NOTE! When eventSpecifier would otherwise be used, giving a "" means
  123. #               to bind the command in whole.
  124. #         NOTE! Beware of looped commands (bind a command and inside that
  125. #               command call the same command again (infinite recursive
  126. #               loop)).
  127. #  ircCmd(channelName,command);
  128. #         Issues a command (like "/names #test").
  129. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  130. #         NOTE! Beware of looped commands (bind a command and inside that
  131. #               command call the same command again (infinite recursive
  132. #               loop)).
  133. #  ircCTCPSend(dest,ctcpData);
  134. #         Sends a CTCP request to a user (dest can be a channel or a nick).
  135. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  136. #  ircCTCPReply(nickName,ctcpData);
  137. #         Sends a CTCP reply to a user.
  138. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  139. #!!ircGetChannelList(serverId);
  140. #         Gets the list of joined channels in a server.
  141. #         RETURN VALUES(S): Channel list (list of strings).
  142. #!!ircGetLocalUserInfo(serverId);
  143. #         Gets the local user (the user the yagIrc is connected) info on a
  144. #         server.
  145. #         RETURN VALUES(S): On failure a 'undef' is returned.
  146. #                           On success, the return is a list, which has the
  147. #                           the folloring items (in the same order):
  148. #                             userNick,userHost,userName
  149. #!!ircGetNameList(channelName);
  150. #         Gets the users of a channel. The list returned will contain a
  151. #         string per user (the user will have any irc-additions in from of
  152. #         the nick, ie. a '@' if the user is an operator and a '+' is the
  153. #         user has voices etc.).
  154. #         RETURN VALUES(S): User list (list of strings).
  155. #         NOTE! The channelName-parameter should have the multiserver-ids
  156. #               embedded on it (if not, then every server connected will
  157. #               be checked and added to the list). Remember, every nick ends
  158. #               with ' serverId' (where serverId is the id of the server).
  159. #!!ircGetServerIdList();
  160. #         Gets a list of the connected server ids and the servers addresses.
  161. #         The list has ID-ADDRESS-pairs, so the return value is ready to be
  162. #         hashed.
  163. #         RETURN VALUES(S): Server Id+address list (list of strings).
  164. #!!ircGetTopic(channelName);
  165. #         Gets the channel topic.
  166. #         RETURN VALUES(S): The topic is returned, or 'undef' if there was an
  167. #                           error.
  168. #         NOTE! The channelName must have the multiserver-id, or else this
  169. #               command fails.
  170. #  ircMenuAdd(menuType,menuText,menuDest,functionName);
  171. #         Adds a menu item to any of the menus (main/channel/nick). The
  172. #         menuText is the text displayed in the menu. The menuDest is the
  173. #         destination for the menu item (if the menuType does not have a
  174. #         destination, then set this to "", see the list at the end of the
  175. #         the command-description). The functionName is the callback function
  176. #         (defined as: functionName(menuType,menuDest,menuItemId);).
  177. #         The menu types are as follow:
  178. #           GLOBAL - Global menus for every window (no menuDest!).
  179. #           CHANNEL - Channel specific pop-up menus (menuDest is the channel
  180. #                     name).
  181. #           NICK - Nick name specific pop-up menus (menuDest is the nick name
  182. #                  to bind).
  183. #         RETURN VALUES(S): The menuItemId (for later menu access). On error
  184. #                           the returned value is "".
  185. #         NOTE! One type of menu binding can only be done once!
  186. #  ircMenuRemove(menuItemId);
  187. #         Removes the menu item by menuItemId.
  188. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  189. #!!ircMenuRemoveMatch(menuType,menuText,menuDest,functionName);
  190. #         Removes the menu item by the exact menu definition.
  191. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  192. #  ircMsg(dest,message);
  193. #         Sends a /msg, dest can be #channel name, nick name or =dcc nick
  194. #         name.
  195. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  196. #  ircNotice(dest,message);
  197. #         Sends a /notice to a user/channel/dcc.
  198. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  199. #  ircServerCmd(serverId,command);
  200. #         Sends raw, unformatted data to the server.
  201. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  202. #  ircText(channelName,text);
  203. #         Writes text to screen (in specific channel).
  204. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  205. #         NOTE! If channelName is "", then the text will go to the current
  206. #               active window.
  207. #!!ircTimerCallback(functionName,timeMS,...);
  208. #         Hooks up a callback timer. After the specified amount of time
  209. #         (given in milliseconds) the functionName is called with the
  210. #         specified parameters (timeMS + everything after it).
  211. #         The callback function must return 'yes' or 'no', depending on
  212. #         whether the callback should stop here. So returning 'yes' keeps the
  213. #         timer calling itself (with the same parameters) and returning 'no'
  214. #         removes this timer from the timer-stack.
  215. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  216. #         NOTE! If you hook up any more timer callbacks in a timer callback
  217. #               function, just be sure the hooks end up somewhere (so you
  218. #               don't accidentally hook up over a million timer callbacks,
  219. #               which is, without saying, slow ;).
  220. #  ircUnBind(bindId)
  221. #         Unbinds a previously bound event by the bindId returned by ircBind.
  222. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  223. #!!ircUnBindMatch(eventType,eventSpecifier,functionName);
  224. #         Unbinds a previously bound event (the eventType, eventSpecifier
  225. #         and functionName must be a perfect match). The reason for this to
  226. #         work is that you can do one binding only once with exactly the same
  227. #         parameters (type/spec/func), so there can be only one binding of
  228. #         any combination.
  229. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  230. #  ircUnBindCmd(bindId);
  231. #         Unbinds a previously bound command by the bindId returned by
  232. #         ircBindCmd.
  233. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  234. #!!ircUnBindCmdMatch(commandName,commandSpecifier,functionName);
  235. #         Unbinds a previously bound command (according to name/specifier+
  236. #         function).
  237. #         RETURN VALUES(S): 'yes' or 'no' depending on success.
  238. #
  239. # '!!' means the function is yet-to-be-implemented.
  240.  
  241. #  HOW YAGIRC SCRIPTS MANAGES MULTIPLE SERVERS
  242. #
  243. #YagIrc can be connected to multiple servers at the same time. This, in the
  244. #view of scripts, presents few problems. Here's how they are solved in yagIRC.
  245. #Each server is given a serverId by yagIRC. This serverId presents the server
  246. #from there on. You send and receive all information to yagIRC using these
  247. #serverIds. When the serverId is not one of the parameters, it is included
  248. #after the nick name separated by space (like "nick serverId") On most cases,
  249. #if the server name is not given, then it applies to every server currently
  250. #connected.
  251.  
  252.  
  253. #  NOTES ON BOUND COMMANDS
  254. #
  255. #The script can bind any command to it's need, ie. the '/MSG' or '/QUIT'
  256. #commands. This means that the original command is out of reach. There may
  257. #be some need to still access the old commands, so by putting '//MSG' or
  258. #'//QUIT' ignores effectively any bindings and ALWAYS uses the unbound
  259. #commands (these work in the yagIRC itself also).
  260.  
  261. #  NOTES ON USERHOST
  262. #
  263. #The userHost returned by some events/commands is in the form of
  264. #'who@where', not the common 'nick!who@where'. The nick is always given in a
  265. #separate statement (to save a line or two of perl code required to split it).
  266.  
  267. # bind joins to channel #mikkeli
  268. ircBind("join", "#mikkeli", join_msg);
  269.  
  270.  
  271. # bind server connections
  272. ircBind("connected", "", server_connected);
  273.  
  274.  
  275. # connect to localhost at startup :)
  276. ircCmd("", "/server localhost");
  277.  
  278.  
  279. sub join_msg {
  280.     ircNotice($_[0], "Hello ".$_[0].", this is just a stupid message sent to everyone who joins this channel.");
  281. }
  282.  
  283.  
  284. sub server_connected {
  285.     ircText("", "%RHi there! So you've finally got this far and connected to IRC server!\n");
  286.     ircCmd("", "/join #mikkeli");
  287. }
  288.