separated commands from message event and added state control to them
This commit is contained in:
@@ -21,49 +21,7 @@ module.exports = {
|
||||
})
|
||||
}
|
||||
}
|
||||
async function sendPositivity() {
|
||||
// Function sends a random string of predetermined positivity, Donothon Top Donator Reward
|
||||
let positive_Messages = [
|
||||
"You are so very worthy of all the love and support that may come your way.",
|
||||
"There are many things which draw us together. In this time and place, that lovely subject is you, Hel.",
|
||||
"The happiness and joy you add to the world is worth more than most anything.",
|
||||
"You deserve every warm laugh, bright smile, and all the genuine kindness given to you.",
|
||||
"There are few things as precious as your time. Thank you for sharing with us.",
|
||||
"Your feelings are valid and you are not less than for having them.",
|
||||
"I've seen all the work you do and I'm so very proud of you.",
|
||||
"You are dearly cherished and I want to thank you for being so wonderfully you.",
|
||||
"You. Are. Worthy. Enough. And I will tell you as many times as it takes for you to believe it.",
|
||||
"Every day you give your best and that is so admirable. Don't let anyone tell you otherwise.",
|
||||
"Your light is like that of the full moon, brightening our lives even in our darkest moments.",
|
||||
"It's okay to take a moment to catch your breath. Even machines require maintenance from time to time.",
|
||||
"Watching you succeed and achieve your heart's desires gives me so much motivation and I am very grateful for it."
|
||||
]
|
||||
|
||||
let rdm = Math.floor(Math.random() * positive_Messages.length)
|
||||
return tClient.say(channel, positive_Messages[rdm])
|
||||
}
|
||||
async function sendDonationAd() {
|
||||
// Function to send static donate ad
|
||||
const links = [
|
||||
"https://bit.ly/heltwittergoals",
|
||||
"https://bit.ly/donatetohel",
|
||||
"http://bit.ly/donothon_goals"
|
||||
];
|
||||
|
||||
const messages = [
|
||||
"Hel is currently celebrating her birthday with a donathon!",
|
||||
`You can see goals and incentives here: ${links[0]}`,
|
||||
`You can donate here: ${links[1]}`,
|
||||
`Terms, conditions, rules and how rewards work are found here: ${links[2]}`,
|
||||
"All donations and gifts are greatly appreciated, but please do so responsibly!"
|
||||
];
|
||||
|
||||
for (const message of messages) {
|
||||
await tClient.say(channel, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (self) { return }
|
||||
if (knownBots.has(userstate.username)) { return }
|
||||
|
||||
@@ -87,16 +45,16 @@ module.exports = {
|
||||
const cmd = args[0]
|
||||
switch (cmd) {
|
||||
case "mode":
|
||||
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { break } // return stops all further operations, so you should just break out of switch
|
||||
let regex = /^(on|off)$/
|
||||
if (!args[1].match(regex)) { break }
|
||||
updateChatMode(await getIDByName(channel.substring(1)), args[1])
|
||||
dClient.emit('Command/mode', channel, userstate, message, self, args[1])
|
||||
break;
|
||||
case "donate":
|
||||
sendDonationAd()
|
||||
dClient.emit('Command/donate', channel, userstate, message, self)
|
||||
break;
|
||||
case "positivity":
|
||||
sendPositivity()
|
||||
dClient.emit('Command/positivity', channel, userstate, message, self)
|
||||
break;
|
||||
case "commands":
|
||||
dClient.emit('Command/commands', channel, userstate, message, self, args[1], args[2])
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,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')
|
||||
const coll = db.collection(channel)
|
||||
const command = await coll.findOne({ name: 'commands' })
|
||||
|
||||
// create if not exists
|
||||
if (!command) {
|
||||
await coll.insertOne({
|
||||
name: 'commands',
|
||||
enabled: false // default
|
||||
})
|
||||
}
|
||||
|
||||
// Default non-admin mode, give list of all enabled commands
|
||||
if (!name) {
|
||||
const commands = await coll.find({ enabled: true }).toArray()
|
||||
var commandList = []
|
||||
commands.forEach((command) => {
|
||||
if (command.enabled) {
|
||||
commandList.push(command.name)
|
||||
}
|
||||
})
|
||||
if (commandList.length == 0) {
|
||||
return await tClient.say(channel, `No commands enabled in this channel`)
|
||||
}
|
||||
console.log(commandList)
|
||||
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':
|
||||
state = true
|
||||
break;
|
||||
case 'off':
|
||||
state = false
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// 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`) }
|
||||
|
||||
|
||||
await coll.findOneAndUpdate({
|
||||
name: name
|
||||
}, {
|
||||
$set: { enabled: state }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
await tClient.say(channel, `[${name}] has been set to [${state}]`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
const { mClient, tClient } = require("../..");
|
||||
|
||||
module.exports = {
|
||||
name: 'Command/donate',
|
||||
once: false,
|
||||
async execute(channel, userstate, message, self) {
|
||||
|
||||
const db = mClient.db('channels')
|
||||
const coll = db.collection(channel)
|
||||
const command = await coll.findOne({ name: 'donate' })
|
||||
|
||||
// create if not exists
|
||||
if (!command) {
|
||||
await coll.insertOne({
|
||||
name: 'donate',
|
||||
enabled: false // default
|
||||
})
|
||||
}
|
||||
|
||||
if (!command.enabled){ return }
|
||||
|
||||
async function sendDonationAd() {
|
||||
// Function to send static donate ad
|
||||
const links = [
|
||||
"https://bit.ly/heltwittergoals",
|
||||
"https://bit.ly/donatetohel",
|
||||
"http://bit.ly/donothon_goals"
|
||||
];
|
||||
|
||||
const messages = [
|
||||
"Hel is currently celebrating her birthday with a donathon!",
|
||||
`You can see goals and incentives here: ${links[0]}`,
|
||||
`You can donate here: ${links[1]}`,
|
||||
`Terms, conditions, rules and how rewards work are found here: ${links[2]}`,
|
||||
"All donations and gifts are greatly appreciated, but please do so responsibly!"
|
||||
];
|
||||
|
||||
for (const message of messages) {
|
||||
await tClient.say(channel, message);
|
||||
}
|
||||
}
|
||||
sendDonationAd()
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
const { tClient, mClient } = require('../..')
|
||||
module.exports = {
|
||||
name: 'Command/positivity',
|
||||
once: false,
|
||||
async execute(channel, userstate, message, self) {
|
||||
const db = mClient.db('channels')
|
||||
const coll = db.collection(channel)
|
||||
const command = await coll.findOne({ name: 'positivity' })
|
||||
|
||||
// create if not exists
|
||||
if (!command) {
|
||||
await coll.insertOne({
|
||||
name: 'positivity',
|
||||
enabled: false // default
|
||||
})
|
||||
}
|
||||
|
||||
if (!command.enabled){ return }
|
||||
|
||||
async function sendPositivity() {
|
||||
// Function sends a random string of predetermined positivity, Donothon Top Donator Reward
|
||||
let positive_Messages = [
|
||||
"You are so very worthy of all the love and support that may come your way.",
|
||||
"There are many things which draw us together. In this time and place, that lovely subject is you, Hel.",
|
||||
"The happiness and joy you add to the world is worth more than most anything.",
|
||||
"You deserve every warm laugh, bright smile, and all the genuine kindness given to you.",
|
||||
"There are few things as precious as your time. Thank you for sharing with us.",
|
||||
"Your feelings are valid and you are not less than for having them.",
|
||||
"I've seen all the work you do and I'm so very proud of you.",
|
||||
"You are dearly cherished and I want to thank you for being so wonderfully you.",
|
||||
"You. Are. Worthy. Enough. And I will tell you as many times as it takes for you to believe it.",
|
||||
"Every day you give your best and that is so admirable. Don't let anyone tell you otherwise.",
|
||||
"Your light is like that of the full moon, brightening our lives even in our darkest moments.",
|
||||
"It's okay to take a moment to catch your breath. Even machines require maintenance from time to time.",
|
||||
"Watching you succeed and achieve your heart's desires gives me so much motivation and I am very grateful for it."
|
||||
]
|
||||
|
||||
let rdm = Math.floor(Math.random() * positive_Messages.length)
|
||||
return tClient.say(channel, positive_Messages[rdm])
|
||||
}
|
||||
sendPositivity()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user