Getting started
Scripts live in the plugins folder inside IRChatterbox's data folder. The quickest way there is Settings → Plugins → Open data folder, then open plugins.
| System | Plugins folder |
|---|---|
| Windows | %APPDATA%\IRChatterbox\plugins |
| macOS | ~/Library/Application Support/IRChatterbox/plugins |
| Linux | ~/.config/IRChatterbox/plugins |
1. Create a file in that folder, for example hello.js:
on("message", function (e) {
if (e.text === "!hello") {
reply(prefix + "Hello, " + e.nick + "!");
}
});
2. Type /reload in IRChatterbox. The server window lists every script that loaded, and any errors with their line numbers.
3. When someone types !hello, you answer [Bot] Hello, bob!.
Every .js and .mrc file in the folder loads at startup and on /reload. Files whose names start with _ are skipped: _example.js and _example.mrc are ready-made examples to copy and rename. All scripts can be switched off at once with Settings → Plugins → Script plugins.
Scripts run in the desktop app (Windows, macOS and Linux).
Two languages
- JavaScript gives you the full API below: events, your own commands, right-click menus, timers, web requests and storage that survives restarts.
- mIRC scripts (
.mrc) run through a built-in interpreter, so most shared mIRC scripts work as they are. What's supported.
Both kinds sit in the same folder and run side by side.
How scripts run
- Sandboxed. Each script runs in its own sandbox. It can't read or write files, start programs or see other scripts' variables. The only way out is the functions listed on this page.
- One thing at a time. A script's handlers run one after another, in order, so you never need locks.
- Time limit. A handler that runs for more than 15 seconds is stopped. Errors appear in the server window as
[yourscript.js] …, and the script keeps running. - Modern JavaScript. ES2015 and later, run by goja: arrow functions,
letandconst, template strings, classes and regular expressions all work. There's norequire,fetchor Node API; use the helpers below. - No bot loops. Start bot replies with
prefix(your bot reply prefix from Settings,[Bot]by default). IRChatterbox's built-in bots never answer lines that start with it. - History is quiet. Messages replayed from a bouncer never trigger scripts.
Events
on("eventName", function (e) { ... });
Every event object has these fields:
| Field | Meaning |
|---|---|
e.server |
The network name from the server editor, e.g. Libera.Chat |
e.serverId |
IRChatterbox's internal id for that server |
e.me |
Your current nick on that network |
e.target |
Where reply() sends to: the channel, or the person in a private chat |
| Event | When | Extra fields |
|---|---|---|
message |
Anyone, including you, sends a normal message | channel, nick, text (formatting removed), raw (with colour codes), self, isChannel, isPM |
action |
Someone else sends a /me action |
same as message |
notice |
A user sends a NOTICE | same as message |
join |
Someone joins a channel | channel, nick, self (it was you) |
part |
Someone leaves a channel | channel, nick, reason, self |
quit |
Someone disconnects | nick, reason, channels (the channels you shared) |
kick |
Someone is kicked | channel, nick (who kicked), victim, reason, self (you were kicked) |
nick |
Someone changes nick | oldNick, newNick, self, channels |
topic |
A topic changes | channel, nick, topic, self |
mode |
Channel modes change | channel, nick, modes (e.g. +o bob) |
invite |
Someone invites you | channel, nick, invited |
connect |
You finish connecting to a network | nick |
disconnect |
You're disconnected | reason |
raw |
Every line from the server (advanced) | command (e.g. PRIVMSG, 001), params (array), nick, prefix, tags |
load |
The script has just been loaded or reloaded | — |
Your own messages arrive as message events with e.self set to true. Return early so your bot doesn't answer itself:
on("message", (e) => {
if (e.self) return;
// ...
});
Commands
Add your own slash commands. They show up in the / autocomplete list.
command("slap", function (e) {
// typed: /slap bob with a trout
// e.args = "bob with a trout", e.argv = ["bob", "with", "a", "trout"]
if (!e.argv.length) return log("usage: /slap nick");
action(e.channel, "slaps " + e.argv[0] + " around a bit with a large trout");
});
The command event has command, args, argv, channel (the window you typed in), server, me and isChannel. Built-in commands such as /join and /kick win over a script command with the same name.
Right-click menus
Add items to IRChatterbox's right-click menus. They appear at the bottom, after a separator.
menu("nicklist", "Slap", function (e) {
action(e.channel, "slaps " + e.nick + " around a bit with a large trout");
});
menu("nicklist,query", "Fun/Hug", function (e) { // "Fun/Hug" makes a Fun submenu
action(e.channel || e.nick, "hugs " + e.nick);
});
menu("message", "Quote", function (e) {
reply("> " + e.nick + ": " + e.text);
});
| Menu | Opens when you right-click | Event has |
|---|---|---|
nicklist |
a nick, in the user list or the chat | nick, channel |
channel |
a channel in the sidebar | channel |
query |
a private chat in the sidebar | nick, channel (the private chat) |
status |
a server in the sidebar | — |
message |
a message in the chat | nick, text, channel |
Every menu event also has menu, server, me and isChannel. reply() answers in the window the menu was opened from. List several menus with commas: menu("nicklist,query", …).
Sending
| Function | What it does |
|---|---|
reply(text) |
Sends to wherever the event happened (a channel or a private chat) |
say(target, text) |
Sends a message to a channel or nick |
action(target, text) |
Sends a /me action |
notice(target, text) |
Sends a NOTICE |
run("/command args") |
Runs any command as if you typed it, e.g. run("/join #test") |
raw("IRC LINE") |
Sends a raw IRC line, e.g. raw("MODE #chan +m") |
Long messages are split automatically, and everything goes through the same flood protection as your own typing. Sending always uses the network the event came from.
Information
| Function | Returns |
|---|---|
me() |
Your current nick |
channels() |
The channels you're in on this network, e.g. ["#linux", "#neowin"] |
users("#chan") |
[{ nick, prefix, away }, …], where prefix is "@", "+", "@+" and so on |
isOp("#chan", nick) |
true if that nick is a channel operator or higher |
stripFormatting(text) |
The text without IRC colour and bold codes |
prefix |
Your bot reply prefix from Settings (a string, not a function) |
Talking to you
| Function | What it does |
|---|---|
log(text) |
Prints [script.js] text in the server window. Only you see it. |
notify(title, body) |
Shows a desktop notification |
Timers
const id = setTimeout(() => reply("5 seconds later"), 5000);
clearTimeout(id);
// every 10 minutes (intervals run at most once a second)
const t = setInterval(() => say("#mychan", "Remember to hydrate 💧"), 10 * 60 * 1000);
clearInterval(t);
A timer remembers where it was created, so reply() inside it goes to the same channel. All of a script's timers are cancelled when it's reloaded.
Storage
Each script gets its own storage that survives restarts:
store.set("count", 5);
store.get("count", 0); // 5 (the second argument is the default when the key is missing)
store.delete("count");
store.keys(); // ["…", …]
Values can be numbers, strings, booleans, arrays or plain objects. They're kept in plugins/data/<script name>.json, which you can open and edit.
Web requests
const html = httpGet("https://example.com"); // the body as a string, "" on error
const data = httpGetJSON("https://api.github.com/repos/phpandrew/IRChatterbox"); // parsed JSON, or null
if (data) reply(prefix + "⭐ " + data.stargazers_count + " stars");
Requests time out after 12 seconds, and responses are capped at 512 KB for text and 2 MB for JSON. For a simple "type !x, fetch a URL, post the result" command you don't need a script: use Settings → Plugins → URL commands.
Helpers
| Function | Returns |
|---|---|
toF(celsius) |
The temperature in Fahrenheit |
toC(fahrenheit) |
The temperature in Celsius |
Examples
Greeter
on("join", (e) => {
if (!e.self && e.channel === "#mychan") {
say(e.channel, `${prefix}Welcome to ${e.channel}, ${e.nick}! 👋`);
}
});
Karma: nick++ and nick--
on("message", (e) => {
const m = e.text.match(/^(\S+)(\+\+|--)$/);
if (!m || m[1].toLowerCase() === e.nick.toLowerCase()) return; // no self-karma
const key = "karma:" + m[1].toLowerCase();
const n = store.get(key, 0) + (m[2] === "++" ? 1 : -1);
store.set(key, n);
reply(`${prefix}${m[1]} now has ${n} karma`);
});
command("karma", (e) => {
const who = (e.argv[0] || me()).toLowerCase();
log(`${who}: ${store.get("karma:" + who, 0)} karma`);
});
Seen
on("message", (e) => {
store.set("seen:" + e.nick.toLowerCase(), { when: Date.now(), where: e.channel, text: e.text });
const m = e.text.match(/^!seen (\S+)/);
if (!m) return;
const s = store.get("seen:" + m[1].toLowerCase(), null);
if (!s) return reply(`${prefix}I haven't seen ${m[1]}.`);
const mins = Math.round((Date.now() - s.when) / 60000);
reply(`${prefix}${m[1]} was last seen ${mins} min ago in ${s.where}: "${s.text}"`);
});
Auto-op your friends
const friends = ["alice", "bob"];
on("join", (e) => {
if (!e.self && friends.includes(e.nick.toLowerCase()) && isOp(e.channel, me())) {
run(`/op ${e.nick}`);
}
});
Rejoin when kicked
on("kick", (e) => {
if (e.self) setTimeout(() => run("/join " + e.channel), 3000);
});
Answer a server numeric
on("raw", (e) => {
if (e.command === "001") log("Registered on " + e.server); // RPL_WELCOME
});
mIRC scripts
Copy a .mrc file into the plugins folder and type /reload. IRChatterbox isn't a full mIRC: it covers the parts most shared scripts use, and skips anything that touches files, programs or windows. The server window lists anything a script uses that was skipped.
alias hello {
if ($1 == $null) { echo -a Usage: /hello nick | return }
msg $chan Hello $1 $+ , from $me!
}
on *:TEXT:!dice:#:msg $chan $nick rolled a $rand(1,6)
on !*:JOIN:#:notice $nick Welcome to $chan $+ , $nick $+ !
Definitions
alias name { … } |
Becomes /name, and $name(args) returns its /return value. alias -l works too. |
on <level>:<EVENT>:…:{ … } |
Events below. Levels: *, 1, me:, ! (not for you), @ (only when you're an op), $ (regex match) |
raw <numeric>:<match>:{ … } |
Server numerics, e.g. raw 332:*: or raw *:*: |
menu nicklist,channel,query,status { … } |
Right-click menu items |
#group on … #group end |
Accepted (the group lines are ignored) |
; comments, /* … */ blocks |
Ignored |
Events: TEXT, ACTION, NOTICE (match the text and #, ?, * or a channel list), JOIN, PART, KICK, TOPIC, INVITE, RAWMODE, INPUT, QUIT, NICK, CONNECT, DISCONNECT, START, LOAD.
TEXT, ACTION and NOTICE run for other people's messages, as in mIRC. Matches use mIRC wildcards (*, ?, &); with the $ level the match is a regex like /^!w(eather)?\s/i.
on INPUT runs on what you type in a channel. /halt or /haltdef stops the line being sent, so a script can rewrite it:
on *:INPUT:#:{ if ($1 == !shout) { say $upper($2-) | halt } }
Commands
- Messages:
/msg,/say,/notice,/describe,/me,/echo [-flags] [#chan] text(shown only to you) - Variables:
/set,/unset(with wildcards like%seen.*),/inc,/dec,/var %a = 1, %b,%x = value(simple maths such as%x = %x + 1works) - Flow:
if/elseif/else,while,break,continue,return,halt,haltdef - Hash tables:
/hmake,/hadd,/hinc,/hdec,/hdel,/hfreeand$hget(table, item) - Timers:
/timer[name] [-m] reps delay command,/timer<name> off,/timers off. As in mIRC, the command is evaluated when it's set and again when it fires; write$!nickto leave an identifier for later. - Everything else goes to IRChatterbox's own commands, so
/join,/part,/kick,/mode,/op,/topic,/away,/rawand the rest work as usual. |separates commands, and[ ]evaluation brackets work (%count. [ $+ [ $nick ] ]).
Identifiers
- Event:
$nick,$chan,$1,$2-,$1-3,$0,$me,$address,$fulladdress,$site,$knick,$newnick,$target,$network,$server,$port - Text:
$len,$upper,$lower,$left,$right,$mid,$pos,$count,$replace,$replacecs,$remove,$str,$strip,$chr,$asc,$+,$+(a,b,c) - Tokens:
$gettok,$numtok,$addtok,$deltok,$remtok,$istok,$findtok - Maths:
$calc,$int,$abs,$round,$rand - Time:
$time,$time(format),$date,$ctime,$ticks,$asctime(ctime, format),$duration - People and channels:
$nick(#chan, N),$nick(#chan, 0),$comchan,$address(nick, type),$mask(address, type) - Other:
$iif,$var,$null,$true,$false,$version
Operators in if and while: ==, ===, !=, <, >, <=, >=, //, \\, isin, isincs, iswm, iswmcs, isnum, isalpha, isalnum, isletter, islower, isupper, ison, isop, ishop, isvoice, isreg, ischan. Put ! in front to negate (!isin), and combine with &&, || and !( … ).
Right-click menus in mIRC scripts
menu nicklist {
Whois:whois $$1
-
Fun
.Slap:me slaps $$1 around a bit with a large trout
.Hug:{
me hugs $$1
inc %hugs
}
$iif($me isop $chan, Op tools)
.Kick:kick $chan $$1
}
nicklistopens on a nick (in the user list or the chat;$1and$snicksare the nick),channelon a channel in the sidebar,queryon a private chat ($1is the nick) andstatuson a server.menu *adds to all four..makes a submenu item and..goes one level deeper.-is a separator.- Labels are worked out when the menu opens, and an item whose label comes out empty is hidden (like
$iifabove). $$1stops the command when there's no value.
Not supported
These are skipped when a script loads, or do nothing when called:
- Dialogs, custom
@windows,menubarmenus,$submenu,ctcpevents and picture windows - Files and INI:
/write,$read,/writeini,$readini,/fopen,$findfile - Programs and DLLs:
/run,/dll,$com - Sockets:
/sockopenand friends (JavaScript scripts havehttpGetfor web requests) /load,/unload,/reloadand/exitfrom inside a script
A script that uses these mostly still loads; only those parts don't run.
Good to know
- Global variables (
%name) are saved toplugins/data/mirc-vars.jsonand survive restarts. Hash tables last until IRChatterbox closes. - Runaway loops stop. A script that runs about 200,000 steps (an endless
while) is stopped, with a message in the server window. - What people say is never run as code, except where you ask for it with a
/timerwhose command includes their text, as in mIRC.
Troubleshooting
- Nothing happens. Type
/reloadand look at the server window. A syntax error shows the file name and line. - "unknown event". Check the spelling against the events table.
- The bot answers itself. Return early when
e.selfis true, or start your replies withprefix. - "event queue full". A handler is blocking, usually a slow
httpGetin a busymessagehandler. Only fetch when a trigger matches. - A script command doesn't run. A built-in command with the same name wins. Pick another name.
Found something the API can't do yet? Open an issue on GitHub.
