Thermodynambot v004-01 Perl script for X-Chat 2 (versions 2.0.8+) by b0at released into the public domain 08 November 2004 INCOMPATIBILITIES WITH VERSION 002 and 003: None. INCOMPATIBILITIES WITH VERSION 001: In version 001 '-' was used to signify no mode (eg -mode: -, +), which was lazy but simple. Some networks may use that character to signify a mode, however. In version 002 you can use 'nomode' to indicate users with no mode (eg -mode: nomode, +), which leaves '-' free for when it might actually crop up. Please check your _thermodynambot.conf and change this if you used 001 and that notation. CHANGES FROM 004: Added a keyword, the lack of which prevented a number of macros from expanding properly (had it added user and addr to the user_info hash if not user and addr instead of if not user and not addr). SUMMARY OF CHANGES SINCE 003: The output from the /who command is now hooked in the case when user_info can't retrieve the user's data (isn't in the context). This means that +in: private actually works now (that and the removal of a dumb bug that captured the wrong value from the config file). Also, added the macro '%o' which expands to the mode of the user. SUMMARY OF CHANGES FROM 001 TO 002: +in/-in take optional networks in the form network:private, network:action, network:#channel (in addition to plain private, action, #channel) Networks can be wildcards and are always case insensitive. Channels can still be wildcards whether or not they have networks specified. The new %w macro expands to the current network. Note: If a network name is not available (e.g., if you didn't connect via the server list and the server doesn't send a network name) then %w will contain and all events will be matched against the current server (or 'offline' if you're not connected or the server can't be found for some reason). NEW FEATURES YOU SHOULD MAYBE BE AWARE OF WHY NOT SINCE 001: User command testing with TDBECHO and TDBTEST, from /help TDBTEST: Usage: TDBTEST '' quotes on mode are required (eg '@', '+', '') ispriv and isaction should be 1 or 0 TDBTEST runs the commands, TDBECHO prints the commands instead With these you can trigger events at any time with any data. All arguments are required. The first argument must include all three of the nick, user, and address. Quotes on the mode are required (use '' for no mode, '@' for ops, etc). "ispriv" indicates if the message should be treated as if it were private, and "isaction" indicates the same for an action ctcp (eg /me, /describe). TDBTEST will run commands triggered as if the event actually occurred: great for triggering something within a channel, for example. TDBECHO will print out the command that would have been run, macros expanded appropriately and all: handy for testing your events privately or offline. SEEKING HELP: Visit #xchat on EFnet, Freenode, or OFTC. Please mention your xchat version number (and build, if not official), any scripts involved and their versions, and your operating system. Be patient and show your support by helping out if you can. FILES: Available at http://b0at.nm.ru/xchat/thermodynambot/002/ as of this writing: thermodynambot-004.pl the script readme.txt this file readme_70.txt this file wrapped to 70 cols _thermodynambot.conf simple .conf file example SHORT INSTALLATION AND USAGE: Edit _thermodynambot.conf, put it and the script into your profile directory, reload the perl plugin. LONG-WINDED INSTALLATION: (0) First make sure you have Perl and the Perl plugin installed. Windows users who need Perl are recommended to use ActiveState's ActivePerl (www.activestate.com/Products/ActivePerl/) but most any distribution will suffice. The Perl plugin is usually either included automatically or as an option during installation. If when you try to load a script it says "Maybe you need to install the Perl or Python plugin?", then the Perl plugin isn't installed or loaded. (1) For each of the platforms below, put the .pl and .conf files for the script in the directory specified (usually the profile directory): - *nix: ~/.xchat2/ - Windows 2000/XP: %userprofile%\Application Data\X-Chat 2\ Simply copy and paste this path in explorer as is. The environment variable %userprofile% will usually expand to C:\Documents and Settings\ - xchat-aqua: Applications/X-ChatAqua/Plugins/ Replace X-ChatAqua with whatever you named the xchat app dir. - Or go to the logging preferences, open the logging directory (or "Data Folder"), and go up one directory from there. - This script uses Xchat::get_info('xchatdir') to find the .conf. If you have the Python plugin loaded, use the following commands in sequence to find your 'xchatdir' (the first one doesn't output anything): /py exec import xchat /py exec xchat.get_info('xchatdir') [Thanks to Zered from Freenode/#xchat for those.] (2) Edit _thermodynambot.conf to your heart's desire. Make sure to read about the syntax and the examples (below) first. (3) Reload the Perl plugin (/reloadall or Windows->Scripts and Plugins, select it, click 'unload', click load, browse to the xchat program directory's plugins subdirectory, load the file with 'perl' in its name) or restart X-Chat (not necessary unless you prefer it). Be careful not to load it twice if you're working in the Scripts and Plugins dialog. (4) Wait for text to match and responses to ensue. NOTES ON .CONF SYNTAX: Changes below new to a version are indicated with the version number in brackets: text below last updated in version <004>. Comments only span one full line and must start with a hash ('#'). Comments, empty lines, __END__ on a line by itself, and anything after __END__ by itself are ignored. "Parse error on line " will be printed to the tab active while the script loads if a line is read but can't be parsed as valid data. Basic entry syntax (including optional parameters): [pattern] +in: place inclusions -in: place exclusions +from: user inclusions -from: user enclusions +mode: mode inclusions -mode: mode exclusions command: xchat command to execute on match pattern: either a wildcard pattern prepended by 'text:' (which is case insensitive) or a regular expression prepended by 'regex:' (which is case sensitive; use '(?i)' at the start for case insensitivity; see perlre, perlretut, perlrequick in perldoc). Patterns may be repeated. Patterns aren't anchored to the beginning or end unless you specify anchoring (regex only)[text:foo] matches 'foo bar' and 'bar foo'. [regex:^foo] matches 'foo bar' but not 'bar foo'. +in: comma-separated list of places to listen in for the pattern. You can specify channel names with wildcards (* for all channels, #foo* for all channels starting with foo). Special values include 'private' for private messages and 'action' to listen to action ctcps (/me, /describe). <003> You can specify wildcard network names with wildcard channels or 'private' or 'action' by separating them with a colon. Note that the xchat client must be in a channel to listen to messages from it. Example: +in: *, private matches in all channels and private messages. <003> While +in: *, efnet:private matches in all channels in all networks and private messages only on efnet. -in: (optional) comma-separated list of places not to listen in for the pattern. It takes the same arguments as +in. This list overrides the +in list. Example: +in: * -in: efnet:* matches messages from every network except efnet. <003> Simlarly, +in: #bob -in: bobnet:#bob matches in all #bob channels on all networks except for bobnet. <002> (+in and -in are replaceable by +where and -where, respectively) +from: comma-separated list of users to listen to for the pattern. You can specify full host masks with wildcards (bob*!*@*) or regular expressions (prepend with an ampersand ['&'] for regex; eg, &.*?![a-z]+@.*). End a nick in '!' to match it with any host (bob*!, b?b!, bob!), prepend an address with '@' to match any nick/ident with it (eg @*foo.com). Anything that doesn't match a full hostmask ([^!]+![^@]+@.+) or a lonesome nick or address (beginning in ! or ends in @) will be considered a wildcard expression. Example: +from: bob!, *!*bob@*, *!*@*bob.com listens to matches from anyone with the nick 'bob', with an ident/user name that matches '*bob', with an address ending in 'bob.com'. +from: * matches anyone. Note that, because of the way xchat retrieves user data, host data for users who are not in the same channel as the client and who send a private message is not available. This could (hopefully) be circumvented by hooking the results of a /who $nick and then processing the original event data, but I'll save that for later. Also note that the 'Your Message' print event is not hooked by default, which means you can't trigger events from the same client that the script is running. This prevents infinite loops in the current absence of any anti-loop code. For now, test with a buddy or with another instance of xchat on the same server. -from: (optional) comma-separated list of users not to listen to for the pattern. It takes the same arguments as +from. This list overrides the +from list. Example: +from: * -from: bob! matches everyone but bob. +mode: (optional) comma-separated list of modes which users who are listened to are limited to. If specified, only users with these modes (eg @, +, %) are listened to for matches. If not specified, any user modes are allowed. Special values: '-' to signify no mode. Note that only the visible mode is can be matched against. -mode: (optional) comma-separated list of modes which exclude users. If specified, users without these modes do not match the pattern. -mode can be specified without specifying +mode. Example: +mode: + will match voiced users who aren't ops or halfops. -mode: - will prevent people without a mode from matching (ie only voiced, ops, halfops, etc). command: a single xchat command (without any preceding command character: 'say foo', not '/say foo'). You can use multiple commands per entry. When you include 'private' in the +in list, use 'msg %c' in your commands to respond to users instead of 'say'; otherwise responses to private messages will be sent to the active channel tab (unless that is your intention, of course, which can be a handy feature in that case). Commands are interoplated for a few macros/keywords: '%%' is replaced with a single percent sign '%' Color codes (%B, %C, %U, %V for reverse, %O for reset) are interpreted correctly. They must be upper case. '%n' is replaced with the user's nick name '%u' is replaced with the user's user name (ident) '%a' is replaced with the user's address '%c' is replaced with the channel they joined (or their nick if in private) <004>'%o' is replaced with the user's mode in the channel (empty if private) <003>'%w' is replaced with the network name (or server name) '%m' is replaced with your own nick name '%d' is replaced with the current local date '%y' is replaced with the current gmt date (in '%Y/%m/%d' format from strftime) '%t' is replaced with the current local time '%z' is replaced with the current gmt (zulu) date (in '%H:%M:%S' format from strftime) '%s' is replaced with the full text matched '%1' (for 1 to the number of matches, up to 9) is replaced with the regular expression capture or wildcard match of that number or nothing if there was no capture. Example: [regex:^(\S)(?:\s+(.*))] which matched 'foo bar' sets %1 to 'foo', %2 to 'bar', and %3 to %9 to ''; while [text:foo ?* *] which matched 'foo bar' sets %1 to 'b' (the ? match), %2 to 'ar' (the * match), '%$' is replaced with the last regex capture, if any. Any unmatched macros are removed (eg, '%q' expands to ''; to output '%q' use '%%q'). Examples: command: say foo command: echo bar command: msg %c You said "%s". Example Entries: [text:words go here] +in: private , *, action -in: #notinthischannel +from: bob!, *!*@*.bob.user +mode: @, %, + -mode: - command: msg %c Foo bar. # escape your slashes [regex:(?i)^(asl|a\/s\/l\/)[?!/]*$] +in: * +from: * # people without a mode only +mode: - command: kick %n No "%1" [text:!ignore * *] +in: * +from: * +mode: @ command: say Ignoring %1 for %2 seconds command: ignore %1 ALL command: timer %2 say Unignoring %1... command: timer %2 unignore %1 # Be very careful with the next examples. [regex:(?i)^!exec\s+(.*)] +in: #someprivatechannelname +from: * +mode: command: exec -o %s [regex:(?i)^!xchat\s+(.*)] +in: * +from: * +mode: @ command: notice bob Use of !xchat command: %s command: %1 EOF.