IRC:exec: Difference between revisions
Line 43: | Line 43: | ||
Some functions are restricted for use by accounts in a hardcoded admin list. | Some functions are restricted for use by accounts in a hardcoded admin list. | ||
< | <source lang="dot"> | ||
~q | ~q | ||
~reload | ~reload | ||
Line 54: | Line 54: | ||
~buckets-list # output list of set bucket indexes to the terminal | ~buckets-list # output list of set bucket indexes to the terminal | ||
~monitor | ~monitor | ||
</ | </source> | ||
==Exec file== | ==Exec file== |
Revision as of 12:09, 4 June 2014
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 for output to an IRC channel.
Input to a script/program is via command line arguments only (stdin is not supported).
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 "privmsg " for it to be sent to the IRC channel.
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, etc).
Bot development
Developer(s): crutchy
Source: https://github.com/crutchy-/test
Files:
- https://github.com/crutchy-/test/blob/master/irc.php
- https://github.com/crutchy-/test/blob/master/exec
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
"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
Currently having difficulty reading large amounts of data and use of gzcompress is hampered by control characters, but you can store complex data in array form by using php's serialize/unserialize (or equivalent in other languages).
Buckets are referenced by an index string, which is encoded/decoded by the bot.
:exec BUCKET_GET :index :exec BUCKET_SET :index data :exec BUCKET_UNSET :index
Tested PHP functions for reading/writing bucket data can be found here: https://github.com/crutchy-/test/blob/master/scripts/lib.php
Administration commands
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 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
Exec file
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%%
#~JRB8D93MSCRQ92E4M1LE9BCX89|5|0|0|0||php scripts/grab.php %%trailing%% %%nick%%
# timer scripts
~UG4HO6EW9NBBE9CH51SOK6H8N3|5|360|0|1||php scripts/monitor.php %%trailing%% %%nick%% %%start%%
#~H5IG287BHWO9XNN76FJ10KJYN6|5|30|0|1||php scripts/comments.php %%trailing%% %%nick%% %%dest%%
# NON-TILDE ALIASES
rofl|5|0|1|1||fortune -s -o
karma|5|0|0|0|php scripts/comments.php %%trailing%% %%nick%% %%dest%% %%alias%%
# 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%%
#~snake|5|0|1|1||echo %%trailing%% | cowsay -f elephant-in-snake
#~test|5|0|0|0||php scripts/test.php %%trailing%% %%dest%% %%nick%%
#~cowsay-fortune|5|0|1|1||sh cowsay-fortune.sh
#~smile|5|0|1|0||php scripts/smile.php %%trailing%%
#~uptime|5|0|1|1||uptime
#~bad|5|0|1|1||fortune -s -o
#~exec-up|5|0|0|1||php scripts/up.php %%start%%
#~sylnt|10|0|1|1||php scripts/soylent.php
#~recurse|5|0|0|1||php scripts/recurse.php
#~tux|5|0|1|0||cowsay -f tux %%trailing%%
#~greet|5|0|0|0||php scripts/greet.php %%trailing%% %%nick%% %%alias%%
#~computer|5|0|0|0||php scripts/computer.php %%trailing%% %%dest%% %%nick%%
~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)
IRC line:
:<prefix> <command> <params> :<trailing>
Script development
Example script
<?php
# test|5|0|0|php scripts/test.php %%trailing%% %%dest%% %%nick%%
echo "when auto-privmsg=0 this shows on terminal (stdout) only\n";
echo "privmsg msg=".$argv[1]."\n";
echo "privmsg chan=".$argv[2]."\n";
echo "privmsg nick=".$argv[3]."\n";
?>
If anyone is interested in adding their own script, do a github fork/pull and/or let crutchy know (crutchy usually hangs out in #soylent and #test).
Usage in IRC
To invoke a script in IRC client:
alias [msg]
Example:
<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 command alias, "atlantic ocean" is passed to the script as %%msg%%
IRCiv
Weather script
Developer(s): crutchy
Source: https://github.com/crutchy-/test/blob/master/scripts/weather.php
Available commands:
- 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.
Usage examples
<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°