75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
const { stripIndents } = require('common-tags');
|
|
|
|
class Infraction {
|
|
|
|
constructor(client, opts = {}) {
|
|
|
|
this.client = client;
|
|
|
|
this.target = opts.target; //User or channel being targeted.
|
|
this.targetType = opts.targetType; // 'user' or 'channel'.
|
|
this.executor = opts.executor; //Whoever executed the command.
|
|
|
|
this.guild = opts.guild;
|
|
this.channel = opts.channel;
|
|
|
|
this.case = null;
|
|
this.type = opts.type; //What type of infraction (mute, kick, etc.)
|
|
|
|
this.timestamp = new Date().getTime();
|
|
this.duration = opts.duration || null; //How long the event will last. Must be in milliseconds.
|
|
this.expiration = opts.duration ? opts.duration + this.timestamp : null; //When the event will expire
|
|
this.reason = opts.reason;
|
|
|
|
this.color = opts.color; //Infraction-defined hexadecimal value to dictate what color the embed is.
|
|
this.dictionary = opts.dictionary || {}; // { past: 'banned', present: 'ban' } Infraction-defined object for the correct spellings.
|
|
|
|
this._resolved = false;
|
|
|
|
}
|
|
|
|
async resolve(opts) {
|
|
|
|
|
|
|
|
}
|
|
|
|
async save() {
|
|
|
|
await this.client.transactionHandler.send({
|
|
provider: 'mongodb',
|
|
request: {
|
|
type: 'insertOne',
|
|
data: this._json
|
|
}
|
|
}).catch(console.error);
|
|
|
|
}
|
|
|
|
get _json() {
|
|
return {
|
|
id: `${this.guild.id}:${this.case}`,
|
|
guild: this.guild.id,
|
|
channel: this.channel ? this.channel.id : null,
|
|
message: this.message ? this.message.id : null,
|
|
executor: this.executor.id,
|
|
target: this.target.id,
|
|
targetType: this.targetType,
|
|
type: this.type,
|
|
case: this.case,
|
|
duration: this.duration,
|
|
expiration: this.expiration,
|
|
reason: this.reason,
|
|
timestamp: this.timestamp,
|
|
};
|
|
}
|
|
|
|
get targetName() {
|
|
return this.targetType === 'user'
|
|
? this.target.tag
|
|
: `#${this.target.name}`;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Infraction; |