IRC Script Executive
"exec" is a script that runs in a CLI that connects to the Soylent IRC server (irc.sylnt.us:6667) and executes other programs and facilitates their interaction with IRC.
Input to a script/program is via command line arguments only. Communication with a program through stdin is supported, but only using a similar syntax to IRC messages and currently stdin is used only to respond to bucket get messages (php scripts can use the lib.php get_bucket function).
stdout of an executed script/program may be passed to an IRC channel or output to exec's stdout (terminal), depending on the value of auto-privmsg in the exec line. If auto-privmsg=0, stdout from the script/program must begin with IRC_MSG or IRC_RAW for it to be sent to IRC. If auto-privmsg=1, all stdout from the script/program is assumed to be prefixed with IRC_MSG and is sent to IRC; this is generally required for programs that can't be easily edited, such as shell binaries (cowsay, fortune, etc).
Programs executed may be anything accessible from the CLI of the machine running the exec script. They may be shell programs (such as cowsay and fortune), php scripts (executed using the CLI php command) or scripts in any other language executable by their respective CLI interpreters (python, perl, haskell, etc).
Download above files from github, open a terminal and change to that directory, and run "php irc.php".
Scripts may be stored anywhere that is accessible to the bot script for CLI execution. If stored in a different location, the script path must be included in the exec file line.
"Buckets" are a feature of exec that allow scripts to store data in a common location which is accessible from any script and is retained/persistent between script executions. Each bucket consists of an array element in the main bot program that is read, written and cleared using IRC-like commands (see below) passed through stdout/stdin pipes from/to executed scripts - buckets are filled by pipes hahaha :-P
Complex data in array form may be stored using php's serialize/unserialize (or equivalent in other languages).
Buckets are referenced by an index string.
:exec BUCKET_GET :index :exec BUCKET_SET :index data :exec BUCKET_UNSET :index
For PHP scripts, there are get_bucket, set_bucket and unset_bucket functions available in lib.php, which can be found here: https://github.com/crutchy-/test/blob/master/scripts/lib.php
A whois command is issued to verify the account name of a user identified with NickServ for authentication purposes.
Some functions are restricted for use by accounts in a hardcoded admin account list.
~q ~reload ~dest-override ~dest-clear ~buckets-dump # dump buckets to terminal ~buckets-save # save buckets to file ~buckets-load # load buckets from file ~buckets-flush # re-initialize buckets ~buckets-list # output list of set bucket indexes to the terminal ~monitor
Example exec file
# alias|timeout(sec)|repeat(sec)|auto-privmsg(1|0)|empty-trailing-allowed(1|0)|account1,account2,etc(or-empty)|cmd # available templates: %%trailing%%, %%dest%%, %%nick%%, %%start%%, %%alias%%, %%cmd%%, %%data%%, %%exec%%, %%params%% # %%trailing%% excludes alias # EXEC ON ALL LINES - ONLY ONE EXEC LINE ALLOWED SO ADD TO COMMAND USING && *|10|0|0|1||php scripts/cmd.php %%cmd%% %%trailing%% %%data%% %%dest%% %%params%% %%nick%% # EXEC BEFORE IRC CONNECTION - ONLY ONE EXEC LINE ALLOWED SO ADD TO COMMAND USING && <init>|10|0|0|1||php scripts/init.php # EXEC ON QUIT - ONLY ONE EXEC LINE ALLOWED SO ADD TO COMMAND USING && <quit>|10|0|0|1||php scripts/quit.php # REQUIRE ADMIN CHECK ~say|2|0|1|0|crutchy|php scripts/say.php %%trailing%% %%nick%% ~bucket|5|0|0|1|crutchy|php scripts/bucket.php %%trailing%% %%nick%% %%dest%% ~wiki|20|0|0|0|crutchy|php scripts/wiki.php %%trailing%% %%dest%% %%nick%% ~ping|5|0|0|1|crutchy|php scripts/ping.php # called from other scripts via NOTICE cmd ~AUJ73HF839CHH2933HRJPA8N2H|5|0|0|0||php scripts/sed.php %%trailing%% %%nick%% %%dest%% %%cmd%% ~TXVHG62M7CGR4K9SC5H6R1S29G|5|0|0|0||php scripts/funnel.php %%cmd%% %%trailing%% %%data%% %%dest%% %%params%% %%nick%% # timer scripts ~UG4HO6EW9NBBE9CH51SOK6H8N3|5|360|0|1||php scripts/monitor.php %%trailing%% %%nick%% %%start%% # NON-TILDE ALIASES rofl|5|0|1|1||fortune -s -o # GENERAL USAGE ALIASES ~|5|0|1|1||php scripts/about.php %%trailing%% ~cowsay|5|0|1|0||cowsay %%trailing%% ~moo|10|0|1|1||apt-get moo ~fortune|5|0|1|1||fortune -s ~php|5|0|0|0||php scripts/php.php %%trailing%% ~con/con|10|0|1|1||php scripts/bsod.php ~bsod|10|0|1|1||php scripts/bsod.php ~join|5|0|0|0||php scripts/join.php %%trailing%% ~part|5|0|0|1||php scripts/part.php %%dest%% %%trailing%% ~isup|30|0|0|0||php scripts/isup.php %%trailing%% ~time|30|0|0|0||php scripts/time.php %%trailing%% ~rainbow|5|0|0|0||php scripts/rainbow.php %%trailing%% ~define|20|0|0|0||php scripts/definitions.php %%trailing%% %%alias%% ~define-add|10|0|0|0||php scripts/definitions.php %%trailing%% %%alias%% ~define-count|5|0|0|1||php scripts/definitions.php %%trailing%% %%alias%% ~weather|10|0|0|1||php scripts/weather.php %%alias%% %%trailing%% ~weather-add|10|0|0|1||php scripts/weather.php %%alias%% %%trailing%% ~civ|120|0|0|1||php scripts/irciv.php %%nick%% %%trailing%% %%dest%% %%start%% %%alias%% ~civ-admin|120|0|0|1|crutchy|php scripts/irciv.php %%nick%% %%trailing%% %%dest%% %%start%% %%alias%% ~civ-map|300|0|0|1||php scripts/irciv_map.php %%nick%% %%trailing%% %%dest%% ~civ-save|5|1200|0|1||php scripts/irciv.php '<<SAVE>>' ~civ-todo|20|0|0|1||php scripts/irciv_todo.php %%nick%% # non-php scripts #~haskell|5|0|1|1||runhaskell scripts/haskell.hs #~perl|5|0|1|1||perl scripts/perl.pl #~fb|10|0|1|1||perl scripts/fb.pl (TheMightyBuzzard) # scripts by chromas ~mackey|5|0|1|0||php /nas/server/git/chromas/mackey.php %%trailing%% %%nick%%
Available exec templates
- %%trailing%% = the message string visible in an IRC client
- %%dest%% = the channel/pm nick where the message originated
- %%nick%% = the nickname of the sender
- %%start%% = microtime(True) result when bot was started
- %%alias%% = the command alias that triggered the script
- %%cmd%% = the IRC command (PRIVMSG,NOTICE,QUIT,PART,NICK,JOIN,numeric,etc)
- %%data%% = the entire IRC line (refer below)
- %%exec%% = the exec line for the trigger alias
- %%params%% = the params part of the IRC line (refer below; usually same as %%dest%% except when %%cmd%% is a numeric)
:<prefix> <command> <params> :<trailing>
PHP script template
If anyone is interested in adding their own script, talk to crutchy (usually hangs out in #soylent and #test) who will be happy to help as best he can.
Usage in IRC
To invoke a script in IRC client:
<crutchy> ~define atlantic ocean <exec> 1 | noun | the 2nd largest ocean; separates North and South America on the west from Europe and Africa on the east\n2 | adjective | relating to or bordering the Atlantic Ocean
In the above example, "~define" is the alias, "atlantic ocean" is passed to the script as %%trailing%% and can be accessed in PHP scripts using the $argv global array variable.
- ~weather location
- ~weather-add code location
note: ~weather-add code location will change the location of the code if the code has already been entered. Currently, codes cannot be deleted.
A few thousand ICAO and IATA/FAA airport codes have been imported into the codes file thanks to OpenFlights.
<crutchy> ~weather <exec> IRC WEATHER INFORMATION BOT <exec> usage: "~weather location" (visit http://wiki.soylentnews.org/wiki/IRC:exec#Weather_script for more info) <exec> data courtesy of the APRS Citizen Weather Observer Program (CWOP) @ http://weather.gladstonefamily.net/ <exec> by crutchy: https://github.com/crutchy-/test/blob/master/scripts/weather.php
<crutchy> ~weather JFK <exec> Weather for Brooklyn, NY US at 2014-04-14 03:36:00 (UTC) ~ 0.8 hrs ago: <exec> temperature = 66°F (18.9°C) dewpoint = 56.3°F (13.5°C) <exec> barometric pressure = 1017.3 mb ~ change of 0 mb over past 0.2 hrs relative humdity = 71% <exec> wind speed = 1 mph (1.6 km/h) wind direction = 336°
<kobach> ~weather vostok, aq <exec> Weather for Vostok Station (RUS), -, Antarctica (the territory South of 60 deg S) at 2014-04-14 12:00:00 (UTC) ~ 0.8 hrs ago: <exec> temperature = -83.7°F (-64.3°C) dewpoint = -90.9°F (-68.3°C) <exec> barometric pressure = 948.9 mb ~ change of 1.6 mb over past 6 hrs relative humdity = 57% <exec> wind speed = 10 mph (16 km/h) wind direction = 200°
<crutchy> ~weather-add crutchy melbourne australia <exec> code "crutchy" set for location "melbourne australia"
<crutchy> ~weather crutchy <exec> Weather for Melbourne Regional Office, VIC, Australia at 2014-04-14 11:00:00 (UTC) ~ 0.8 hrs ago: <exec> temperature = 60.4°F (15.8°C) dewpoint = 50.2°F (10.1°C) <exec> barometric pressure = 1023.5 mb ~ change of -1.4 mb over past 3 hrs relative humdity = 68% <exec> wind speed = (no data) wind direction = 0°