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

Commit

Permalink
Add index display public info feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruoshi.Ling committed Aug 29, 2015
1 parent e07b8d6 commit b485576
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ App( config ).start();
- `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)
1 change: 1 addition & 0 deletions README_zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@ App( config ).start();
- `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)
38 changes: 37 additions & 1 deletion lib/slack-to-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var SlackToIRC = function(config) {
showSlackChannel: false,
serverPort: 80,
httpsServerPort: 443,
isDisplayInfo: true,
isHttpsConnecttion: false
});

Expand Down Expand Up @@ -55,7 +56,7 @@ SlackToIRC.prototype._server = function() {
if (req.method === 'POST') {
this._requestHandler(req, res);
} else {
res.end('Recieved request (not post).');
res.end(this.config.isDisplayInfo ? this._getIndexHtml() : 'Recieved request (not post).');
}
}.bind(this));

Expand Down Expand Up @@ -117,4 +118,39 @@ SlackToIRC.prototype._decodeMessage = function(text) {
.decodeAngel().encodeAmpersand().toString();
};

SlackToIRC.prototype._getIndexHtml = function() {
var html = '';

html += '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">'
+ '<title>Slack IRC Messages Syncbot</title>'
+ '<style>table, tr, td, th{border: 1px solid black; border-spacing: 0;} td, th{padding:.4em;}</style>'
+ '</head><body>'
+ '<h1>Slack IRC Messages Syncbot</h1>'
+ '<h2>Sync Channels</h2>'
+ '<table>'
+ '<thead><tr><th>IRC Channel</th><th>Slack Channel</th></tr></thead>'
+ '<tbody>' + this._objectToHtmlTr(this.config.channels) + '</tbody>'
+ '</table>'
+ '<h2>Binding Users</h2>'
+ '<table>'
+ '<thead><tr><th>IRC Acoount</th><th>Slack Account</th></tr></thead>'
+ '<tbody>' + this._objectToHtmlTr(this.config.users) + '</tbody>'
+ '</table>'
+ '<h2>Banned IRC Nicks</h2><p>' + this.config.bannedIRCNicks.join(', ') + '</p>'
+ '<p><a href="https://github.com/fntsrlike/slack-irc-syncbot">[Github]</a><p>'
+ '</body></html>';

return html;
}

SlackToIRC.prototype._objectToHtmlTr = function(object) {
var html = '';

for (var key in object) {
html += '<tr><td>' + key + '</td><td>' + object[key] + '</td></tr>';
}

return html;
}

module.exports = SlackToIRC;

0 comments on commit b485576

Please sign in to comment.