-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBadwords.js
More file actions
191 lines (175 loc) · 6.27 KB
/
Badwords.js
File metadata and controls
191 lines (175 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
var playerList = {};
var playerListArray = [];
var badwords = [/[a4@][s$5][s$5]h[o0][l1][e€]+/, /[bß][a4@]rm[iy7]+/, /[bß][a4@][s$5][t₺][a4@]rd+/, /[bß][ıi1][t₺][cç¢]h+/, /[c¢]un[t₺]+/, /f[uü][cç¢]k+/, /[l1]m[a4@][o0]+/, /[l1]mf[a4@][o0]+/, /pu[s5$][s5$][y7]+/, /r[e€][t₺][a4@]rd+/, /[s$5][t₺]fu+/, /wh[o0]r[e€]+/, /w[t₺]f+/];
var roomObject = {
limits: {
Chat: {
Badwords: 2
}
},
maxPlayers: 12,
name: "Bad words",
noPlayer: true,
public: true,
timeout: {
Chat: {
Badwords: 600000
}
}
};
var colors = {
Chat: {
Admin: {
Badwords: 0xFF8000,
Muted: 0xFFFF00
},
Badwords: {
Mute: 0xFF0000,
Unmute: 0x00FF00,
},
Mute: {
Still: 0xFFFF00
},
Player: [0xFFFFFF, 0xFFDB72]
},
Join: {
Muted: 0xFFFF00,
Welcome: 0xFFFFFF
},
};
var fonts = {
Chat: {
Admin: {
Badwords: "bold",
Muted: "bold"
},
Badwords: {
Mute: "bold",
Unmute: "normal",
},
Mute: {
Still: "bold"
},
Player: ["normal", "bold"]
},
Join: {
Muted: "bold",
Welcome: "normal"
},
};
var sounds = {
Chat: {
Admin: {
Badwords: 2,
Muted: 1
},
Badwords: {
Mute: 2,
Unmute: 1,
},
Mute: {
Still: 2
},
Player: [1, 1]
},
Join: {
Muted: 2,
Welcome: 1
}
};
var messages = {
Chat: {
Badwords: {
Kick: "You were banned for keeping using bad words.",
Mute: `was muted for ${roomObject.timeout.Chat.Badwords / 60000 == 1 ? roomObject.timeout.Chat.Badwords / 60000 + " minute. A further attempt will result in ban!" : roomObject.timeout.Chat.Badwords / 60000 + " minutes. A further attempt will result in ban!"}`,
Unmute: "is now unmuted!"
},
Mute: {
Still: "You are still muted! Only the administration can see your messages."
}
},
Join: {
Badwords: "You were banned due to joining the room with bad name.",
Blacklisted: "You are banned forever!",
Muted: "You have an active mute punishment so you cannot talk before your punishment ends.",
Welcome: "Welcome!"
}
};
var kickTypes = {
Chat: {
Badwords: true
},
Join: {
Badwords: true,
Blacklisted: true
}
};
var room = HBInit({ roomName: roomObject.name, noPlayer: roomObject.noPlayer, public: roomObject.public, maxPlayers: roomObject.maxPlayers });
function getPreviousAccounts(player) {
return playerListArray.length > 0 && playerListArray.filter(p => p.auth == player.auth || p.conn == player.conn);
}
function isBadword(str) {
return badwords.filter(b => str.match(b)).length > 0;
}
room.onPlayerChat = function (player, message) {
var administrators = room.getPlayerList().filter(p => p.admin == true);
if (isBadword(message) == true) {
playerList[player.name].badwords++;
if (playerList[player.name].badwords < roomObject.limits.Chat.Badwords) {
if (playerList[player.name].muted == false) {
var name = player.name;
administrators.forEach(p => {
room.sendAnnouncement(`${player.name}: ${message}`, p.id, colors.Chat.Admin.Badwords, fonts.Chat.Admin.Badwords, sounds.Chat.Admin.Badwords);
});
room.sendAnnouncement(`${name} ${messages.Chat.Badwords.Mute}`, null, colors.Chat.Badwords.Mute, fonts.Chat.Badwords.Mute, sounds.Chat.Badwords.Mute);
playerList[name].muted = true;
setTimeout(function () {
if (playerList[name].muted == true) {
playerList[name].muted = false;
room.sendAnnouncement(`${player.name} ${messages.Chat.Badwords.Unmute}`, null, colors.Chat.Badwords.Unmute, fonts.Chat.Badwords.Unmute, sounds.Chat.Badwords.Unmute);
}
}, roomObject.timeout.Chat.Badwords);
}
return false;
}
else {
room.kickPlayer(player.id, `${messages.Chat.Badwords.Kick}`, kickTypes.Chat.Badwords);
return false;
}
}
if (playerList[player.name].muted == true) {
room.sendAnnouncement(`${messages.Chat.Mute.Still} (${message})`, player.id, colors.Chat.Mute.Still, fonts.Chat.Mute.Still, sounds.Chat.Mute.Still);
administrators.forEach(p => {
room.sendAnnouncement(`${player.name}: ${message}`, p.id, colors.Chat.Admin.Muted, fonts.Chat.Admin.Muted, sounds.Chat.Admin.Muted);
});
return false;
}
else if (playerList[player.name].muted == false) {
room.sendAnnouncement(`${player.name}: ${message}`, null, colors.Chat.Player[Number(player.admin)], fonts.Chat.Player[Number(player.admin)], sounds.Chat.Player[Number(player.admin)]);
return false;
}
}
room.onPlayerJoin = function (player) {
if (isBadword(player.name) == true) {
room.kickPlayer(player.id, `${messages.Join.Badwords}`, kickTypes.Join.Badwords);
}
else {
if (playerList[player.name] == undefined) {
playerList[player.name] = { name: player.name, auth: player.auth, conn: player.conn, muted: false, badwords: 0 };
}
var accounts = getPreviousAccounts(player);
if (accounts.length > 0) {
var blacklisted = accounts.filter(a => a.badwords >= roomObject.limits.Chat.Badwords);
var muted = accounts.filter(a => a.muted == true);
if (blacklisted.length > 0) {
room.kickPlayer(player.id, `${messages.Join.Blacklisted}`, kickTypes.Join.Blacklisted);
}
else if (muted.length > 0) {
room.sendAnnouncement(`${messages.Join.Muted}`, player.id, colors.Join.Muted, fonts.Join.Muted, sounds.Join.Muted);
playerList[player.name].muted = true;
}
}
playerListArray.push(playerList[player.name]);
room.sendAnnouncement(`${messages.Join.Welcome}`, player.id, colors.Join.Welcome, fonts.Join.Welcome, sounds.Join.Welcome);
}
}