Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Beta version #22

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
FROM node:0.10
FROM fntsrlike/node-irc:latest
MAINTAINER Ruoshi Ling <[email protected]>

# Requirment libs
RUN apt-get update && apt-get install -y libicu-dev

# Node_modules Cache
COPY ./package.json /app/package.json
COPY ./README.md /app/README.md
Expand Down
131 changes: 84 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,99 +1,136 @@
# Slack IRC Syncbot
Synchronize messages between [Slack](http://slack.com) and [IRC](https://en.wikipedia.org/wiki/Internet_Relay_Chat).

## Usage
## 1. Usage for node.js

### 1-1. Requirments
- `git`
- `node.js` & `npm`

### 1-2. Steps
```bash
git clone https://github.com/fntsrlike/slack-irc-syncbot.git
cd slack-irc-syncbot
npm install
$ git clone https://github.com/fntsrlike/slack-irc-syncbot.git
$ cd slack-irc-syncbot
$ npm install
```

Write your own configuration file (Refer `config.sample.js`) is a good starting point for building your own. The details can refer Configure part in below.
Refer `config.js.sample` to write your own configuration. Meaning of setting detail could refer the section "Configuration". After create your configuration to project root as `config.js`, execute the command:

```bash
$ node <設定檔名>
```

Save this to a file in the root of the project then run your bot with:
It will execute program. To join IRC channel may need for a while. When finished setup progress, it will display messages as following:

node your-config
```bash
$ node config.js
.............done!
Server running at http://localhost:8080/
```

This will launch the bot in your terminal based on provided configuration.
## 2. Usage for Docker-Compose

## Usage for Docker
This project also support docker. If you have install docker and docker-compose, you can excute project without installing node.js in your local.

This project also support docker. you can clone the project and configure it. BTW, your config file should be named `config.js`.
```shell
$ git clone https://github.com/fntsrlike/slack-irc-syncbot.git
$ cd slack-irc-syncbot
$ cp config.sample.js config.js
$ vim config.js
...
```
### 2-1. Requirements
- `git`
- `docker`
- `docker-compose`

Then build image and run.
```shell
$ docker build --tag="slack-irc-syncbot" ./
...
$ docker run -d -P slack-irc-syncbot
```
### 2-2. Steps

If you don't want to rebuild images after editing config file, just use volume to sync config and restart container.
```shell
$ docker run -d -P -v $PWD/config.js:/app/config.js --name="slackbot" slack-irc-syncbot
$ vim config.js
...
$ docker restart slackbot
After you create your own configuration as `config.js` in project root, edit `docker-compose.yml` to setting arguments of docker, usually we will set volumes and ports. At last, execute command:

```bash
$ docker-compose up -d
```

In addition, if your want to specify expose port, remember to use `-p` argument replace `-P`
`docker` will create image and container to execute program in background.

## 3. Configuration

In thie section, we will explain how to set configuration with `config.js.sample`.

## Configuration
Explain configuration in config.sample.js with comment.
```javascript
'use strict';

var App = require('./lib/app');

// -- Setting form this line

// Basic configuration of IRCBot
// var config = {
// nick: '<IRCBot's nick>',
// username: '<IRCBot's username>',
// password: '<IRCBot's password, option>',
// token: '<Slack API token>',
// incomeUrl: '<Slack Incoming Integrations Income Url',
// outgoingToken: ['<Slack Outgoing Integrations token>'],
// serverPort: 80
// };

var config = {
// Require item
nick: 'slackbot',
username: 'slackbot-username',
token: 'XXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXX',
incomeUrl: 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX',
outgoingToken: 'XXXXXXXXXXXXXXXXXXXXXXXX',
outgoingToken: ['XXXXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXX'],
serverPort: 80
};

// Channels map
// The channels wanna be sync messages.
config.channels = {
'#irc-channel password(optional)': '#slack-channel'
'#<IRC channel> [password, option]': '#<Slack channgel>',
'#sample' : '#general'
};

// Users map
// Index is not nick, but username at IRC. It could be get by `/whois`.
// Value is slack's username.
// To sync nicks and avatar of user
config.users = {
'ircLogin (not nick)': 'slackUser'
'<IRC username(NOT NICK)>': '<Slack username>',
'ircuser': 'slackuser'
};

// Baned list of IRC Nicks. Usually are bots.
config.bannedIRCNicks = [
'<IRC Nick>',
'ircNick'
];

// To filter messages has bad word or dirty word
config.bannedKeywords = [
'keyword'
];

// -- Setting end on this line

App( config ).start();
```

### Requirements
### 3-1. Requirements
- `nick`: IRCbot's nick, it should be unique on IRC Server
- `username`: IRC bot's username
- `token`: Slack's API token
- `incomeUrl`: From Incoming WebHooks of Integrations
- `outgoingToken`: From Outgoing WebHooks of Integrations
- `channels`: Channels map. Decide to sync which IRC chanel to Slack channel
- `users`: Users map. Let messages sync from IRC could dislpay usesname of Slack

### Options
### 3-2. Options
- `server`: IRC server, default is `irc.freenode.com`
- `iconUrl`: Default ICON for messages from IRC to Slack by url. 48*48 size is better
- `iconEmoji`: As iconUrl but by emoji code. It will override by iconUrl
- `serverPort`: The port of web application to get post request from slack. default is 80
- `httpsServerPort`: As `serverPort` but in https connection. default is 443.
- `initializeTimeoutLimit`: Set seconds to be limit time of initialization.
- `listUpdatedPeriod`: Set seconds to update user list

### Flags
### 3-3. Flags
- `isSilent`: Set true to stop IRC bot from speaking into the channel
- `isSystemSilent`: Set true to stop speak any bot's system messages
- `isUsersTracking`: Set true to tracking IRC users' nick. Otherwise, user mapping will be turn off.
- `isAutoTildeAdded`: Set true to add tilde prefix on IRC nicks
- `isShowSlackChannel`: Set true to display channel name of slack on IRC channel
- `isMapName`:
- `isMapAvatar`:
- `isMapName`: Set true to sync nicks.
- `isMapAvatar`: Set true to sync avatar
- `isHttpsConnecttion' Set `true` to turn on https connection.
- `isDisplayInfo' Set true to let index display some public information.

Other config options about IRCBot, can refer [node-irc](https://github.com/martynsmith/node-irc/blob/0.3.x/lib/irc.js)
138 changes: 138 additions & 0 deletions README_zh-tw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Slack IRC Syncbot

同步 [Slack](http://slack.com)、[IRC](https://en.wikipedia.org/wiki/Internet_Relay_Chat) 兩者之間的訊息。

## 1. 直接使用 node.js 執行

### 1-1. 前置需求
- `git`
- `node.js` & `npm`

### 1-2. 步驟

```bash
$ git clone https://github.com/fntsrlike/slack-irc-syncbot.git
$ cd slack-irc-syncbot
$ npm install
```

參考 `config.js.sample` 編寫您所需要的設定檔,設定值詳細的意義請參考下面的「設定」章節。然後將設定值儲存至專案根目錄(檔名通常是 `config.js`)。然後輸入下面的指令:

$ node <設定檔名>

之後就會運行機器人,掛載 IRC 頻道可能會需要一段時間,當完成時,即會顯示如下的訊息:

```
$ node config.js
.............done!
Server running at http://localhost:8080/
```

## 2. 透過 Docker-Compose 執行

這個專案是支援 `Docker` 的,只要您的電腦有 `Docker` 和 `docker-compose`,您就不用刻意去安裝 `node.js`。

### 2-1. 前置需求
- `git`
- `docker`
- `docker-compose`

### 2-2. 步驟

在你修改玩設定檔後,可以在修改 `docker-compose.yml` 的 `volumes` 和 `ports` 去決定有使用的設定檔或輸出的 port。然後就可以執行下列指令

```shell
$ docker-compose up -d
```

`docker-compose` 就會去建立該 `image` 然後自動在背景執行程式。


## 3. 設定檔詳解

在這個章節我們會透過講解 `config.js.sample` 裡面項目,幫助您要如何撰寫您專屬的 `config.js`。

```javascript
'use strict';

var App = require('./lib/app');

// -- 從這邊開始進行設定

// 關於機器人的基本設定值
// var config = {
// nick: '<IRC 機器人暱稱>',
// username: '<IRC 機器人帳號>',
// password: '<IRC 機器人密碼,選填>',
// token: '<Slack API token>',
// incomeUrl: '<Slack Incoming Integrations Income Url',
// outgoingToken: ['<Slack Outgoing Integrations token>'],
// serverPort: 80
// };

var config = {
nick: 'slackbot',
username: 'slackbot-username',
token: 'XXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXX',
incomeUrl: 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX',
outgoingToken: ['XXXXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXX'],
serverPort: 80
};

// 機器人要同步的頻道,前後分別為 IRC Server 和 Slack 的 Channel 名稱。
config.channels = {
'#<IRC 頻道名稱> [頻道密碼、選填]': '#<Slack 頻道名稱>',
'#sample' : '#general'
};

// 使用者暱稱、頭像同步,前後分別為 IRC Server 和 Slack 的 username。
config.users = {
'<IRC 帳號(非暱稱)>': '<Slack 帳號>',
'ircuser': 'slackuser'
};

// IRC 暱稱黑名單
config.bannedIRCNicks = [
'<IRC 暱稱>',
'ircNick'
];

// 關鍵字黑名單,擁有以下關鍵字的訊息將會被篩選掉。
config.bannedKeywords = [
'keyword'
];

// -- 到此行結束設定。

App( config ).start();
```

### 3-1. 必填的屬性
- `nick`: IRC 帳號的暱稱。每個暱稱在 IRC Server 都是不可重複的。若是重複,程式會自動加上數字遞疊。
- `username`: IRC 帳號的使用者名稱。
- `token`: Slack 的 API token。
- `incomeUrl`: Slack Incoming WebHooks Integrations 提供的網址。
- `outgoingToken`: Slack Outgoing WebHooks Integrations 提供的 `token`。若同步多個頻道,則會有多個 token,以 Array 的形式儲存。

### 3-2. 選填的屬性
#### 3-2-1. 屬性
- `server`: IRC server 位址,預設是 `irc.freenode.com`。
- `iconUrl`: IRC 同步到 Slack 訊息顯示預設頭像的網址。48 * 48 的長寬是比較推薦的。
- `iconEmoji`: 同上,但是是輸入 emoji code。效果會被 `iconUrl` 覆蓋。
- `serverPort`: 接收 Slack 訊息用的網頁所使用的 port。預設是 `80` port。
- `httpsServerPort`: 同上,但是在 https 的連線狀況。預設是 `443` port。
- `initializeTimeoutLimit`: 設定初始化時,判定超時、失敗的秒數。
- `listUpdatedPeriod`: 設定定期更新使用者名單的秒數。

#### 3-2-2. 開關
- `isSilent`: 設成 `true` 去對機器人在 IRC 上靜音。預設是 `false`。
- `isSystemSilent`: 同上。不過特別針對系統訊息。
- `isUsersTracking`: 設成 `true` 去追蹤 IRC 上使用者的暱稱。預設是 `true`。
- `isAutoTildeAdded`: 設成 `true` 去讓雙平台使用者名稱綁定的 IRC 名稱前,加上 `~` 作為前綴。預設是 `false`。
- `isShowSlackChannel`: 設成 `true` 讓同步到 Slack 訊息的使用者名稱前加上 IRC Channel 的名稱。預設是 `false`,
- `isMapName`: 設成 `true` 決定是否開啟暱稱同步的功能。預設為 `true`。
- `isMapAvatar`:設成 `true` 決定是否開啟頭像同步的功能。預設為 `true`。
- `isHttpsConnecttion' 設成 `true` 去開啟 https 連線服務。
- `isDisplayInfo' 設成 `true` 讓首頁顯示可公開資訊。預設為 `true`。

其他關於程式的設定,可以參考 [node-irc](https://github.com/martynsmith/node-irc/blob/0.3.x/lib/irc.js)。
12 changes: 10 additions & 2 deletions config.sample.js → config.js.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var config = {
username: 'slackbot-username',
token: 'XXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXX',
incomeUrl: 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX',
outgoingToken: 'XXXXXXXXXXXXXXXXXXXXXXXX',
outgoingToken: ['XXXXXXXXXXXXXXXXXXXXXXXX'],
serverPort: 80
};

Expand All @@ -16,7 +16,15 @@ config.channels = {
};

config.users = {
'ircLogin (not nick)': 'slackUser'
'ircAccount': 'slackUser'
};

config.bannedIRCNicks = [
'ircNick'
];

config.bannedKeywords = [
// 'keyword'
];

App( config ).start();
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app:
build: ./
environment:
- TZ=Asia/Taipei
volumes:
- ./config.js:/app/config.js
ports:
- "8080:80"
Loading