added settings
This commit is contained in:
@@ -21,7 +21,7 @@ module.exports = {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (self) { return }
|
||||
if (knownBots.has(userstate.username)) { return }
|
||||
|
||||
@@ -54,7 +54,13 @@ module.exports = {
|
||||
dClient.emit('Command/positivity', channel, userstate, message, self)
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { tClient } = require("../..");
|
||||
const { tClient, mClient } = require("../..");
|
||||
const { getChannelInformation } = require("../../functions");
|
||||
|
||||
// Event triggered by Custom Shoutout emitted in Messages.js
|
||||
@@ -9,7 +9,21 @@ module.exports = {
|
||||
name: 'Twitch/Shoutout',
|
||||
once: false,
|
||||
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)
|
||||
async function doShoutouts(channel, user) {
|
||||
try {
|
||||
|
||||
@@ -3,54 +3,68 @@ const { mClient, tClient } = require("../..");
|
||||
module.exports = {
|
||||
name: 'Command/commands',
|
||||
once: false,
|
||||
async execute(channel, userstate, message, self, name, state) {
|
||||
const db = mClient.db('channels')
|
||||
async execute(channel, userstate, message, self, state, name) {
|
||||
const db = mClient.db('commands')
|
||||
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' })
|
||||
|
||||
// create if not exists
|
||||
// create in disabled state if not exists
|
||||
if (!command) {
|
||||
await coll.insertOne({
|
||||
name: 'commands',
|
||||
enabled: false // default
|
||||
enabled: true,
|
||||
default: true
|
||||
})
|
||||
}
|
||||
|
||||
// Default non-admin mode, give list of all enabled commands
|
||||
if (!name) {
|
||||
const commands = await coll.find({ enabled: true }).toArray()
|
||||
const commands = await coll.find({}).toArray()
|
||||
var commandList = []
|
||||
commands.forEach((command) => {
|
||||
if (command.enabled) {
|
||||
commandList.push(command.name)
|
||||
if(userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1){
|
||||
commandList.push(` ${command.name}`)
|
||||
} else {
|
||||
commandList.push(` ${command.name}(${command.enabled?'✅':'❌'})`)
|
||||
}
|
||||
|
||||
})
|
||||
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)
|
||||
await tClient.say(channel, `Command List: ${commandList.toString()}`)
|
||||
return await tClient.say(channel, `Command List: ${commandList.toString()}`)
|
||||
}
|
||||
|
||||
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { return }
|
||||
|
||||
if (!state) { return }
|
||||
|
||||
|
||||
// Admin Mode & Additional Parameters were given
|
||||
|
||||
// Parameters are valid
|
||||
switch (state) {
|
||||
case 'on':
|
||||
case 'enable':
|
||||
state = true
|
||||
break;
|
||||
case 'off':
|
||||
case 'disable':
|
||||
state = false
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return tClient.say(channel, `invalid state, expecting 'enable' or 'disable'`)
|
||||
}
|
||||
|
||||
// command is valid
|
||||
|
||||
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`) }
|
||||
|
||||
@@ -63,6 +77,6 @@ module.exports = {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
await tClient.say(channel, `[${name}] has been set to [${state}]`)
|
||||
return await tClient.say(channel, `[${name}] has been set to [${state}]`)
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@ module.exports = {
|
||||
once: false,
|
||||
async execute(channel, userstate, message, self) {
|
||||
|
||||
const db = mClient.db('channels')
|
||||
const db = mClient.db('commands')
|
||||
const coll = db.collection(channel)
|
||||
const command = await coll.findOne({ name: 'donate' })
|
||||
|
||||
// create if not exists
|
||||
// create in disabled state if not exists
|
||||
if (!command) {
|
||||
await coll.insertOne({
|
||||
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() {
|
||||
// Function to send static donate ad
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
const { mClient } = require('../..')
|
||||
const { mClient, tClient } = 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 db = mClient.db('commands')
|
||||
const coll = db.collection(channel)
|
||||
const command = await coll.findOne({ name: 'mode' })
|
||||
|
||||
// create if not exists
|
||||
// create in disabled state if not exists
|
||||
if (!command) {
|
||||
await coll.insertOne({
|
||||
name: 'mode',
|
||||
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 }
|
||||
let regex = /^(on|off)$/
|
||||
|
||||
@@ -3,11 +3,11 @@ module.exports = {
|
||||
name: 'Command/positivity',
|
||||
once: false,
|
||||
async execute(channel, userstate, message, self) {
|
||||
const db = mClient.db('channels')
|
||||
const db = mClient.db('commands')
|
||||
const coll = db.collection(channel)
|
||||
const command = await coll.findOne({ name: 'positivity' })
|
||||
|
||||
// create if not exists
|
||||
// create in disabled state if not exists
|
||||
if (!command) {
|
||||
await coll.insertOne({
|
||||
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() {
|
||||
// Function sends a random string of predetermined positivity, Donothon Top Donator Reward
|
||||
|
||||
@@ -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}]`)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user