add subsitution regexp for chat messages (currently unused)

This commit is contained in:
HF 2020-04-28 02:30:13 +02:00
parent 29129b98f7
commit 1ca9932b84

View File

@ -18,26 +18,19 @@ class ChatProvider {
this.history = []; this.history = [];
this.filters = [ this.filters = [
{ {
regexp: /ADMIN/g, regexp: /ADMIN/gi,
matches: 2, matches: 2,
}, },
{ {
regexp: /FUCK/g, regexp: /FUCK/gi,
matches: 2, matches: 2,
}, },
{ {
regexp: /admin/g, regexp: /FACK/gi,
matches: 3,
},
{
regexp: /fuck/g,
matches: 3,
},
{
regexp: /FACK/g,
matches: 3, matches: 3,
}, },
]; ];
this.substitutes = [];
} }
addMessage(name, message) { addMessage(name, message) {
@ -48,7 +41,7 @@ class ChatProvider {
} }
async sendMessage(user, message) { async sendMessage(user, message) {
if (message.length > 300) { if (message.length > 200) {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
return 'You can\'t send a message this long :('; return 'You can\'t send a message this long :(';
} }
@ -63,7 +56,7 @@ class ChatProvider {
} }
if (message === message.toUpperCase()) { if (message === message.toUpperCase()) {
return null; return 'Stop shouting';
} }
for (let i = 0; i < this.filters.length; i += 1) { for (let i = 0; i < this.filters.length; i += 1) {
@ -75,6 +68,11 @@ class ChatProvider {
} }
} }
for (let i = 0; i < this.substitutes.length; i += 1) {
const subsitute = this.substitutes[i];
message = message.replace(subsitute.regexp, subsitute.replace);
}
if (user.isAdmin() && message.charAt(0) === '/') { if (user.isAdmin() && message.charAt(0) === '/') {
// admin commands // admin commands
const cmd = message.split(' '); const cmd = message.split(' ');