Skip to content

Commit

Permalink
system/moderation: Fix incorrect timeout messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Apr 5, 2018
1 parent 72d2078 commit 9124f5b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 53 deletions.
10 changes: 3 additions & 7 deletions libs/commons.js
Expand Up @@ -132,13 +132,9 @@ Commons.prototype.sendMessage = async function (message, sender, attr) {
return true
}

Commons.prototype.timeout = function (username, reason, timeout, silent) {
if (global.configuration.getValue('moderationAnnounceTimeouts')) {
if (!silent) process.send({type: 'say', sender: username, message: '$sender, ' + reason[0].toLowerCase() + reason.substring(1)})
process.send({type: 'timeout', username: username, timeout: timeout, reason: reason})
} else {
process.send({type: 'timeout', username: username, timeout: timeout, reason: reason})
}
Commons.prototype.timeout = function (username, reason, timeout) {
if (cluster.isMaster) global.client.timeout(config.settings.broadcaster_username, username, timeout, reason)
else process.send({type: 'timeout', username: username, timeout: timeout, reason: reason})
}

Commons.prototype.getOwner = function () {
Expand Down
27 changes: 14 additions & 13 deletions libs/systems/moderation.js
Expand Up @@ -118,27 +118,28 @@ class Moderation {
if (warningsAllowed === 0) {
msg = await new Message(msg.replace(/\$count/g, -1)).parse()
log.timeout(`${sender.username} [${type}] ${time}s timeout | ${text}`)
global.commons.timeout(sender.username, msg, time, silent)
global.commons.timeout(sender.username, msg, time)
return
}

if (_.filter(warnings, (o) => o.username === sender.username).length >= warningsAllowed) {
const isWarningCountAboveThreshold = _.filter(warnings, (o) => o.username === sender.username).length >= warningsAllowed
if (isWarningCountAboveThreshold) {
msg = await new Message(warning.replace(/\$count/g, parseInt(warningsAllowed, 10) - warnings.length)).parse()
log.timeout(`${sender.username} [${type}] ${time}s timeout | ${text}`)
global.commons.timeout(sender.username, msg, time)
await global.db.engine.remove('moderation.warnings', { username: sender.username })
return
}

await global.db.engine.insert('moderation.warnings', { username: sender.username, timestamp: _.now() })
warning = await new Message(warning.replace(/\$count/g, parseInt(warningsAllowed, 10) - warnings.length)).parse()
if (warningsTimeout) {
log.timeout(`${sender.username} [${type}] ${time}s timeout | ${text}`)
global.commons.timeout(sender.username, warning, 1, silent)
}
} else {
await global.db.engine.insert('moderation.warnings', { username: sender.username, timestamp: _.now() })
const warningsLeft = parseInt(warningsAllowed, 10) - warnings.length
warning = await new Message(warning.replace(/\$count/g, warningsLeft)).parse()
if (warningsTimeout) {
log.timeout(`${sender.username} [${type}] 1s timeout, warnings left ${warningsLeft} | ${text}`)
global.commons.timeout(sender.username, warning, 1)
}

if (announceTimeouts && !silent) {
global.commons.sendMessage('$sender, ' + warning, sender)
if (announceTimeouts && !silent) {
global.commons.sendMessage('$sender, ' + warning, sender)
}
}

// cleanup warnings
Expand Down
32 changes: 16 additions & 16 deletions locales/cs.json
Expand Up @@ -1104,22 +1104,22 @@
"moderation": {
"user-have-link-permit": "Uzivatel $username muze nyni postnout $count $link do chatu",
"permit-parse-failed": "{core.command-parse} !permit [username]",
"user-is-warned-about-links": "Nejsou povoleny linky, pozadej o !permit (if $count>-1|[zbyva $count varovani])",
"user-is-warned-about-symbols": "Prilisne pouzivani symbolu neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-is-warned-about-long-message": "Tva zprava je prilis dlouha (if $count>-1|[zbyva $count varovani])",
"user-is-warned-about-caps": "Prilisne pouzivani velkych pismen neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-is-warned-about-spam": "Spamovani neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-is-warned-about-color": "Pouzivani /me neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-is-warned-about-emotes": "Zadne spamovani smajlikama! (if $count>-1|[zbyva $count varovani])",
"user-is-warned-about-blacklist": "Zadne zakazane slova (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-links": "Nejsou povoleny linky, pozadej o !permit (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-symbols": "Prilisne pouzivani symbolu neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-long-message": "Tva zprava je prilis dlouha (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-caps": "Prilisne pouzivani velkych pismen neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-spam": "Spamovani neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-color": "Pouzivani /me neni povoleno (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-emotes": "Zadne spamovani smajlikama! (if $count>-1|[zbyva $count varovani])",
"user-have-timeout-for-blacklist": "Zadne zakazane slova (if $count>-1|[zbyva $count varovani])"
"user-is-warned-about-links": "Nejsou povoleny linky, pozadej o !permit [zbyva $count varovani]",
"user-is-warned-about-symbols": "Prilisne pouzivani symbolu neni povoleno [zbyva $count varovani]",
"user-is-warned-about-long-message": "Tva zprava je prilis dlouha [zbyva $count varovani]",
"user-is-warned-about-caps": "Prilisne pouzivani velkych pismen neni povoleno [zbyva $count varovani]",
"user-is-warned-about-spam": "Spamovani neni povoleno [zbyva $count varovani]",
"user-is-warned-about-color": "Pouzivani /me neni povoleno [zbyva $count varovani]",
"user-is-warned-about-emotes": "Zadne spamovani smajlikama! [zbyva $count varovani]",
"user-is-warned-about-blacklist": "Zadne zakazane slova [zbyva $count varovani]",
"user-have-timeout-for-links": "Nejsou povoleny linky, pozadej o !permit",
"user-have-timeout-for-symbols": "Prilisne pouzivani symbolu neni povoleno",
"user-have-timeout-for-long-message": "Tva zprava je prilis dlouha",
"user-have-timeout-for-caps": "Prilisne pouzivani velkych pismen neni povoleno",
"user-have-timeout-for-spam": "Spamovani neni povoleno",
"user-have-timeout-for-color": "Pouzivani /me neni povoleno",
"user-have-timeout-for-emotes": "Zadne spamovani smajlikama!",
"user-have-timeout-for-blacklist": "Zadne zakazane slova"
},
"queue": {
"info": {
Expand Down
32 changes: 16 additions & 16 deletions locales/en.json
Expand Up @@ -1098,22 +1098,22 @@
"moderation": {
"user-have-link-permit": "User $username can post a $count $link to chat",
"permit-parse-failed": "{core.command-parse} !permit [username]",
"user-is-warned-about-links": "No links allowed, ask for !permit (if $count>-1|[$count warnings left])",
"user-is-warned-about-symbols": "No excessive symbols usage (if $count>-1|[$count warnings left])",
"user-is-warned-about-long-message": "Long messages are not allowed (if $count>-1|[$count warnings left])",
"user-is-warned-about-caps": "No excessive caps usage (if $count>-1|[$count warnings left])",
"user-is-warned-about-spam": "Spamming is not allowed (if $count>-1|[$count warnings left])",
"user-is-warned-about-color": "Colors and /me is not allowed (if $count>-1|[$count warnings left])",
"user-is-warned-about-emotes": "No emotes spamming (if $count>-1|[$count warnings left])",
"user-is-warned-about-blacklist": "No blacklisted words (if $count>-1|[$count warnings left])",
"user-have-timeout-for-links": "No links allowed, ask for !permit (if $count>-1|[$count warnings left])",
"user-have-timeout-for-symbols": "No excessive symbols usage (if $count>-1|[$count warnings left])",
"user-have-timeout-for-long-message": "Long message are not allowed (if $count>-1|[$count warnings left])",
"user-have-timeout-for-caps": "No excessive caps usage (if $count>-1|[$count warnings left])",
"user-have-timeout-for-spam": "Spamming is not allowed (if $count>-1|[$count warnings left])",
"user-have-timeout-for-color": "Colors and /me is not allowed (if $count>-1|[$count warnings left])",
"user-have-timeout-for-emotes": "No emotes spamming (if $count>-1|[$count warnings left])",
"user-have-timeout-for-blacklist": "No blacklisted words (if $count>-1|[$count warnings left])"
"user-is-warned-about-links": "No links allowed, ask for !permit [$count warnings left]",
"user-is-warned-about-symbols": "No excessive symbols usage [$count warnings left]",
"user-is-warned-about-long-message": "Long messages are not allowed [$count warnings left]",
"user-is-warned-about-caps": "No excessive caps usage [$count warnings left]",
"user-is-warned-about-spam": "Spamming is not allowed [$count warnings left]",
"user-is-warned-about-color": "Colors and /me is not allowed [$count warnings left]",
"user-is-warned-about-emotes": "No emotes spamming [$count warnings left]",
"user-is-warned-about-blacklist": "No blacklisted words [$count warnings left]",
"user-have-timeout-for-links": "No links allowed, ask for !permit",
"user-have-timeout-for-symbols": "No excessive symbols usage",
"user-have-timeout-for-long-message": "Long message are not allowed",
"user-have-timeout-for-caps": "No excessive caps usage",
"user-have-timeout-for-spam": "Spamming is not allowed",
"user-have-timeout-for-color": "Colors and /me is not allowed",
"user-have-timeout-for-emotes": "No emotes spamming",
"user-have-timeout-for-blacklist": "No blacklisted words"
},
"queue": {
"info": {
Expand Down
2 changes: 1 addition & 1 deletion main.js
Expand Up @@ -148,7 +148,7 @@ function fork () {
} else if (msg.type === 'db') {
// do nothing on db
} else if (msg.type === 'timeout') {
global.client.timeout(config.settings.broadcaster_username, msg.username, msg.timeout, msg.reason)
global.commons.timeout(msg.username, msg.reason, msg.timeout)
} else if (msg.type === 'api') {
global.api[msg.fnc](msg.username, msg.id)
} else if (msg.type === 'event') {
Expand Down

0 comments on commit 9124f5b

Please sign in to comment.