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

Commit 60f2b7a

Browse files
author
Ruoshi.Ling
committed
Add index display public info feature
1 parent e07b8d6 commit 60f2b7a

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README_zh-tw.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,6 @@ App( config ).start();
128128
- `isMapName`: 設成 `true` 決定是否開啟暱稱同步的功能。預設為 `true`
129129
- `isMapAvatar`:設成 `true` 決定是否開啟頭像同步的功能。預設為 `true`
130130
- `isHttpsConnecttion' 設成 `true` 去開啟 https 連線服務。
131+
- `isDisplayInfo' 設成 `true` 讓首頁顯示可公開資訊。預設為 `true`。
131132

132133
其他關於程式的設定,可以參考 [node-irc](https://github.com/martynsmith/node-irc/blob/0.3.x/lib/irc.js)

lib/slack-to-irc.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var SlackToIRC = function(config) {
1717
showSlackChannel: false,
1818
serverPort: 80,
1919
httpsServerPort: 443,
20+
isDisplayInfo: true,
2021
isHttpsConnecttion: false
2122
});
2223

@@ -55,7 +56,7 @@ SlackToIRC.prototype._server = function() {
5556
if (req.method === 'POST') {
5657
this._requestHandler(req, res);
5758
} else {
58-
res.end('Recieved request (not post).');
59+
res.end(this.config.isDisplayInfo ? this._getIndexHtml() : 'Recieved request (not post).');
5960
}
6061
}.bind(this));
6162

@@ -117,4 +118,39 @@ SlackToIRC.prototype._decodeMessage = function(text) {
117118
.decodeAngel().encodeAmpersand().toString();
118119
};
119120

121+
SlackToIRC.prototype._getIndexHtml = function() {
122+
var html = '';
123+
124+
html += '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">'
125+
+ '<title>Slack IRC Messages Syncbot</title>'
126+
+ '<style>table, tr, td, th{border: 1px solid black; border-spacing: 0;} td, th{padding:.4em;}</style>'
127+
+ '</head><body>'
128+
+ '<h1>Slack IRC Messages Syncbot</h1>'
129+
+ '<h2>Sync Channels</h2>'
130+
+ '<table>'
131+
+ '<thead><tr><th>IRC Channel</th><th>Slack Channel</th></tr></thead>'
132+
+ '<tbody>' + this._objectToHtmlTr(this.config.channels) + '</tbody>'
133+
+ '</table>'
134+
+ '<h2>Binding Users</h2>'
135+
+ '<table>'
136+
+ '<thead><tr><th>IRC Acoount</th><th>Slack Account</th></tr></thead>'
137+
+ '<tbody>' + this._objectToHtmlTr(this.config.users) + '</tbody>'
138+
+ '</table>'
139+
+ '<h2>Banned IRC Nicks</h2><p>' + this.config.bannedIRCNicks.join(', ') + '</p>'
140+
+ '<p><a href="https://github.com/fntsrlike/slack-irc-syncbot">[Github]</a><p>'
141+
+ '</body></html>';
142+
143+
return html;
144+
}
145+
146+
SlackToIRC.prototype._objectToHtmlTr = function(object) {
147+
var html = '';
148+
149+
for (var key in object) {
150+
html += '<tr><td>' + key + '</td><td>' + object[key] + '</td></tr>';
151+
}
152+
153+
return html;
154+
}
155+
120156
module.exports = SlackToIRC;

0 commit comments

Comments
 (0)