Skip to content

Scripting

Велимир Мајсторов edited this page Feb 13, 2026 · 1 revision

Scripting

AndroidIRCX includes a built-in JavaScript scripting engine.

This page follows the in-app Scripting Help content and documents hooks, API, examples, and usage tips.

Quick Start

Scripts are plain JavaScript modules. Export hooks to react to events:

module.exports = {
  onConnect: (networkId) => { /* ... */ },
  onDisconnect: (networkId, reason) => { /* ... */ },
  onMessage: (msg) => { /* msg.channel, msg.from, msg.text */ },
  onNotice: (msg) => { /* notice messages */ },
  onJoin: (channel, nick, msg) => { /* ... */ },
  onPart: (channel, nick, reason, msg) => { /* ... */ },
  onQuit: (nick, reason, msg) => { /* ... */ },
  onNickChange: (oldNick, newNick, msg) => { /* ... */ },
  onKick: (channel, kickedNick, kickerNick, reason, msg) => { /* ... */ },
  onMode: (channel, setterNick, mode, target, msg) => { /* ... */ },
  onTopic: (channel, topic, setterNick, msg) => { /* ... */ },
  onInvite: (channel, inviterNick, msg) => { /* ... */ },
  onCTCP: (type, from, text, msg) => { /* ... */ },
  onRaw: (line, direction, msg) => { /* return modified line or { cancel: true } */ },
  onCommand: (text, ctx) => { /* return newText or { cancel: true } */ },
  onTimer: (name) => { /* timer fired */ },
};

API

Available Functions

  • api.log(text) - log to script log buffer
  • api.sendMessage(channel, text, networkId?)
  • api.sendCommand(command, networkId?)
  • api.sendNotice(target, text, networkId?)
  • api.sendCTCP(target, type, params?, networkId?)
  • api.getChannelUsers(channel, networkId?) - returns string[]
  • api.getChannels(networkId?) - returns string[]
  • api.setTimer(name, delayMs, repeat?) - set timer
  • api.clearTimer(name) - clear timer
  • api.getNetworkId() - current network ID
  • api.isConnected(networkId?) - check connection
  • api.userNick - current nick
  • api.getConfig() - script config JSON

Hooks

Connection Events

  • onConnect(networkId) - when connected
  • onDisconnect(networkId, reason?) - when disconnected

Message Events

  • onMessage(msg) - channel/query messages
  • onNotice(msg) - notice messages
  • onCTCP(type, from, text, msg) - CTCP requests

Channel Events

  • onJoin(channel, nick, msg) - user joined
  • onPart(channel, nick, reason, msg) - user parted
  • onQuit(nick, reason, msg) - user quit
  • onNickChange(oldNick, newNick, msg) - nick changed
  • onKick(channel, kickedNick, kickerNick, reason, msg) - user kicked
  • onMode(channel, setterNick, mode, target?, msg) - mode changed
  • onTopic(channel, topic, setterNick, msg) - topic changed
  • onInvite(channel, inviterNick, msg) - channel invite

Other Events

  • onRaw(line, direction, msg?) - raw IRC line (in/out)
  • onCommand(text, ctx) - outgoing command
  • onTimer(name) - timer fired

Examples

Auto-op

module.exports = {
  onJoin: (channel, nick, msg) => {
    if (nick === api.userNick) return;
    api.sendCommand('MODE ' + channel + ' +o ' + nick);
  },
};

Welcome

module.exports = {
  onJoin: (channel, nick) => {
    api.sendMessage(channel, 'Welcome, ' + nick + '!');
  },
};

Alias (/hello)

module.exports = {
  onCommand: (text) => {
    if (text.startsWith('/hello')) return '/say Hello there!';
    return text;
  },
};

CTCP Responder

module.exports = {
  onCTCP: (type, from, text) => {
    if (type === 'VERSION') {
      api.sendCTCP(from, 'VERSION', 'AndroidIRCX');
    }
  },
};

Timer Example

module.exports = {
  onConnect: () => {
    api.setTimer('periodic', 60000, true); // every 60s
  },
  onTimer: (name) => {
    if (name === 'periodic') {
      api.log('Timer fired!');
    }
  },
  onDisconnect: () => {
    api.clearTimer('periodic');
  },
};

Kick Protection

module.exports = {
  onKick: (channel, kickedNick, kickerNick, reason) => {
    if (kickedNick === api.userNick) {
      api.sendCommand('JOIN ' + channel);
    }
  },
};

Tips

  • Scripts are disabled by default; enable each one.
  • Use Lint to catch syntax errors.
  • Enable logging to see script output/errors in the log tab.
  • onCommand can cancel send by returning { cancel: true }.
  • onRaw can modify or cancel raw IRC lines.
  • Use timers for periodic tasks; clear them on disconnect.
  • Check api.isConnected() before sending commands.

Managing Scripts In App

  1. Open Settings.
  2. Go to Scripting & Ads.
  3. Open Scripts (Scripting Time & No-Ads).
  4. Add/edit scripts and enable them.
  5. Use Script Logs to inspect output and errors.

Related

Clone this wiki locally