diff --git a/commands/random/reminder.js b/commands/random/reminder.js new file mode 100644 index 0000000..4f09ec2 --- /dev/null +++ b/commands/random/reminder.js @@ -0,0 +1,71 @@ +const {Command, Random, ErrorMessage, ErrorType} = require('../../lib.js'); +const {EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('discord.js'); + +var Job = require('cron').CronJob; + + class remind extends Command{ + constructor(client){ + super(client, { + name: 'remind', + aliases: ['remindme'], + description: `It will send you a message after the ammount of minutes you specified. Ex: !remindme "message" 5` + + }) + } + async run(message, args) + { + if(!args[1]) return new ErrorMessage(this.client).send(ErrorType.NoArguments, message); + if(isNaN(parseInt(args[1]))) return new ErrorMessage(this.client).send(ErrorType.Arguments,message); + var reminderMessage = args.slice(0,-1); + reminderMessage = new Array(reminderMessage).join(" ") + console.log('Reminder:', message.author.id, 'wants to be reminded of', reminderMessage, 'in', args[args.length-1]); + const embed = new EmbedBuilder() + const randomID = Random(); + embed.setFooter({text:'Rem-chan on ', iconURL:"https://i.imgur.com/g6FSNhL.png"}) + embed.setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'}); + embed.setColor(0x110809); + embed.setTimestamp() + embed.setTitle(`Reminder set.`) + embed.addFields({name:'With the message:', value:reminderMessage}) + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(randomID+0) + .setLabel('Remove message.') + .setStyle(ButtonStyle.Primary), + ); + const row1 = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(randomID+1) + .setLabel('Remove reminder.') + .setStyle(ButtonStyle.Danger), + ); + const filter = i => i.customId.slice(0, i.customId.length-1) === randomID; + message.channel.send({embeds: [embed], components: [row, row1] }); + + var timer = new Job( + new Date(new Date().setMinutes(new Date().getMinutes()+parseInt(args[args.length-1]))), + function() { + message.author.send(reminderMessage) + }, + null, + true + ); + + const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); + collector.on('collect', async m => + { + if(m.customId[m.customId.length-1]==1) timer.stop(); + message.delete(); + m.message.delete(); + }); + collector.on('end', async m=> + { + message.delete(); + m.message.delete() + }) + + } + } + module.exports = remind; \ No newline at end of file diff --git a/lib.js b/lib.js index 3bf3373..0003341 100644 --- a/lib.js +++ b/lib.js @@ -124,8 +124,7 @@ class _Client extends Client { let commandName=message.content.split('!')[1].split(' ')[0]; let args = message.content.split(' '); - args.splice(0,1); - args = args.filter(n=>n); + args = args.slice(1); if(this.commands.get(commandName)) { let needsAdmin = this.commands.get(commandName).needsAdmin; diff --git a/package-lock.json b/package-lock.json index 3cf174a..e9d9d42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@discordjs/voice": "^0.13.0", "axios": "^1.1.3", "bufferutil": "^4.0.7", + "cron": "^2.4.0", "discord-ytdl-core": "^5.0.4", "discord.js": "^14.6.0", "ejs": "^3.1.8", @@ -1824,6 +1825,14 @@ "node": ">= 0.10" } }, + "node_modules/cron": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/cron/-/cron-2.4.0.tgz", + "integrity": "sha512-Cx77ic1TyIAtUggr0oAhtS8MLzPBUqGNIvdDM7jE3oFIxfe8LXWI9q3iQN/H2CebAiMir53LQKWOhEKnzkJTAQ==", + "dependencies": { + "luxon": "^3.2.1" + } + }, "node_modules/css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", @@ -2727,6 +2736,14 @@ "es5-ext": "~0.10.2" } }, + "node_modules/luxon": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.0.tgz", + "integrity": "sha512-7eDo4Pt7aGhoCheGFIuq4Xa2fJm4ZpmldpGhjTYBNUYNCN6TIEP6v7chwwwt3KRp7YR+rghbfvjyo3V5y9hgBw==", + "engines": { + "node": ">=12" + } + }, "node_modules/m3u8stream": { "version": "0.8.6", "resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.6.tgz", @@ -5382,6 +5399,14 @@ "vary": "^1" } }, + "cron": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/cron/-/cron-2.4.0.tgz", + "integrity": "sha512-Cx77ic1TyIAtUggr0oAhtS8MLzPBUqGNIvdDM7jE3oFIxfe8LXWI9q3iQN/H2CebAiMir53LQKWOhEKnzkJTAQ==", + "requires": { + "luxon": "^3.2.1" + } + }, "css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", @@ -6048,6 +6073,11 @@ "es5-ext": "~0.10.2" } }, + "luxon": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.0.tgz", + "integrity": "sha512-7eDo4Pt7aGhoCheGFIuq4Xa2fJm4ZpmldpGhjTYBNUYNCN6TIEP6v7chwwwt3KRp7YR+rghbfvjyo3V5y9hgBw==" + }, "m3u8stream": { "version": "0.8.6", "resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.6.tgz", diff --git a/package.json b/package.json index 835d8df..ce8431b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,9 @@ "musicWorker": "nodemon musicWorker.js 334456736633323520 Legendary" }, "nodemonConfig": { - "ignore": ["public/*"] + "ignore": [ + "public/*" + ] }, "author": "", "license": "ISC", @@ -19,6 +21,7 @@ "@discordjs/voice": "^0.13.0", "axios": "^1.1.3", "bufferutil": "^4.0.7", + "cron": "^2.4.0", "discord-ytdl-core": "^5.0.4", "discord.js": "^14.6.0", "ejs": "^3.1.8",