kana is our implementation of an IRC bot for the AnimeBytes IRC server.
kana listens for following IRC events:
PRIVMSG {:nick} :enter <channels> <username> <key>
PRIVMSG {:nick} :identify <username> <key>
INVITE
Following commands are accessible:
- !user [username]
Additionally:
- Will listen on every channel it joins and resolve
<title>
for links posted - Will listen for raw ECHO commands and forward them to specified channels
- Will listen for Gitea style webhook on
/webhook/gitea
. Suppported events are:push
(maximum of 10 commits will be echo'ed in channel)create
delete
- Will listen for Drone CI webhook on
/webhook/drone
. Supported events are:created
updated
success
killed
failure
error
- Sends
WHO
to#animebytes
every 5 minutes and transmits list of users back to remote endpoint at/api/irc/notifier
kana requires NodeJS v20.9 or later and Yarn package manager
yarn && yarn build
node dist/index.js
Example systemd unit file:
[Unit]
Description=kana
After=network.target
[Service]
EnvironmentFile=/opt/kana/.env
WorkingDirectory=/opt/kana
ExecStart=/usr/bin/node dist/index.js
RestartSec=30s
Restart=always
User=kana
[Install]
WantedBy=default.target
Alternatively, you can also build/use a docker container instead:
docker build . -t kana
docker run -d --restart=always --env-file=.env --user 1001:1001 -v ${PWD}/channels.json:/app/channels.json kana
Configuration is done using environment variables:
IRC_SERVER
- IRC server to connect toIRC_PORT
- IRC port to connect toIRC_USE_SSL
- Set to 'true' if the irc server is using sslIRC_VERIFY_SSL
- Set to 'false' if you wish to ignore the validity of the SSL certificate on the IRC serverIRC_NICK
- Nickname to use when connecting to IRC serverIRC_REALNAME
- Realname to use when connecting to IRC serverIRC_USERNAME
- Username to use when connecting to IRC serverIRC_IGNORE_USERS
- List of user nicks to ignore messages from, delimited by,
OPER_USERNAME
- Oper usernameOPER_PASS
- Oper passwordIGNORE_OPER_FAILURE
- Set to 'true' to ignore the requirement of a successful OPER command (for testing and development)SITE_API_KEY
- API key to authenticate with site, used for sending back list of online users, fetching user stats via!user
and!dess
HTTP_BIND
- Hostname on which bot will expose Express router, used by Gitea and DroneCI webhookHTTP_PORT
- Port on which bot will expose Express router, used by Gitea and DroneCI webhookGIT_WEBHOOK
- Secret key to authenticate Gitea and DroneCI webhook endpointGIT_CHANNEL
- Channel used to echo messages received by Gitea webhookECHO_BIND
- Hostname on which bot will listen for raw ECHO commandsECHO_PORT
- Port on which bot will listen for raw ECHO commandsECHO_AUTH_KEY
- Secret key to authenticate Echo requestsLOG_LEVEL
- One of the stringstrace
,debug
,info
,warn
, orerror
to use as the log level
Additionally, channels.json
file is used by bot to dynamically store list of channels it knows about:
{
"$id": "channels.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"join": {
"description": "What command should bot use to join channel; setting auto (default) will try JOIN followed by SAJOIN",
"type": "string",
"enum": ["auto", "join", "sajoin"]
},
"persist": {
"description": "Mark channel as persistent; bot wil retry this channel on failure instead of removing it from list",
"type": "boolean"
}
}
}
}
You can pre-populate that file with list of channels that you want bot to always be on by creating new entry and
setting its persistent
property to true
.