2023-02-11 23:49:24 -05:00
|
|
|
import { Member, User } from 'eris';
|
2021-12-23 22:36:13 -05:00
|
|
|
import { createPaginationEmbed } from 'eris-pagination';
|
2023-02-11 23:49:24 -05:00
|
|
|
import { Command, Client, RichEmbed, CmdContext } from '../class';
|
2021-12-23 22:36:13 -05:00
|
|
|
|
|
|
|
export default class Notes extends Command {
|
|
|
|
constructor(client: Client) {
|
|
|
|
super(client);
|
|
|
|
this.name = 'notes';
|
|
|
|
this.description = 'Pulls up notes for a member, with an optional categorical filter.';
|
|
|
|
this.usage = `${this.client.config.prefix}notes <member> [filter: comm | cs | edu]`;
|
|
|
|
this.permissions = 1;
|
|
|
|
this.guildOnly = true;
|
|
|
|
this.enabled = true;
|
|
|
|
}
|
|
|
|
|
2023-02-11 23:49:24 -05:00
|
|
|
public async run(ctx: CmdContext) {
|
|
|
|
if (!ctx.args[0]) return this.client.commands.get('help').run(new CmdContext(ctx.message, [this.name]));
|
|
|
|
let member: Member | User = this.client.util.resolveMember(ctx.args[0], this.mainGuild);
|
2022-03-22 12:15:54 -04:00
|
|
|
if (!member) {
|
|
|
|
try {
|
2023-02-11 23:49:24 -05:00
|
|
|
member = await this.client.getRESTUser(ctx.args[0]);
|
2022-03-22 12:15:54 -04:00
|
|
|
} catch {
|
|
|
|
member = undefined;
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
2022-03-22 12:15:54 -04:00
|
|
|
}
|
2023-02-11 23:49:24 -05:00
|
|
|
if (!member) return this.error(ctx.message.channel, 'User specified could not be found.');
|
2021-12-23 22:36:13 -05:00
|
|
|
|
2022-03-22 12:15:54 -04:00
|
|
|
const notes = await this.client.db.mongo.Note.find({ userID: member.id });
|
2023-02-11 23:49:24 -05:00
|
|
|
if (!notes || notes?.length < 1) return this.error(ctx.message.channel, 'No notes exist for this user.');
|
2021-12-23 22:36:13 -05:00
|
|
|
|
2022-03-22 12:15:54 -04:00
|
|
|
const noteArray: [{ name: string, value: string, inline: boolean }?] = [];
|
2023-02-11 23:49:24 -05:00
|
|
|
if (ctx.args[1] === 'comm' || ctx.args[1] === 'cs' || ctx.args[1] === 'edu') {
|
|
|
|
switch (ctx.args[1]) {
|
2022-03-22 12:15:54 -04:00
|
|
|
case 'comm':
|
|
|
|
for (const note of notes.sort((a, b) => b.date.getTime() - a.date.getTime()).filter((r) => r.category === 'comm')) {
|
|
|
|
noteArray.push({
|
|
|
|
name: `${note._id}${note.category === '' ? '' : `, ${note.category.toUpperCase()}`} | ${note.date.toLocaleString('en-us')} ET | Staff: ${this.client.users.get(note.staffID) ? `${this.client.users.get(note.staffID).username}#${this.client.users.get(note.staffID).discriminator}` : 'N/A'}`,
|
|
|
|
value: note.text,
|
|
|
|
inline: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'cs':
|
|
|
|
for (const note of notes.sort((a, b) => b.date.getTime() - a.date.getTime()).filter((r) => r.category === 'cs')) {
|
|
|
|
noteArray.push({
|
|
|
|
name: `${note._id}${note.category === '' ? '' : `, ${note.category.toUpperCase()}`} | ${note.date.toLocaleString('en-us')} ET | Staff: ${this.client.users.get(note.staffID) ? `${this.client.users.get(note.staffID).username}#${this.client.users.get(note.staffID).discriminator}` : 'N/A'}`,
|
|
|
|
value: note.text,
|
|
|
|
inline: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'edu':
|
|
|
|
for (const note of notes.sort((a, b) => b.date.getTime() - a.date.getTime()).filter((r) => r.category === 'edu')) {
|
|
|
|
noteArray.push({
|
|
|
|
name: `${note._id}${note.category === '' ? '' : `, ${note.category.toUpperCase()}`}} | ${note.date.toLocaleString('en-us')} ET | Staff: Staff: ${this.client.users.get(note.staffID) ? `${this.client.users.get(note.staffID).username}#${this.client.users.get(note.staffID).discriminator}` : 'N/A'}`,
|
|
|
|
value: note.text,
|
|
|
|
inline: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const note of notes.sort((a, b) => b.date.getTime() - a.date.getTime())) {
|
|
|
|
noteArray.push({
|
|
|
|
name: `${note._id}${note.category === '' ? '' : `, ${note.category}`} | ${note.date.toLocaleString('en-us')} ET | Staff: ${this.client.users.get(note.staffID) ? `${this.client.users.get(note.staffID).username}#${this.client.users.get(note.staffID).discriminator}` : 'N/A'}`,
|
|
|
|
value: note.text,
|
|
|
|
inline: true,
|
|
|
|
});
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 12:15:54 -04:00
|
|
|
const noteSplit = this.client.util.splitFields(noteArray);
|
|
|
|
const cmdPages: RichEmbed[] = [];
|
|
|
|
noteSplit.forEach((split) => {
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
embed.setColor('#0000FF');
|
|
|
|
embed.setAuthor(`${member.username}#${member.discriminator}`, member.avatarURL);
|
|
|
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
|
|
|
embed.setTimestamp();
|
|
|
|
split.forEach((c) => embed.addField(c.name, c.value, c.inline));
|
|
|
|
return cmdPages.push(embed);
|
|
|
|
});
|
2023-02-11 23:49:24 -05:00
|
|
|
if (cmdPages.length === 1) return ctx.message.channel.createMessage({ embed: cmdPages[0] });
|
|
|
|
return createPaginationEmbed(ctx.message, cmdPages);
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
|
|
|
}
|