Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions commands/Moderation/case.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@ const { Command } = require('klasa');

module.exports = class extends Command {

constructor(...args) {
super(...args, {
name: 'case',
permLevel: 4,
runIn: ['text'],
description: language => language.get('COMMAND_CASE_DESCRIPTION'),
usage: '<case:integer>'
});
}
constructor(...args) {
super(...args, {
name: 'case',
permLevel: 4,
runIn: ['text'],
description: language => language.get('COMMAND_CASE_DESCRIPTION'),
usage: '<case:integer>'
});
}

async run(msg, [selected]) {
const log = msg.guild.settings.modlogs[selected];
if (!log) return msg.send(`${msg.language.get('COMMAND_CASE_SORRY')} ${msg.author}, ${msg.language.get('COMMAND_CASE_NO')}`);
async run(msg, [caseNum]) {
const logs = await this.provider.get('modlogs', msg.guild.id);
const info = logs.infractions.find(infractions => infractions.case === caseNum);

const [user, moderator] = await Promise.all([
this.client.users.fetch(log.user),
this.client.users.fetch(log.moderator)
]);
return msg.send([
`User : ${user.tag} (${user.id})`,
`Moderator : ${moderator.tag} (${moderator.id})`,
`Reason : ${log.reason || `${msg.language.get('COMMAND_CASE_REASON')} '${msg.guild.settings.prefix}reason ${selected}' ${msg.language.get('COMMAND_CASE_CLAIM')}`}`
], { code: 'http' });
}
const user = this.client.users.get(info.user);
const moderator = this.client.users.get(info.moderator);

return msg.send([
`User : ${user.tag} (${user.id})`,
`Moderator : ${moderator.tag} (${moderator.id})`,
`Reason : ${info.reason || `${msg.language.get('COMMAND_CASE_REASON')} '${msg.guild.settings.prefix}reason ${caseNum}' ${msg.language.get('COMMAND_CASE_CLAIM')}`}`
], { code: 'http' });
}

get provider() {
return this.client.providers.default;
}
};
27 changes: 26 additions & 1 deletion posrednik.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ class Posrednik extends Client {

}

const client = new Posrednik();

client.gateways.register('modlogs', {
moderator: {
type: 'user',
default: null
},
user: {
type: 'user',
default: null
},
action: {
type: 'user',
default: null
},
timed: {
type: 'boolean',
default: false
},
duration: {
type: 'integer',
default: 0
}
});

// Logs the account in
// noinspection JSIgnoredPromiseFromCall
new Posrednik().login(config.token);
client.login(config.token);
28 changes: 23 additions & 5 deletions util/modlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = class ModLog {
this.user = null;
this.moderator = null;
this.reason = null;
this.timed = null;

this.case = null;
}
Expand Down Expand Up @@ -43,10 +44,15 @@ module.exports = class ModLog {
return this;
}

setTimed(value) {
this.timed = value;
return this;
}

// Checks if the modlog channel still exsists if not it throws an error to the console

async send() {
const channel = this.guild.channels.get(this.guild.settings.channels.modlog);
const channel = this.guild.channels.get(this.guild.settings.modlog);
if (!channel) throw 'The modlog channel does not exist, did it get deleted?';
await this.getCase();
return channel.send({ embed: this.embed });
Expand All @@ -61,7 +67,8 @@ module.exports = class ModLog {
.setDescription([
`**Type**: ${this.type[0].toUpperCase() + this.type.slice(1)}`,
`**User**: ${this.user.tag} (${this.user.id})`,
`**Reason**: ${this.reason || `Use \`${this.guild.settings.prefix}reason ${this.case}\` to claim this log.`}`
`**Reason**: ${this.reason || `Use \`${this.guild.settings.prefix}reason ${this.case}\` to claim this log.`}`,
`**Timed Infraction**: ${this.timed}`
])
.setFooter(`Case ${this.case}`)
.setTimestamp();
Expand All @@ -71,8 +78,14 @@ module.exports = class ModLog {
// Here we get the case number and create a modlog provider entry

async getCase() {
this.case = this.guild.settings.modlogs.length;
return this.guild.settings.update('modlogs', this.pack);
const modlogs = await this.provider.get('modlogs', this.guild.id);
if (!modlogs) {
this.case = 0;
return this.provider.create('modlogs', this.guild.id, { infractions: [this.pack] }).then(() => 0);
}
this.case = modlogs.infractions.length
modlogs.infractions.push(this.pack);
await this.provider.update('modlogs', this.guild.id, modlogs);
}

// Here we pack all the info together
Expand All @@ -83,10 +96,15 @@ module.exports = class ModLog {
user: this.user.id,
moderator: this.moderator.id,
reason: this.reason,
case: this.case
case: this.case,
timed: this.timed
};
}

get provider() {
return this.client.providers.default;
}

// And here we just define the color for a certain type of offence or action

static colour(type) {
Expand Down