const {Command,ErrorMessage, ErrorType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('../../lib.js') const strikeM = require('../../models/strikes'); class strike extends Command{ constructor(client){ super(client, { name: 'strike', group:'admin', description: 'Strikes an user. Usage !strike @USER REASON', needsAdmin:true, }) this.client = client; this.message; } async run(message, args) { //Check admin privilege this.message = message; var confirm = await this.confirmArgs(message,args); if(confirm=='Error') return new ErrorMessage(this.client).send(ErrorType.Arguments, message, ['Use the mention method to pass the user.', 'Make sure you provide a reason.']) var strike = new strikeM(); strike.strikerID = confirm.strikerID; strike.strokedID = confirm.strokedID; strike.guildName = message.guild.name; strike.guildID = message.guild.id strike.reason = confirm.reason; strike.date = Date.now(); strike.save(err=> { if(err)console.log(err); this.sendMessage(confirm.strokedID,confirm.reason); message.delete(); }) } async sendMessage(strokedID, reason) { let name = this.client.guilds.cache.get(this.message.guildId).members.cache.get(strokedID); const embed = new EmbedBuilder() 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(`Strike`) embed.setDescription(`${name} has been struck.`) embed.addFields({name:'Reason:', value:reason}) const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId('RemoveStrikeMessage') .setLabel('Remove this.') .setStyle(ButtonStyle.Primary), ); const filter = i => i.customId === 'RemoveStrikeMessage'; await this.message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const collector = this.message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { m.message.delete() .then(()=> { // console.log('Strikes: Embed Message: Deleted'); }) .catch(()=> { // console.log('Strikes: Embed Message: failed to delete.'); }) }); } async confirmArgs(message,args) { if(args.length<2) return 'Error' if(!args[0].split('@')) return 'Error' let strikerID = message.author.id; let strokedID = args[0].split('@')[1].split('>')[0]; return {strikerID, strokedID, reason:args.splice(-1,1).join(' ')} } }module.exports = strike;