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

Commit 29cfffe

Browse files
author
Ruoshi.Ling
committed
Add banned keywords feature
1 parent b485576 commit 29cfffe

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var config = {
7878
serverPort: 80
7979
};
8080

81-
// The channels wanna be sync messages.
81+
// The channels wanna be sync messages.
8282
config.channels = {
8383
'#<IRC channel> [password, option]': '#<Slack channgel>',
8484
'#sample' : '#general'
@@ -90,12 +90,17 @@ config.users = {
9090
'ircuser': 'slackuser'
9191
};
9292

93-
// Baned list of IRC Nicks
93+
// Baned list of IRC Nicks. Usually are bots.
9494
config.bannedIRCNicks = [
9595
'<IRC Nick>',
9696
'ircNick'
9797
];
9898

99+
// To filter messages has bad word or dirty word
100+
config.bannedKeywords = [
101+
'keyword'
102+
];
103+
99104
// -- Setting end on this line
100105

101106
App( config ).start();

README_zh-tw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ config.bannedIRCNicks = [
9797
'ircNick'
9898
];
9999

100+
// 關鍵字黑名單,擁有以下關鍵字的訊息將會被篩選掉。
101+
config.bannedKeywords = [
102+
'keyword'
103+
];
104+
100105
// -- 到此行結束設定。
101106

102107
App( config ).start();

config.js.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ config.bannedIRCNicks = [
2323
'ircNick'
2424
];
2525

26+
config.bannedKeywords = [
27+
// 'keyword'
28+
];
29+
2630
App( config ).start();

lib/irc-to-slack.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var IrcToSlack = function(config) {
1010
}
1111

1212
this.config = _.defaults(config, {
13-
'bannedIRCNicks': []
13+
'bannedIRCNicks': [],
14+
'bannedKeywords': []
1415
});
1516

1617
return this;
@@ -29,11 +30,18 @@ IrcToSlack.prototype._sentToSlack = function(type, from, to, message) {
2930
var avatars = this.config.avatarMap;
3031
var hasAvatar = false;
3132
var isNickExist = !!this.nameMap.getSlackNameByIrcNick(from);
33+
var bannedKeywords = this.config.bannedKeywords;
3234

3335
if (_.contains(this.config.bannedIRCNicks, username)) {
3436
return;
3537
}
3638

39+
for (var i=0, len=bannedKeywords.length; i < len; i++) {
40+
if (message.toLowerCase().indexOf(bannedKeywords[i].toLowerCase()) > -1) {
41+
return;
42+
}
43+
}
44+
3745
if (this.config.isMapName && isNickExist) {
3846
username = this.nameMap.getSlackNameByIrcNick(from);
3947
hasAvatar = typeof avatars[username] !== 'undefined';

0 commit comments

Comments
 (0)