Strike command error handling and propagation of strike model data increase.

master
masterhc 1 year ago
parent 73d5c8a9ac
commit ecbdd4f785

@ -21,10 +21,15 @@ const strikeM = require('../../models/strikes');
const isActive = await new Strikes(this.client).getAreStrikesActive(message.guildId); const isActive = await new Strikes(this.client).getAreStrikesActive(message.guildId);
if(!isActive) return new ErrorMessage(this.client).send(ErrorType.FeatureInnactive, message) if(!isActive) return new ErrorMessage(this.client).send(ErrorType.FeatureInnactive, message)
var confirm = await this.confirmArgs(message,args); 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.']) 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.','Make sure to only mention one person per strike.'])
const Stroked = message.mentions.users.toJSON()[0];
var strike = new strikeM(); var strike = new strikeM();
strike.strikerID = confirm.strikerID; strike.strikerID = message.author.id;
strike.strokedID = confirm.strokedID; strike.strikerName = message.author.username;
strike.strikerAvatar = message.author.avatar?message.author.avatar:'NOAVATAR';
strike.strokedID = Stroked.id;
strike.strokedName = Stroked.username;
strike.strokedAvatar = Stroked.avatar?Stroked.avatar: 'NOAVATAR';
strike.guildName = message.guild.name; strike.guildName = message.guild.name;
strike.guildID = message.guild.id strike.guildID = message.guild.id
strike.reason = confirm.reason; strike.reason = confirm.reason;
@ -33,20 +38,19 @@ const strikeM = require('../../models/strikes');
strike.save(err=> strike.save(err=>
{ {
if(err)console.log(err); if(err)console.log(err);
this.sendMessage(confirm.strokedID,confirm.reason); this.sendMessage(Stroked,confirm.reason);
message.delete(); message.delete();
}) })
} }
async sendMessage(strokedID, reason) async sendMessage(Stroked, reason)
{ {
let name = this.client.guilds.cache.get(this.message.guildId).members.cache.get(strokedID);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
embed.setFooter({text:'Rem-chan on ', iconURL:"https://i.imgur.com/g6FSNhL.png"}) 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.setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'});
embed.setColor(0x110809); embed.setColor(0x110809);
embed.setTimestamp() embed.setTimestamp()
embed.setTitle(`Strike`) embed.setTitle(`Strike`)
embed.setDescription(`${name} has been struck.`) embed.setDescription(`${Stroked.username} has been struck.`)
embed.addFields({name:'Reason:', value:reason}) embed.addFields({name:'Reason:', value:reason})
const row = new ActionRowBuilder() const row = new ActionRowBuilder()
@ -72,9 +76,9 @@ const strikeM = require('../../models/strikes');
async confirmArgs(message,args) async confirmArgs(message,args)
{ {
if(args.length<2) return 'Error' if(args.length<2) return 'Error'
if(!args[0].split('@')) return 'Error' if(!args[0].includes('@')) return 'Error'
let strikerID = message.author.id; if(args.join('').split('@').length>2) return 'Error'
let strokedID = args[0].split('@')[1].split('>')[0]; if(isNaN(args[0].replaceAll(/[<@>]/g, ''))) return 'Error'
return {strikerID, strokedID, reason:args.splice(-1,1).join(' ')} return {reason:args.splice(-1,1).join(' ')}
} }
}module.exports = strike; }module.exports = strike;

Loading…
Cancel
Save