diff --git a/events/Twitch/Message.js b/events/Twitch/Message.js index 6a9ac27..20da3e1 100644 --- a/events/Twitch/Message.js +++ b/events/Twitch/Message.js @@ -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; diff --git a/events/TwitchCommands/commands.js b/events/TwitchCommands/commands.js new file mode 100644 index 0000000..976d413 --- /dev/null +++ b/events/TwitchCommands/commands.js @@ -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}]`) + } +} \ No newline at end of file diff --git a/events/TwitchCommands/donate.js b/events/TwitchCommands/donate.js new file mode 100644 index 0000000..726cdb1 --- /dev/null +++ b/events/TwitchCommands/donate.js @@ -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() + } +} \ No newline at end of file diff --git a/events/TwitchCommands/mode.js b/events/TwitchCommands/mode.js new file mode 100644 index 0000000..4a02d9e --- /dev/null +++ b/events/TwitchCommands/mode.js @@ -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) + } +} \ No newline at end of file diff --git a/events/TwitchCommands/positivity.js b/events/TwitchCommands/positivity.js new file mode 100644 index 0000000..8d0b9fd --- /dev/null +++ b/events/TwitchCommands/positivity.js @@ -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() + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5a769a0..bec1392 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,15 +21,15 @@ } }, "node_modules/@discordjs/builders": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.10.0.tgz", - "integrity": "sha512-ikVZsZP+3shmVJ5S1oM+7SveUCK3L9fTyfA8aJ7uD9cNQlTqF+3Irbk2Y22KXTb3C3RNUahRkSInClJMkHrINg==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.10.1.tgz", + "integrity": "sha512-OWo1fY4ztL1/M/DUyRPShB4d/EzVfuUvPTRRHRIt/YxBrUYSz0a+JicD5F5zHFoNs2oTuWavxCOVFV1UljHTng==", "license": "Apache-2.0", "dependencies": { "@discordjs/formatters": "^0.6.0", "@discordjs/util": "^1.1.1", "@sapphire/shapeshift": "^4.0.0", - "discord-api-types": "^0.37.114", + "discord-api-types": "^0.37.119", "fast-deep-equal": "^3.1.3", "ts-mixer": "^6.0.4", "tslib": "^2.6.3" @@ -66,9 +66,9 @@ } }, "node_modules/@discordjs/rest": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.4.2.tgz", - "integrity": "sha512-9bOvXYLQd5IBg/kKGuEFq3cstVxAMJ6wMxO2U3wjrgO+lHv8oNCT+BBRpuzVQh7BoXKvk/gpajceGvQUiRoJ8g==", + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.4.3.tgz", + "integrity": "sha512-+SO4RKvWsM+y8uFHgYQrcTl/3+cY02uQOH7/7bKbVZsTfrfpoE62o5p+mmV+s7FVhTX82/kQUGGbu4YlV60RtA==", "license": "Apache-2.0", "dependencies": { "@discordjs/collection": "^2.1.1", @@ -76,10 +76,10 @@ "@sapphire/async-queue": "^1.5.3", "@sapphire/snowflake": "^3.5.3", "@vladfrangu/async_event_emitter": "^2.4.6", - "discord-api-types": "^0.37.114", + "discord-api-types": "^0.37.119", "magic-bytes.js": "^1.10.0", "tslib": "^2.6.3", - "undici": "6.19.8" + "undici": "6.21.1" }, "engines": { "node": ">=18" @@ -113,18 +113,18 @@ } }, "node_modules/@discordjs/ws": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@discordjs/ws/-/ws-1.2.0.tgz", - "integrity": "sha512-QH5CAFe3wHDiedbO+EI3OOiyipwWd+Q6BdoFZUw/Wf2fw5Cv2fgU/9UEtJRmJa9RecI+TAhdGPadMaEIur5yJg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@discordjs/ws/-/ws-1.2.1.tgz", + "integrity": "sha512-PBvenhZG56a6tMWF/f4P6f4GxZKJTBG95n7aiGSPTnodmz4N5g60t79rSIAq7ywMbv8A4jFtexMruH+oe51aQQ==", "license": "Apache-2.0", "dependencies": { "@discordjs/collection": "^2.1.0", - "@discordjs/rest": "^2.4.1", + "@discordjs/rest": "^2.4.3", "@discordjs/util": "^1.1.0", "@sapphire/async-queue": "^1.5.2", "@types/ws": "^8.5.10", "@vladfrangu/async_event_emitter": "^2.2.4", - "discord-api-types": "^0.37.114", + "discord-api-types": "^0.37.119", "tslib": "^2.6.2", "ws": "^8.17.0" }, @@ -148,9 +148,9 @@ } }, "node_modules/@mongodb-js/saslprep": { - "version": "1.1.9", - "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.9.tgz", - "integrity": "sha512-tVkljjeEaAhCqTzajSdgbQ6gE6f3oneVwa3iXR6csiEwXXOFsiC6Uh9iAjAhXPtqa/XMDHWjjeNH/77m/Yq2dw==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.2.0.tgz", + "integrity": "sha512-+ywrb0AqkfaYuhHs6LxKWgqbh3I72EpEgESCw37o+9qPx9WTCkgDm2B+eMrwehGtHBWHFU4GXvnSCNiFhhausg==", "license": "MIT", "dependencies": { "sparse-bitfield": "^3.0.3" @@ -494,23 +494,23 @@ "license": "MIT" }, "node_modules/discord.js": { - "version": "14.17.3", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.17.3.tgz", - "integrity": "sha512-8/j8udc3CU7dz3Eqch64UaSHoJtUT6IXK4da5ixjbav4NAXJicloWswD/iwn1ImZEMoAV3LscsdO0zhBh6H+0Q==", + "version": "14.18.0", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.18.0.tgz", + "integrity": "sha512-SvU5kVUvwunQhN2/+0t55QW/1EHfB1lp0TtLZUSXVHDmyHTrdOj5LRKdR0zLcybaA15F+NtdWuWmGOX9lE+CAw==", "license": "Apache-2.0", "dependencies": { - "@discordjs/builders": "^1.10.0", + "@discordjs/builders": "^1.10.1", "@discordjs/collection": "1.5.3", "@discordjs/formatters": "^0.6.0", - "@discordjs/rest": "^2.4.2", + "@discordjs/rest": "^2.4.3", "@discordjs/util": "^1.1.1", - "@discordjs/ws": "^1.2.0", + "@discordjs/ws": "^1.2.1", "@sapphire/snowflake": "3.5.3", - "discord-api-types": "^0.37.114", + "discord-api-types": "^0.37.119", "fast-deep-equal": "3.1.3", "lodash.snakecase": "4.1.1", "tslib": "^2.6.3", - "undici": "6.19.8" + "undici": "6.21.1" }, "engines": { "node": ">=18" @@ -1335,9 +1335,9 @@ "license": "MIT" }, "node_modules/undici": { - "version": "6.19.8", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz", - "integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==", + "version": "6.21.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.21.1.tgz", + "integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==", "license": "MIT", "engines": { "node": ">=18.17" @@ -1365,9 +1365,9 @@ } }, "node_modules/whatwg-url": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.1.0.tgz", - "integrity": "sha512-jlf/foYIKywAt3x/XWKZ/3rz8OSJPiWktjmk891alJUEjiVxKX9LEO92qH3hv4aJ0mN3MWPvGMCy8jQi95xK4w==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.1.1.tgz", + "integrity": "sha512-mDGf9diDad/giZ/Sm9Xi2YcyzaFpbdLpJPr+E9fSkyQ7KpQD4SdFcugkRQYzhmfI4KeV4Qpnn2sKPdo+kmsgRQ==", "license": "MIT", "dependencies": { "tr46": "^5.0.0",