Add anti-spam system
This commit is contained in:
parent
8a7a97cfe9
commit
f8ddba5fd7
3 changed files with 23 additions and 8 deletions
|
@ -11,6 +11,7 @@
|
|||
"time.minutePlural": " minutes ",
|
||||
"time.second": " second ",
|
||||
"time.secondPlural": " seconds ",
|
||||
"chat.antiSpamTriggered": "Anti-spam has been triggered for this server.",
|
||||
"command.about.usage": "",
|
||||
"command.about.desc": "About the bot",
|
||||
"command.cb.usage": " <command>",
|
||||
|
|
|
@ -2,6 +2,7 @@ const settings = require('../settings.json')
|
|||
const parsePlain = require('../util/chatparse_plain.js')
|
||||
const parseConsole = require('../util/chatparse_console.js')
|
||||
const parse1204 = require('../util/parseNBT.js')
|
||||
const { getMessage } = require('../util/lang.js')
|
||||
const convertChatStyleItem = (item) => {
|
||||
const output = {}
|
||||
for (const i in item) {
|
||||
|
@ -26,6 +27,11 @@ const convertChatTypeItem = (item) => {
|
|||
}
|
||||
module.exports = {
|
||||
load: (b) => {
|
||||
b.messageCount = 0;
|
||||
b.chatDisabledUntil = 0;
|
||||
b.interval.antiSpam = setInterval(()=>{
|
||||
b.messageCount = 0;
|
||||
}, 4000)
|
||||
b.messageTypes = []
|
||||
b._client.on('registry_data', (data) => {
|
||||
if (data.codec.value['minecraft:chat_type']) {
|
||||
|
@ -163,6 +169,13 @@ module.exports = {
|
|||
})
|
||||
|
||||
b.on('chat', (data) => {
|
||||
b.messageCount++;
|
||||
if(Date.now() < b.chatDisabledUntil) return
|
||||
if(b.messageCount >= 100){
|
||||
b.info(getMessage(settings.defaultLang, "chat.antiSpamTriggered"))
|
||||
b.chatDisabledUntil = Date.now() + 30000
|
||||
return
|
||||
}
|
||||
const msgConsole = parseConsole(data.json)
|
||||
const msgPlain = parsePlain(data.json)
|
||||
if (settings.logJSONmessages) console.log(data.json)
|
||||
|
@ -170,14 +183,6 @@ module.exports = {
|
|||
if (msgPlain.startsWith('Command set: ')) return
|
||||
b.emit('plainchat', msgPlain, data.type)
|
||||
b.displayChat(data.type, `${msgConsole}\x1b[0m`)
|
||||
|
||||
const fullCommand = data.message
|
||||
for (const prefix of b.prefix) {
|
||||
if (fullCommand.startsWith(prefix)) {
|
||||
const command = fullCommand.slice(prefix.length)
|
||||
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, prefix)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,15 @@ module.exports = {
|
|||
load: (b) => {
|
||||
b.prefix = settings.prefix
|
||||
b.lastCmd = 0
|
||||
b.on("chat",(data)=>{
|
||||
const fullCommand = data.message
|
||||
for (const prefix of b.prefix) {
|
||||
if (fullCommand.startsWith(prefix)) {
|
||||
const command = fullCommand.slice(prefix.length)
|
||||
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, prefix)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.runCommand = (name, nickname, uuid, text, msgType, prefix) => {
|
||||
if (uuid === '00000000-0000-0000-0000-000000000000') return
|
||||
if (Date.now() - b.lastCmd <= 1000) return
|
||||
|
|
Loading…
Reference in a new issue