added settings

This commit is contained in:
DeSqBlocki
2025-02-13 21:04:53 +01:00
parent 5b07182020
commit 85f031c33a
8 changed files with 155 additions and 29 deletions
+8 -2
View File
@@ -21,7 +21,7 @@ module.exports = {
}) })
} }
} }
if (self) { return } if (self) { return }
if (knownBots.has(userstate.username)) { return } if (knownBots.has(userstate.username)) { return }
@@ -54,7 +54,13 @@ module.exports = {
dClient.emit('Command/positivity', channel, userstate, message, self) dClient.emit('Command/positivity', channel, userstate, message, self)
break; break;
case "commands": case "commands":
dClient.emit('Command/commands', channel, userstate, message, self, args[1], args[2]) dClient.emit('Command/commands', channel, userstate, message, self, args[1], args[2])
break;
case "settings":
dClient.emit('Command/settings', channel, userstate, message, self, args[1], args[2])
break;
case "so":
dClient.emit('Command/so', channel, userstate, message, self, args[1])
break; break;
default: default:
break; break;
+16 -2
View File
@@ -1,4 +1,4 @@
const { tClient } = require("../.."); const { tClient, mClient } = require("../..");
const { getChannelInformation } = require("../../functions"); const { getChannelInformation } = require("../../functions");
// Event triggered by Custom Shoutout emitted in Messages.js // Event triggered by Custom Shoutout emitted in Messages.js
@@ -9,7 +9,21 @@ module.exports = {
name: 'Twitch/Shoutout', name: 'Twitch/Shoutout',
once: false, once: false,
async execute(reason, channel, username) { async execute(reason, channel, username) {
// Check if shoutout is enabled
const db = mClient.db('settings')
const coll = db.collection(channel)
const setting = await coll.findOne({ name: 'shoutout' })
// create in disabled state if not exists
if (!setting) {
await coll.insertOne({
name: 'shoutout',
enabled: false // default
})
}
if (!setting?.enabled && reason != 'command' ){ return }
// Function to perform shoutout (Nightbot or custom) // Function to perform shoutout (Nightbot or custom)
async function doShoutouts(channel, user) { async function doShoutouts(channel, user) {
try { try {
+29 -15
View File
@@ -3,54 +3,68 @@ const { mClient, tClient } = require("../..");
module.exports = { module.exports = {
name: 'Command/commands', name: 'Command/commands',
once: false, once: false,
async execute(channel, userstate, message, self, name, state) { async execute(channel, userstate, message, self, state, name) {
const db = mClient.db('channels') const db = mClient.db('commands')
const coll = db.collection(channel) const coll = db.collection(channel)
const defaultCommands = await coll.find({ default: true}).toArray()
var isDefault = false
defaultCommands.forEach((command) => {
if(command.default && command.name == name ){
isDefault = true
}
})
if (isDefault){
return tClient.say(channel, `${name} can't be modified`)
}
const command = await coll.findOne({ name: 'commands' }) const command = await coll.findOne({ name: 'commands' })
// create if not exists // create in disabled state if not exists
if (!command) { if (!command) {
await coll.insertOne({ await coll.insertOne({
name: 'commands', name: 'commands',
enabled: false // default enabled: true,
default: true
}) })
} }
// Default non-admin mode, give list of all enabled commands // Default non-admin mode, give list of all enabled commands
if (!name) { if (!name) {
const commands = await coll.find({ enabled: true }).toArray() const commands = await coll.find({}).toArray()
var commandList = [] var commandList = []
commands.forEach((command) => { commands.forEach((command) => {
if (command.enabled) { if(userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1){
commandList.push(command.name) commandList.push(` ${command.name}`)
} else {
commandList.push(` ${command.name}(${command.enabled?'✅':'❌'})`)
} }
}) })
if (commandList.length == 0) { if (commandList.length == 0) {
return await tClient.say(channel, `No commands enabled in this channel`) return await tClient.say(channel, `No commands available in this channel`)
} }
console.log(commandList) return await tClient.say(channel, `Command List: ${commandList.toString()}`)
await tClient.say(channel, `Command List: ${commandList.toString()}`)
} }
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return } if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return }
if (!state) { return } if (!state) { return }
// Admin Mode & Additional Parameters were given // Admin Mode & Additional Parameters were given
// Parameters are valid // Parameters are valid
switch (state) { switch (state) {
case 'on': case 'enable':
state = true state = true
break; break;
case 'off': case 'disable':
state = false state = false
break; break;
default: default:
break; return tClient.say(channel, `invalid state, expecting 'enable' or 'disable'`)
} }
// command is valid // command is valid
const findCommand = await coll.findOne({ name: name }) const findCommand = await coll.findOne({ name: name })
if (!findCommand) { return await tClient.say(channel, `Command [${name}] not found. Try using it first if it exists`) } if (!findCommand) { return await tClient.say(channel, `Command [${name}] not found. Try using it first if it exists`) }
@@ -63,6 +77,6 @@ module.exports = {
upsert: true upsert: true
}) })
await tClient.say(channel, `[${name}] has been set to [${state}]`) return await tClient.say(channel, `[${name}] has been set to [${state}]`)
} }
} }
+3 -3
View File
@@ -5,11 +5,11 @@ module.exports = {
once: false, once: false,
async execute(channel, userstate, message, self) { async execute(channel, userstate, message, self) {
const db = mClient.db('channels') const db = mClient.db('commands')
const coll = db.collection(channel) const coll = db.collection(channel)
const command = await coll.findOne({ name: 'donate' }) const command = await coll.findOne({ name: 'donate' })
// create if not exists // create in disabled state if not exists
if (!command) { if (!command) {
await coll.insertOne({ await coll.insertOne({
name: 'donate', name: 'donate',
@@ -17,7 +17,7 @@ module.exports = {
}) })
} }
if (!command.enabled){ return } if (!command?.enabled){ return tClient.say(channel, `This command is currently disabled `)}
async function sendDonationAd() { async function sendDonationAd() {
// Function to send static donate ad // Function to send static donate ad
+4 -4
View File
@@ -1,21 +1,21 @@
const { mClient } = require('../..') const { mClient, tClient } = require('../..')
const { updateChatMode, getIDByName } = require('../../functions') const { updateChatMode, getIDByName } = require('../../functions')
module.exports = { module.exports = {
name: 'Command/mode', name: 'Command/mode',
once: false, once: false,
async execute(channel, userstate, message, self, params) { async execute(channel, userstate, message, self, params) {
const db = mClient.db('channels') const db = mClient.db('commands')
const coll = db.collection(channel) const coll = db.collection(channel)
const command = await coll.findOne({ name: 'mode' }) const command = await coll.findOne({ name: 'mode' })
// create if not exists // create in disabled state if not exists
if (!command) { if (!command) {
await coll.insertOne({ await coll.insertOne({
name: 'mode', name: 'mode',
enabled: false // default enabled: false // default
}) })
} }
if (!command.enabled){ return } if (!command?.enabled){ return tClient.say(channel, `This command is currently disabled `) }
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return } if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return }
let regex = /^(on|off)$/ let regex = /^(on|off)$/
+3 -3
View File
@@ -3,11 +3,11 @@ module.exports = {
name: 'Command/positivity', name: 'Command/positivity',
once: false, once: false,
async execute(channel, userstate, message, self) { async execute(channel, userstate, message, self) {
const db = mClient.db('channels') const db = mClient.db('commands')
const coll = db.collection(channel) const coll = db.collection(channel)
const command = await coll.findOne({ name: 'positivity' }) const command = await coll.findOne({ name: 'positivity' })
// create if not exists // create in disabled state if not exists
if (!command) { if (!command) {
await coll.insertOne({ await coll.insertOne({
name: 'positivity', name: 'positivity',
@@ -15,7 +15,7 @@ module.exports = {
}) })
} }
if (!command.enabled){ return } if (!command?.enabled){ return tClient.say(channel, `This command is currently disabled `) }
async function sendPositivity() { async function sendPositivity() {
// Function sends a random string of predetermined positivity, Donothon Top Donator Reward // Function sends a random string of predetermined positivity, Donothon Top Donator Reward
+69
View File
@@ -0,0 +1,69 @@
const { mClient, tClient } = require("../..");
module.exports = {
name: 'Command/settings',
once: false,
async execute(channel, userstate, message, self, state, name) {
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return }
const db = mClient.db('commands')
const coll = db.collection(channel)
const command = await coll.findOne({ name: 'settings' })
// create in disabled state if not exists
if (!command) {
await coll.insertOne({
name: 'settings',
enabled: true,
default: true
})
}
if (!command?.enabled) { return tClient.say(channel, `This command is currently disabled `) }
const db2 = mClient.db('settings')
const coll2 = db2.collection(channel)
// Default non-admin mode, give list of all enabled commands
if (!name) {
const settings = await coll2.find({}).toArray()
var settingsList = []
console.log(settings)
settings.forEach((setting) => {
settingsList.push(` ${setting.name}(${setting.enabled?'✅':'❌'})`)
})
if (settingsList.length == 0) {
return await tClient.say(channel, `No settings available in this channel`)
}
return await tClient.say(channel, `Settings List: ${settingsList.toString()}`)
}
if (!state) { return }
// Parameters are valid
switch (state) {
case 'enable':
state = true
break;
case 'disable':
state = false
break;
default:
return tClient.say(channel, `invalid state, expecting 'enable' or 'disable'`)
}
// command is valid
const findSetting = await coll2.findOne({ name: name })
if (!findSetting) { return await tClient.say(channel, `Setting [${name}] not found.`) }
await coll2.findOneAndUpdate({
name: name
}, {
$set: { enabled: state }
}, {
upsert: true
})
return await tClient.say(channel, `[${name}] has been set to [${state}]`)
}
}
+23
View File
@@ -0,0 +1,23 @@
const { mClient, dClient, tClient } = require('../..')
const { updateChatMode, getIDByName } = require('../../functions')
module.exports = {
name: 'Command/so',
once: false,
async execute(channel, userstate, message, self, name) {
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return }
const db = mClient.db('commands')
const coll = db.collection(channel)
const command = await coll.findOne({ name: 'so' })
// create in disabled state if not exists
if (!command) {
await coll.insertOne({
name: 'so',
enabled: false // default
})
}
if (!command?.enabled) { return tClient.say(channel, `This command is currently disabled `) }
dClient.emit('Twitch/Shoutout', 'command', channel, name)
}
}