separated commands from message event and added state control to them

This commit is contained in:
DeSqBlocki
2025-02-13 19:45:13 +01:00
parent fe0c937fb2
commit 5b07182020
6 changed files with 217 additions and 79 deletions
+25
View File
@@ -0,0 +1,25 @@
const { mClient } = require('../..')
const { updateChatMode, getIDByName } = require('../../functions')
module.exports = {
name: 'Command/mode',
once: false,
async execute(channel, userstate, message, self, params) {
const db = mClient.db('channels')
const coll = db.collection(channel)
const command = await coll.findOne({ name: 'mode' })
// create if not exists
if (!command) {
await coll.insertOne({
name: 'mode',
enabled: false // default
})
}
if (!command.enabled){ return }
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return }
let regex = /^(on|off)$/
if (!params.match(regex)) { return }
updateChatMode(await getIDByName(channel.substring(1)), params)
}
}