├── .gitignore ├── LICENSE ├── README.md ├── build.xml ├── contrib ├── jira │ ├── .classpath │ ├── .project │ ├── LICENSE │ ├── README.txt │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── fm │ │ │ │ └── last │ │ │ │ └── jira │ │ │ │ └── plugins │ │ │ │ └── IrccatListener.java │ │ └── resources │ │ │ └── atlassian-plugin.xml │ │ └── test │ │ ├── java │ │ ├── fm │ │ │ └── last │ │ │ │ └── jira │ │ │ │ └── plugins │ │ │ │ └── UnitTestMyPlugin.java │ │ └── it │ │ │ └── IntegrationTestMyPlugin.java │ │ ├── resources │ │ └── TEST_RESOURCES_README.txt │ │ └── xml │ │ └── IntegrationTestData.xml └── trac │ ├── README │ └── irccat.py ├── examples ├── command_runner.py ├── example.php ├── example.sh ├── init.d │ └── irccat ├── irccat.xml └── twitter-feed.php ├── irccat.sh ├── libs ├── commons-collections-3.2.jar ├── commons-configuration-1.5.jar ├── commons-lang-2.3.jar ├── commons-logging-1.1.1.jar ├── pircbot.jar ├── xercesImpl.jar └── xml-apis.jar └── src └── fm └── last └── irccat ├── CatHandler.java ├── IRCCat.java └── Scripter.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Ant... 2 | build 3 | dist 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Archived - See irccloud/irccat 2 | 3 | I'm not running this java version any more, please see this [irccat clone in go](https://github.com/irccloud/irccat). 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | IRCcat 13 | ====== 14 | 15 | As in `cat` to IRC. 16 | 17 | IRCcat does 2 things: 18 | 19 | 1) Listens on a specific ip:port and writes incoming data to an IRC channel. 20 | This is useful for sending various announcements and log messages to irc 21 | from shell scripts, Nagios and other services. 22 | 23 | 2) Hands off commands issued on irc to a handler program (eg: shell script) 24 | and responds to irc with the output of the handler script. This only 25 | happens for commands addressed to irccat: or prefixed with ?. 26 | (easily extend irccat functionality with your own scripts) 27 | 28 | 29 | Installation 30 | ------------ 31 | Edit the irccat.xml so it knows which irc server, channel etc.. 32 | Check you have sun jvm >=1.5 (java -version) 33 | 34 | This will build and package irccat as a jar: 35 | 36 | $ ant dist 37 | 38 | Then, using the appropriate config file: 39 | 40 | $ ant -Dconfigfile=./examples/irccat.xml run 41 | 42 | Also, you'll probably want to install netcat. 43 | 44 | 45 | Sending text to IRC 46 | ------------------- 47 | By default IRCCat listens on 127.0.0.1:12345, and sends data to the 48 | default (first) channels. In a networked server environment you will p 49 | robably want to make it listen on the private LAN interface. 50 | 51 | Examples: 52 | 53 | $ echo "Hello World" | netcat -q0 localhost 12345 54 | $ tail -f /var/log/www/error.log | netcat localhost 12345 55 | 56 | In a server environment, consider adding a hostname to your internal DNS or 57 | using a virtual IP for irccat to listen on, in case you want to move irccat 58 | to another box later. 59 | 60 | 61 | Sending to specific channels 62 | ---------------------------- 63 | To send to a specific channel rather than the default, put the channel name 64 | as the first word in the data (the channel name will be stripped): 65 | 66 | $ echo "#mychannel hello world" | netcat -q0 machinename 12345 67 | 68 | This sends "hello world" to #mychannel 69 | 70 | First word defines the recipients, you can use comma separated list. 71 | # prefix indicates channel, @ indicates a nick. 72 | 73 | Examples: 74 | 75 | - "#chan blah blah" 76 | just sends to #chan 77 | 78 | - "@RJ psst, this is a pm" 79 | just sends via PM to user RJ 80 | 81 | - "#channel1,#channel2,@RJ,@Russ blah blah this is the message" 82 | this sends to 2 channels, and 2 users (RJ, Russ) 83 | 84 | - "#* Attention, something important" 85 | this sends to all channels the bot is in 86 | 87 | - "#chan %REDroses are red%NORMAL, grass is #GREENgreen#NORMAL" 88 | you can use colors too, see IRCCat.java for the full list; 89 | Either "#" or "%" will work. 90 | 91 | 92 | 93 | Changing topics in channels 94 | --------------------------- 95 | To change the topic in a channel (rather than sending a message), use 96 | the prefix %TOPIC. 97 | 98 | $ echo "%TOPIC #mychannel hello world" | netcat -q0 machinename 12345 99 | 100 | This changes the topic of #mychannel to "hello world" (assuming the bot 101 | has permission to set the topic) 102 | 103 | Second word defines the recipient channels. You can use a comma separated 104 | list. Nick recipients will be accepted, but silently ignored. 105 | 106 | Examples: 107 | 108 | - "%TOPIC #chan new topic" 109 | just changes the topic of #chan 110 | 111 | - "%TOPIC #channel1,#channel2 this channel is great" 112 | this changes the topics of two channels 113 | 114 | - "%TOPIC #* Important Topic" 115 | this changes the topics in all channels the bot is in 116 | 117 | 118 | Built-in commands 119 | ----------------- 120 | There are a handful of built-in commands for instructing the bot at runtime. 121 | 122 | Built-in commands are prefixed with a ! 123 | 124 | !join #chan pass - joins another channel. pass is optional 125 | !part #chan - parts chan 126 | !channels - lists channels the bot is in 127 | !spam blah blah.. - repeats your message in all joined channels 128 | !exit - System.exit() 129 | 130 | Trust 131 | ----- 132 | 133 | Any command (?.. !..) uttered in a channel with irccat in is executed and 134 | implicitly trusted. 135 | 136 | Any command PMed to irccat is ignored unless the user 137 | is joined to the default (first) channel in the config file. 138 | 139 | 140 | SVN commit notifications 141 | ------------------------ 142 | svn hooks let you announce commits etc. 143 | For example, try this in your SVN repo/hooks/post-commit file: 144 | 145 | REPOS="$1" 146 | REV="$2" 147 | LOG=`/usr/bin/svnlook log -r $REV $REPOS` 148 | AUTHOR=`/usr/bin/svnlook author -r $REV $REPOS` 149 | echo "SVN commit by $AUTHOR (r$REV) '$LOG' http://web-svn-interface.example.com/?rev=$REV" | netcat -q0 machinename 12345 150 | 151 | 152 | Nagios alerts to irc 153 | -------------------- 154 | Buried in our nagios config is this, from misccommands.cfg: 155 | 156 | define command { 157 | command_name host-notify-by-irc 158 | command_line /bin/echo "#sys Nagios: Host '$HOSTALIAS$' is $HOSTSTATE$ - Info: $OUTPUT$" | /bin/netcat -q 1 irccathost 12345 159 | } 160 | 161 | define command { 162 | command_name service-notify-by-irc 163 | command_line /bin/echo "#sys Nagios: Service $SERVICEDESC$ on '$HOSTALIAS$' is $SERVICESTATE$ - Info: $OUTPUT$" | /bin/netcat -q 1 irccathost 12345 164 | } 165 | 166 | And in contacts.cfg: 167 | 168 | define contact{ 169 | contact_name irccat 170 | alias irccat 171 | service_notification_period 24x7 172 | host_notification_period 24x7 173 | service_notification_options w,c,r 174 | host_notification_options d,r 175 | service_notification_commands service-notify-by-irc 176 | host_notification_commands host-notify-by-irc 177 | email blah@blah 178 | } 179 | 180 | Feedback 181 | -------- 182 | Email: rj@metabrew.com 183 | Web: http://www.last.fm/user/RJ (work, and the reason irccat exists) 184 | Web: http://www.metabrew.com/ (blog) 185 | Irc: irc://irc.audioscrobbler.com/audioscrobbler 186 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /contrib/jira/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | -------------------------------------------------------------------------------- /contrib/jira/.project: -------------------------------------------------------------------------------- 1 | 2 | jira-plugin-irccat 3 | Parent POM for JIRA plugins. Specifies which version of Java to compile 4 | against, and Maven repositories for JIRA and its dependencies. 5 | 6 | 7 | 8 | org.eclipse.jdt.core.javabuilder 9 | 10 | 11 | 12 | org.eclipse.jdt.core.javanature 13 | 14 | -------------------------------------------------------------------------------- /contrib/jira/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, Last.fm Ltd. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | * Neither the name of the Last.fm Ltd. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11 | -------------------------------------------------------------------------------- /contrib/jira/README.txt: -------------------------------------------------------------------------------- 1 | This is a JIRA listener plugin which sends notifications to irccat on JIRA ticket changes. 2 | 3 | For information on how to build this: 4 | 5 | http://confluence.atlassian.com/display/DEVNET/How+to+Build+an+Atlassian+Plugin 6 | 7 | To install and configure: 8 | 9 | - Copy the .jar file to the WEB-INF/lib directory in your JIRA install 10 | - Restart JIRA 11 | - The plugin should now show up under Administration->Plugins 12 | - Under Administration->Listeners, add a new listener with the class fm.last.jira.plugins.IrccatListener 13 | - Edit the config for that listener: 14 | - irccat.channel is the channel that you want the notifications sent to 15 | - irccat.host/port is the host/port where irccat is running 16 | - irccat.projectkeyregex is a regular expression matching the project key you want this listener to affect 17 | - You can add as many listeners as you require (one per channel) 18 | 19 | 20 | Russ Garrett 21 | russ@last.fm 22 | -------------------------------------------------------------------------------- /contrib/jira/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 4.0.0 6 | fm.last.jira.plugins 7 | jira-plugin-irccat 8 | 1.0 9 | 10 | 11 | LastFM 12 | http://www.last.fm 13 | 14 | 15 | JIRA Irccat Plugin 16 | JIRA listener plugin for IRCCat. 17 | atlassian-plugin 18 | 19 | 20 | com.atlassian.jira 21 | jira-api 22 | ${jira.version} 23 | provided 24 | 25 | 26 | 27 | 28 | 29 | 30 | com.atlassian.maven.plugins 31 | maven-jira-plugin 32 | 3.8 33 | true 34 | 35 | ${jira.version} 36 | ${jira.version} 37 | 38 | 39 | 40 | maven-compiler-plugin 41 | 42 | 1.6 43 | 1.6 44 | 45 | 46 | 47 | 48 | 49 | 50 | com.atlassian.jira.plugins 51 | jira-plugin-base 52 | 8 53 | 54 | 55 | 56 | 5.0 57 | 3.8 58 | fm.last.jira.plugins.jira-plugin-irccat 59 | 3.13 60 | 3.13 61 | 3.13 62 | 63 | 64 | 65 | 66 | 67 | Russ Garrett 68 | Last.fm Ltd. 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /contrib/jira/src/main/java/fm/last/jira/plugins/IrccatListener.java: -------------------------------------------------------------------------------- 1 | package fm.last.jira.plugins; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStreamWriter; 5 | import java.net.Socket; 6 | import java.util.Iterator; 7 | import java.util.Map; 8 | import java.util.regex.Pattern; 9 | import com.atlassian.jira.config.properties.APKeys; 10 | import com.atlassian.jira.config.properties.ApplicationProperties; 11 | 12 | import org.apache.commons.lang.StringUtils; 13 | 14 | import com.atlassian.jira.ComponentManager; 15 | import com.atlassian.jira.ManagerFactory; 16 | import com.atlassian.jira.event.issue.AbstractIssueEventListener; 17 | import com.atlassian.jira.event.issue.IssueEvent; 18 | import com.atlassian.jira.event.issue.IssueEventListener; 19 | import com.atlassian.jira.issue.Issue; 20 | 21 | public class IrccatListener extends AbstractIssueEventListener implements IssueEventListener { 22 | 23 | private String[] acceptedParams = {"irccat.projectkeyregex", "irccat.host", "irccat.port", "irccat.channel"}; 24 | private Pattern projectKeyPattern = null; 25 | private String host = null; 26 | private int port; 27 | private String channel = null; 28 | 29 | public void init(Map params) { 30 | if (params.get("irccat.projectkeyregex") != null) { 31 | this.projectKeyPattern = Pattern.compile((String)params.get("irccat.projectkeyregex"), Pattern.CASE_INSENSITIVE); 32 | } 33 | this.host = (String)params.get("irccat.host"); 34 | this.port = Integer.parseInt((String)params.get("irccat.port")); 35 | this.channel = (String)params.get("irccat.channel"); 36 | ApplicationProperties a = ManagerFactory.getApplicationProperties(); 37 | Iterator keys = a.getKeys().iterator(); 38 | while (keys.hasNext()) { 39 | String b = (String)keys.next(); 40 | System.err.println(b + " = " + a.getString(b)); 41 | } 42 | } 43 | 44 | protected boolean isEventMonitored(IssueEvent event) { 45 | return projectKeyPattern != null && projectKeyPattern.matcher(event.getIssue().getProjectObject().getKey()).matches(); 46 | } 47 | 48 | protected void sendNotification(String message) { 49 | Socket so = null; 50 | try { 51 | so = new Socket(host, port); 52 | OutputStreamWriter osw = new OutputStreamWriter(so.getOutputStream()); 53 | osw.write(channel + " " + message + "\n"); 54 | osw.close(); 55 | } catch (IOException e) { 56 | System.err.println("Unable to send irccat message to " + host + ":" + port + ", due to: " + e.getMessage()); 57 | } finally { 58 | try { 59 | if (so != null) 60 | so.close(); 61 | } catch (Exception e) {} 62 | } 63 | } 64 | 65 | public void workflowEvent(IssueEvent event) { 66 | if (!isEventMonitored(event)) 67 | return; 68 | Issue issue = event.getIssue(); 69 | StringBuilder sb = new StringBuilder(); 70 | sb.append("JIRA issue "); 71 | sb.append(ManagerFactory.getApplicationProperties().getString(APKeys.JIRA_BASEURL)); 72 | sb.append("/browse/"); 73 | sb.append(issue.getKey()); 74 | sb.append(" "); 75 | sb.append(ComponentManager.getInstance().getEventTypeManager().getEventType(event.getEventTypeId()).getName().toLowerCase()); 76 | sb.append(" by "); 77 | sb.append(event.getUser().getName()); 78 | if (event.getComment() != null && event.getComment().getBody().length() > 0) { 79 | sb.append(" \""); 80 | sb.append(StringUtils.abbreviate(event.getComment().getBody(), 100)); 81 | sb.append("\""); 82 | } 83 | 84 | sendNotification(sb.toString()); 85 | } 86 | 87 | public String[] getAcceptedParams() { 88 | return acceptedParams; 89 | } 90 | 91 | public String getDescription() { 92 | return "IRCCat listener"; 93 | } 94 | 95 | public boolean isInternal() { 96 | return false; 97 | } 98 | 99 | public boolean isUnique() { 100 | return false; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /contrib/jira/src/main/resources/atlassian-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ${project.description} 4 | ${project.version} 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /contrib/jira/src/test/java/fm/last/jira/plugins/UnitTestMyPlugin.java: -------------------------------------------------------------------------------- 1 | package fm.last.jira.plugins; 2 | 3 | import junit.framework.TestCase; 4 | 5 | public class UnitTestMyPlugin extends TestCase 6 | { 7 | public void testSomething() 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /contrib/jira/src/test/java/it/IntegrationTestMyPlugin.java: -------------------------------------------------------------------------------- 1 | package it; 2 | 3 | import junit.framework.TestCase; 4 | 5 | public class IntegrationTestMyPlugin extends TestCase 6 | { 7 | public void testSomething() 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /contrib/jira/src/test/resources/TEST_RESOURCES_README.txt: -------------------------------------------------------------------------------- 1 | Create any of the test resources you might need in this directory. 2 | 3 | Please remove this file before releasing your plugin. 4 | -------------------------------------------------------------------------------- /contrib/jira/src/test/xml/IntegrationTestData.xml: -------------------------------------------------------------------------------- 1 | Create all XML test resources here - these might be needed for populating JIRA instance at the integration-test phase with test data. 2 | 3 | Please remove this file before releasing your plugin. 4 | -------------------------------------------------------------------------------- /contrib/trac/README: -------------------------------------------------------------------------------- 1 | Seems like someone made a google code project for this plugin, with instructions: 2 | http://code.google.com/p/irccat-listener-trac-plugin/ 3 | -------------------------------------------------------------------------------- /contrib/trac/irccat.py: -------------------------------------------------------------------------------- 1 | import socket 2 | from trac.core import * 3 | from trac.ticket.api import ITicketChangeListener 4 | 5 | class IrcCatListener(Component): 6 | implements(ITicketChangeListener) 7 | 8 | def _sendText(self, ticketid, text): 9 | try: 10 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 11 | s.connect(("1.2.3.4",12345)) 12 | s.send("#last.fm Trac: ticket #%i (http://www.example.com/trac/ticket/%i) %s" % (ticketid, ticketid, text)) 13 | s.close() 14 | except: 15 | return 16 | 17 | def ticket_created(self, ticket): 18 | self._sendText(ticket.id, "\"%s\" created by %s." % (ticket.values['summary'][0:100], ticket.values['reporter'])) 19 | 20 | def ticket_changed(self, ticket, comment, author, old_values): 21 | self._sendText(ticket.id, "changed by %s, Comment: %s." % (author, comment[0:100])) 22 | -------------------------------------------------------------------------------- /examples/command_runner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os, sys, re, subprocess 3 | 4 | # If this script is set as your command handler, when any ?command is run in IRC it will 5 | # look in the path defined below for a script matching that command name and run it. 6 | # 7 | # e.g. ?uptime would look in "/usr/share/irccat/" (the default) for any script called 8 | # "uptime", with any extension. It would happily run both uptime.sh and uptime.py, or 9 | # a script in whatever language you like. Command names are limited to [0-9a-z]. 10 | 11 | path = '/usr/share/irccat/' 12 | 13 | args = sys.argv[1] 14 | bits = args.split(' ') 15 | command = bits[3].lower() 16 | 17 | found = False 18 | if re.match('^[a-z0-9]+$', command): 19 | for file in os.listdir(path): 20 | 21 | if re.match('^%s\.[a-z]+$' % command, file): 22 | found = True 23 | 24 | procArgs = [path + file] 25 | procArgs.extend(bits) 26 | proc = subprocess.Popen(procArgs, stdout=subprocess.PIPE) 27 | stdout = proc.stdout 28 | 29 | while True: 30 | # We do this to avoid buffering from the subprocess stdout 31 | print os.read(stdout.fileno(), 65536), 32 | sys.stdout.flush() 33 | 34 | if proc.poll() != None: 35 | break 36 | 37 | if found == False: 38 | print "Unknown command '%s'" % command 39 | -------------------------------------------------------------------------------- /examples/example.php: -------------------------------------------------------------------------------- 1 | 40 | -------------------------------------------------------------------------------- /examples/example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script handles ?commands to irccat 3 | 4 | # all our stuff is in a php script, take a look and replace the path etc: 5 | php -f ./scripts/example.php "$@" 6 | -------------------------------------------------------------------------------- /examples/init.d/irccat: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: irccat 4 | # Should-Start: $local_fs 5 | # Should-Stop: $local_fs 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: irccat - Simple IRC daemon 9 | # Description: irccat - Simple IRC daemon 10 | ### END INIT INFO 11 | 12 | NAME=irccat 13 | DESC=irccat 14 | USER=irc 15 | PIDFILE=/var/run/irccat.pid 16 | ANT=/usr/bin/ant 17 | CONFIGFILE=/etc/irccat/irccat.xml 18 | IRCCAT_HOME=/usr/local/src/irccat 19 | 20 | case "$1" in 21 | start) 22 | echo -n "Starting $DESC: " 23 | start-stop-daemon --background --user $USER --pidfile=$PIDFILE \ 24 | --make-pidfile --chuid $USER --startas $ANT \ 25 | --exec $JAVA_HOME/jre/bin/java --quiet --oknodo \ 26 | --start -- \ 27 | -Dconfigfile=$CONFIGFILE \ 28 | -f $IRCCAT_HOME/build.xml run 29 | echo "$NAME." 30 | ;; 31 | stop) 32 | echo -n "Stopping $DESC: " 33 | start-stop-daemon --user $USER --pidfile=$PIDFILE --chuid $USER \ 34 | --startas $ANT --exec $JAVA_HOME/jre/bin/java --quiet \ 35 | --oknodo --stop 36 | echo "$NAME." 37 | rm -f $PIDFILE 38 | ;; 39 | 40 | restart|force-reload) 41 | echo -n "Restarting $DESC: " 42 | start-stop-daemon --user $USER --pidfile=$PIDFILE --chuid $USER \ 43 | --startas $ANT --exec $JAVA_HOME/jre/bin/java --quiet \ 44 | --oknodo --stop 45 | rm -f $PIDFILE 46 | sleep 1 47 | start-stop-daemon --background --user $USER --pidfile=$PIDFILE \ 48 | --make-pidfile --chuid $USER --startas $ANT \ 49 | --exec $JAVA_HOME/jre/bin/java --quiet --oknodo \ 50 | --start -- \ 51 | -Dconfigfile=$CONFIGFILE \ 52 | -f $IRCCAT_HOME/build.xml run 53 | echo "$NAME." 54 | ;; 55 | *) 56 | N=/etc/init.d/$NAME 57 | echo "Usage: $N {start|stop|restart|force-reload}" >&2 58 | exit 1 59 | ;; 60 | esac 61 | 62 | exit 0 63 | -------------------------------------------------------------------------------- /examples/irccat.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
irc.example.com
7 | 6667 8 | 9 | 10 | 11 |
12 | 13 | 14 | irccat 15 | 16 | 250 17 | irccat 18 | 19 | 20 | 21 | 22 | 12345 23 | 127.0.0.1 24 | 25 | 26 | 27 | 31 | 32 | 33 | 34 | 35 | 36 | testchan1 37 | blah 38 | 39 | 40 | testchan2 41 | 42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /examples/twitter-feed.php: -------------------------------------------------------------------------------- 1 | refresh_url)) { 49 | $refreshUrl = $json->refresh_url; 50 | 51 | if ($firstRun) { 52 | $firstRun = false; 53 | continue; 54 | } 55 | 56 | foreach ($json->results as $result) { 57 | if ($message = processMessage($result->text, $filters, $translateTo)) { 58 | print "{$result->from_user}: {$message}\n"; 59 | } 60 | } 61 | 62 | } else { 63 | // On error, reset to front page and retry 64 | $refreshUrl = $originalUrl; 65 | } 66 | } 67 | 68 | sleep(30); 69 | } 70 | 71 | function processMessage ($string, $filters, $lang) { 72 | 73 | // Resolve shortened URL's to the full thing for filtering 74 | preg_match_all('/http:\/\/[^ $)]+/i', $string, $urls); 75 | if ($urls) { 76 | foreach ($urls[0] as $url) { 77 | if ($redirect = getRedirect($url)) { 78 | $string = str_replace($url, $redirect, $string); 79 | } 80 | } 81 | } 82 | 83 | $string = cleanString($string); 84 | 85 | if ($lang && ($aTranslation = translateString($string, $lang))) { 86 | $string = "{$aTranslation['string']} [Lang: {$aTranslation['detectedLang']}]"; 87 | } 88 | 89 | if ($filters) { 90 | foreach ($filters as $filter) { 91 | if (preg_match("/{$filter}/i", $string)) { 92 | $string = ''; 93 | break; 94 | } 95 | } 96 | } 97 | 98 | return $string; 99 | } 100 | 101 | function translateString ($string, $lang) { 102 | 103 | $translation = file( 104 | "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|{$lang}&v=1.0&q=" 105 | .urlencode($string) 106 | ); 107 | 108 | $detectedLang = false; 109 | if ($translation) { 110 | $json = json_decode(implode('', $translation)); 111 | $sourceLang = $json->responseData->detectedSourceLanguage; 112 | if (strtolower($sourceLang) != strtolower($lang) && trim($sourceLang)) { 113 | $detectedLang = $sourceLang; 114 | $string = cleanString($json->responseData->translatedText); 115 | } 116 | } 117 | 118 | if ($detectedLang) { 119 | return array( 120 | 'string' => $string, 121 | 'detectedLang' => $detectedLang, 122 | ); 123 | } 124 | 125 | return false; 126 | } 127 | 128 | function cleanString ($string) { 129 | $string = str_replace('\/','/', urldecode($string)); 130 | $string = html_entity_decode($string, null, 'UTF-8'); 131 | return htmlspecialchars_decode($string); 132 | } 133 | 134 | function getRedirect ($url) { 135 | $curl = curl_init(); 136 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 137 | curl_setopt($curl, CURLOPT_URL, $url); 138 | curl_setopt($curl, CURLOPT_HEADER, true); 139 | curl_setopt($curl, CURLOPT_NOBODY, true); 140 | $headers = curl_exec($curl); 141 | curl_close($curl); 142 | 143 | preg_match('/Location:(.*?)[\r\n]/i', $headers, $redirect); 144 | return $redirect ? urlencode(trim($redirect[1])) : false; 145 | } 146 | -------------------------------------------------------------------------------- /irccat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Run irccat. 4 | # 5 | set -e 6 | cd `dirname $0` 7 | cp="dist/irccat.jar" 8 | for jar in libs/*.jar 9 | do 10 | cp="$cp:$jar" 11 | done 12 | 13 | exec java -cp "build/:$cp" fm.last.irccat.IRCCat "${1:-irccat.xml}" 14 | -------------------------------------------------------------------------------- /libs/commons-collections-3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJ/irccat/aa9579fb18b697a32b9f6df822417f962ae30a67/libs/commons-collections-3.2.jar -------------------------------------------------------------------------------- /libs/commons-configuration-1.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJ/irccat/aa9579fb18b697a32b9f6df822417f962ae30a67/libs/commons-configuration-1.5.jar -------------------------------------------------------------------------------- /libs/commons-lang-2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJ/irccat/aa9579fb18b697a32b9f6df822417f962ae30a67/libs/commons-lang-2.3.jar -------------------------------------------------------------------------------- /libs/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJ/irccat/aa9579fb18b697a32b9f6df822417f962ae30a67/libs/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /libs/pircbot.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJ/irccat/aa9579fb18b697a32b9f6df822417f962ae30a67/libs/pircbot.jar -------------------------------------------------------------------------------- /libs/xercesImpl.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJ/irccat/aa9579fb18b697a32b9f6df822417f962ae30a67/libs/xercesImpl.jar -------------------------------------------------------------------------------- /libs/xml-apis.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RJ/irccat/aa9579fb18b697a32b9f6df822417f962ae30a67/libs/xml-apis.jar -------------------------------------------------------------------------------- /src/fm/last/irccat/CatHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | irccat - a development support irc bot 3 | Copyright (C) 2006-2008 Richard Jones 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; version 2 of the GPL only, not 3 :P 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | package fm.last.irccat; 19 | 20 | import java.net.*; 21 | import java.io.*; 22 | 23 | // passes command to external program and returns results back to irc 24 | class CatHandler extends Thread { 25 | 26 | IRCCat bot; 27 | Socket sock; 28 | 29 | CatHandler(Socket s, IRCCat b){ 30 | sock = s; 31 | bot = b; 32 | } 33 | 34 | public void run(){ 35 | try{ 36 | BufferedReader in = new BufferedReader( 37 | new InputStreamReader( 38 | sock.getInputStream(), "UTF-8")); 39 | String inputLine = new String(); 40 | String recipients[] = null; 41 | boolean all = false; 42 | boolean topic = false; 43 | int i = 0; 44 | while ((inputLine = in.readLine()) != null) { 45 | if(i++==0){ 46 | String[] words = inputLine.split(" "); 47 | if(words[0].equals("%TOPIC")) { 48 | topic = true; 49 | inputLine = inputLine.substring(7); 50 | String[] newwords = new String[words.length-1]; 51 | System.arraycopy(words, 1, newwords, 0, newwords.length); 52 | words = newwords; 53 | } 54 | if(words[0].equals("#*")){ 55 | // send to all channels 56 | all = true; 57 | inputLine = inputLine.substring(3); 58 | }else 59 | if(words[0].startsWith("#") || words[0].startsWith("@")){ 60 | String addressees[] = words[0].split(","); 61 | for(int j=0; j 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; version 2 of the GPL only, not 3 :P 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | package fm.last.irccat; 19 | 20 | import org.apache.commons.configuration.*; 21 | import org.jibble.pircbot.*; 22 | import java.net.*; 23 | import java.io.*; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.HashMap; 27 | 28 | public class IRCCat extends PircBot { 29 | 30 | private String nick; 31 | private String cmdScript; 32 | private String defaultChannel = null; 33 | private int maxCmdResponseLines = 26; 34 | private XMLConfiguration config; 35 | 36 | public static void main(String[] args) throws Exception { 37 | try { 38 | if (args.length == 0) { 39 | System.out.println("first param should be config file"); 40 | System.exit(-1); 41 | } 42 | XMLConfiguration c = null; 43 | try { 44 | c = new XMLConfiguration(args[0]); 45 | } catch (ConfigurationException cex) { 46 | System.err.println("Configuration error, check config file"); 47 | cex.printStackTrace(); 48 | System.exit(1); 49 | } 50 | 51 | IRCCat bot = new IRCCat(c); 52 | 53 | // listen for stuff and send it to irc: 54 | ServerSocket serverSocket = null; 55 | InetAddress inet = null; 56 | try { 57 | if (bot.getCatIP() != null) 58 | inet = InetAddress.getByName(bot.getCatIP()); 59 | } catch (UnknownHostException ex) { 60 | System.out 61 | .println("Could not resolve config cat.ip, fix your config"); 62 | ex.printStackTrace(); 63 | System.exit(2); 64 | } 65 | 66 | try { 67 | serverSocket = new ServerSocket(bot.getCatPort(), 0, inet); 68 | } catch (IOException e) { 69 | System.err.println("Could not listen on port: " 70 | + bot.getCatPort()); 71 | System.exit(1); 72 | } 73 | 74 | System.out.println("Listening on " + bot.getCatIP() + " : " 75 | + bot.getCatPort()); 76 | 77 | while (true) { 78 | try { 79 | Socket clientSocket = serverSocket.accept(); 80 | // System.out.println("Connection on catport from: " 81 | // + clientSocket.getInetAddress().toString()); 82 | CatHandler handler = new CatHandler(clientSocket, bot); 83 | handler.start(); 84 | } catch (Exception e) { 85 | e.printStackTrace(); 86 | } 87 | } 88 | 89 | } catch (Exception e) { 90 | e.printStackTrace(); 91 | } 92 | 93 | } 94 | 95 | public IRCCat(XMLConfiguration c) throws Exception { 96 | this.config = c; 97 | setEncoding("UTF8"); 98 | cmdScript = config.getString("script.cmdhandler"); 99 | maxCmdResponseLines = config.getInt("script.maxresponselines", 26); 100 | nick = config.getString("bot.nick"); 101 | setName(nick); 102 | setLogin(nick); 103 | setVersion(config.getString("bot.version", getVersion())); 104 | setMessageDelay(config.getLong("bot.messagedelay", 1000)); 105 | setFinger(config.getString("bot.finger", 106 | "IRCCat - a development support bot, used by Last.fm")); 107 | 108 | 109 | try { 110 | // connect to server 111 | int tries =0 ; 112 | while (!isConnected()) { 113 | tries++; 114 | System.out.println("Connecting to server [try "+tries+"]: "+ config.getString("server.address")); 115 | connect(config.getString("server.address"), config.getInt( 116 | "server.port", 6667), config.getString( 117 | "server.password", "")); 118 | if(tries>1) Thread.sleep(10000); 119 | } 120 | } catch (Exception e) { 121 | System.out.println(e.toString()); 122 | } 123 | 124 | } 125 | 126 | public String getCmdScript() { 127 | return cmdScript; 128 | } 129 | 130 | public int getCmdMaxResponseLines() { 131 | return maxCmdResponseLines; 132 | } 133 | 134 | protected void onDisconnect(){ 135 | while (!isConnected()) { 136 | try { 137 | reconnect(); 138 | } 139 | catch (Exception ex) { 140 | try { 141 | Thread.sleep(10000); 142 | } catch (InterruptedException e) { 143 | break; 144 | } 145 | } 146 | } 147 | } 148 | 149 | @SuppressWarnings("unchecked") 150 | protected void onConnect() { 151 | 152 | // join channels 153 | List chans = config 154 | .configurationsAt("channels.channel"); 155 | for (HierarchicalConfiguration chan : chans) { 156 | System.out.println("/join #" + chan.getString("name")); 157 | joinChannel("#" + chan.getString("name") + " " 158 | + chan.getString("password", "")); 159 | // first one in the list considered default: 160 | if (defaultChannel == null) 161 | defaultChannel = "#"+chan.getString("name"); 162 | } 163 | String nickpass = config.getString("server.identify",""); 164 | if(nickpass != "") identify(nickpass); 165 | 166 | System.out.println("Default channel: "+defaultChannel); 167 | } 168 | 169 | public int getCatPort() { 170 | return config.getInt("cat.port", 12345); 171 | } 172 | 173 | public String getCatIP() { 174 | return config.getString("cat.ip", "127.0.0.1"); 175 | } 176 | 177 | public String getDefaultChannel() { 178 | return defaultChannel; 179 | } 180 | 181 | // PM was sent to us on irc 182 | public void onPrivateMessage(String sender, String login, String hostname, 183 | String message) { 184 | handleMessage(null, sender, message); 185 | } 186 | 187 | public void changeTopic(String target, String topic) { 188 | super.setTopic(target, topic); 189 | } 190 | 191 | public void sendMsg(String t, String m) { 192 | m = mIRCify(m); 193 | super.sendMessage(t, m); 194 | } 195 | 196 | public String mIRCify(String m) { 197 | Map colorReplacementMap = new HashMap(); 198 | colorReplacementMap.put("NORMAL", Colors.NORMAL); 199 | colorReplacementMap.put("BOLD", Colors.BOLD); 200 | colorReplacementMap.put("UNDERLINE", Colors.UNDERLINE); 201 | colorReplacementMap.put("REVERSE", Colors.REVERSE); 202 | colorReplacementMap.put("WHITE", Colors.WHITE); 203 | colorReplacementMap.put("BLACK", Colors.BLACK); 204 | colorReplacementMap.put("DBLUE", Colors.DARK_BLUE); 205 | colorReplacementMap.put("DGREEN", Colors.DARK_GREEN); 206 | colorReplacementMap.put("RED", Colors.RED); 207 | colorReplacementMap.put("BROWN", Colors.BROWN); 208 | colorReplacementMap.put("PURPLE", Colors.PURPLE); 209 | colorReplacementMap.put("ORANGE", Colors.OLIVE); 210 | colorReplacementMap.put("YELLOW", Colors.YELLOW); 211 | colorReplacementMap.put("GREEN", Colors.GREEN); 212 | colorReplacementMap.put("TEAL", Colors.TEAL); 213 | colorReplacementMap.put("CYAN", Colors.CYAN); 214 | colorReplacementMap.put("BLUE", Colors.BLUE); 215 | colorReplacementMap.put("PINK", Colors.MAGENTA); 216 | colorReplacementMap.put("DGRAY", Colors.DARK_GRAY); 217 | colorReplacementMap.put("GRAY", Colors.LIGHT_GRAY); 218 | 219 | for(Map.Entry e : colorReplacementMap.entrySet()) { 220 | // Support #COLOR or %COLOR 221 | // either format can be confusing, depending on context. 222 | m = m.replaceAll( "%" + e.getKey(), e.getValue()); 223 | m = m.replaceAll( "#" + e.getKey(), e.getValue()); 224 | } 225 | return m; 226 | } 227 | 228 | // message sent to our channel 229 | public void onMessage(String channel_, String sender, String login, 230 | String hostname, String message) { 231 | handleMessage(channel_, sender, message); 232 | } 233 | 234 | public void onPart(String _channel, String _sender, String _login, 235 | String _hostname) { 236 | if (!_sender.equals(nick)) 237 | return; 238 | // System.out.println("Exiting due to onPart()"); 239 | // System.exit(-1); 240 | } 241 | 242 | public void onQuit(String _sourceNick, String _sourceLogin, 243 | String _sourceHostname, String _reason) { 244 | if (!_sourceNick.equals(nick)) 245 | return; 246 | System.out.println("Exiting due to onQuit()"); 247 | System.exit(-1); 248 | } 249 | 250 | public void onKick(String channel_, String kickerNick, String kickerLogin, 251 | String kickerHostname, String recipientNick, String reason) { 252 | if (!recipientNick.equals(nick)) 253 | return; 254 | 255 | // we were kicked 256 | } 257 | 258 | // is this nick trusted? (are they in the default channel) 259 | private boolean isTrusted(String n){ 260 | //return true 261 | User[] users = getUsers(getDefaultChannel()); 262 | for(int j =0; j "+message); 283 | return; 284 | } 285 | // irccat builtin command processing: 286 | String resp = handleBuiltInCommand(message.substring(1).trim(), 287 | sender); 288 | if (!(resp == null || resp.equals(""))) 289 | sendMessage(respondTo, resp); 290 | 291 | System.out.println("Built-in: ["+respondTo+"] <"+sender+"> "+message); 292 | return; 293 | } 294 | 295 | if (message.startsWith("?")) { 296 | // external script command. 297 | cmd = message.substring(1).trim(); 298 | } else { 299 | // just a normal message which we ignore 300 | return; 301 | } 302 | 303 | if (cmd.trim().length() < 1) 304 | return; 305 | 306 | // if a PM, you gotta be trusted. 307 | if(channel_ == null && !isTrusted(sender)) { 308 | System.out.println("UNTRUSTED (ignoring): ["+respondTo+"] <"+sender+"> "+message); 309 | return; 310 | } 311 | 312 | // now "cmd" contains the message, minus the address prefix (eg: ?) 313 | // hand off msg to thread that executes shell script 314 | System.out.println("Scripter: ["+respondTo+"] <"+sender+"> "+message); 315 | Thread t = new Scripter(sender, channel_, respondTo, cmd, this); 316 | t.run(); 317 | } 318 | 319 | /* 320 | * Basic built-in command processing allows you to instruct the bot at 321 | * runtime to join/leave channels etc 322 | */ 323 | protected String handleBuiltInCommand(String cmd, String sender) { 324 | String toks[] = cmd.split(" "); 325 | String method = toks[0]; 326 | 327 | // JOIN A CHANNEL 328 | if (method.equals("join") && toks.length >= 2) { 329 | if (toks.length == 3) 330 | joinChannel(toks[1], toks[2]); 331 | else 332 | joinChannel(toks[1]); 333 | 334 | sendMessage(toks[1], "<" + sender + "> !" + cmd); 335 | return "Joining: " + toks[1]; 336 | } 337 | 338 | // PART A CHANNEL 339 | if (method.equals("part") && toks.length == 2) { 340 | sendMessage(toks[1], "<" + sender + "> !" + cmd); 341 | partChannel(toks[1]); 342 | return "Leaving: " + toks[1]; 343 | } 344 | 345 | // BROADCAST MSG TO ALL CHANNELS 346 | if (method.equals("spam")) { 347 | this.catStuffToAll("<" + sender + "> " + cmd.substring(5)); 348 | } 349 | 350 | // LIST CHANNELS THE BOT IS IN 351 | if (method.equals("channels")) { 352 | String[] c = getChannels(); 353 | StringBuffer sb = new StringBuffer("I am in " + c.length 354 | + " channels: "); 355 | for (int i = 0; i < c.length; ++i) 356 | sb.append(c[i] + " "); 357 | return sb.toString(); 358 | } 359 | 360 | // EXIT() 361 | if (method.equals("exit")) 362 | System.exit(0); 363 | 364 | return ""; 365 | } 366 | 367 | public void catTopic(String stuff, String[] recips) { 368 | for (int ci = 0; ci < recips.length; ci++) { 369 | changeTopic(recips[ci], stuff); 370 | } 371 | } 372 | 373 | public void catTopicToAll(String stuff) { 374 | String[] channels = getChannels(); 375 | for (int i = 0; i < channels.length; i++) { 376 | changeTopic(channels[i], stuff); 377 | } 378 | } 379 | 380 | public void catStuffToAll(String stuff) { 381 | String[] channels = getChannels(); 382 | for (int i = 0; i < channels.length; i++) { 383 | sendMsg(channels[i], stuff); 384 | } 385 | } 386 | 387 | public void catStuff(String stuff, String[] recips) { 388 | for (int ci = 0; ci < recips.length; ci++) { 389 | sendMsg(recips[ci], stuff); 390 | } 391 | } 392 | 393 | } 394 | -------------------------------------------------------------------------------- /src/fm/last/irccat/Scripter.java: -------------------------------------------------------------------------------- 1 | /* 2 | irccat - a development support irc bot 3 | Copyright (C) 2006-2008 Richard Jones 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; version 2 of the GPL only, not 3 :P 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | package fm.last.irccat; 19 | 20 | import java.io.*; 21 | 22 | // hands off cmd to shell script and returns stdout to the requester 23 | class Scripter extends Thread { 24 | IRCCat bot; 25 | String nick, channel, returnName, cmd; 26 | 27 | Scripter(String nk, String ch, String r, String c, IRCCat b){ 28 | nick = nk; 29 | channel = ch; 30 | cmd = c; 31 | returnName = r; 32 | bot = b; 33 | } 34 | 35 | public void run(){ 36 | try{ 37 | Runtime runtime = Runtime.getRuntime(); 38 | Process process = runtime.exec(new String[]{bot.getCmdScript() ,nick + " " + channel + " " + returnName+" "+cmd}); 39 | InputStream is = process.getInputStream(); 40 | InputStreamReader isr = new InputStreamReader(is, "UTF-8"); 41 | BufferedReader br = new BufferedReader(isr); 42 | String line; 43 | int i=0; 44 | while ((line = br.readLine()) != null) { 45 | bot.sendMsg(returnName, line); 46 | if(++i==bot.getCmdMaxResponseLines()){ 47 | bot.sendMsg(returnName, ""); 48 | break; 49 | } 50 | } 51 | }catch(Exception e){ 52 | e.printStackTrace(); 53 | } 54 | 55 | } 56 | } 57 | 58 | --------------------------------------------------------------------------------