8 |
import History from '../../automod/History'; |
import History from '../../automod/History'; |
9 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
10 |
import ms from 'ms'; |
import ms from 'ms'; |
11 |
|
import { fetchEmojiStr } from '../../utils/Emoji'; |
12 |
|
import Note from '../../models/Note'; |
13 |
|
|
14 |
export default class NotegetCommand extends BaseCommand { |
export default class NotegetCommand extends BaseCommand { |
15 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
34 |
let id: string; |
let id: string; |
35 |
|
|
36 |
if (options.isInteraction) { |
if (options.isInteraction) { |
37 |
id = await options.options.getNumber('id')?.toString()!; |
id = await <string> options.options.getNumber('id')?.toString(); |
38 |
} |
} |
39 |
else { |
else { |
40 |
id = options.args[0]; |
id = await options.args[0]; |
41 |
} |
} |
42 |
|
|
43 |
await client.db.get("SELECT * FROM notes WHERE id = ? AND guild_id = ?", [[id], msg.guild!.id], async (err: any, data: any) => { |
const note = await Note.findOne({ |
44 |
if (err) { |
where: { |
45 |
console.log(err); |
guild_id: msg.guild!.id, |
46 |
|
id |
47 |
} |
} |
48 |
|
}); |
49 |
|
|
50 |
if (data === undefined) { |
if (!note) { |
51 |
await msg.reply({ |
await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`); |
52 |
embeds: [ |
return; |
53 |
new MessageEmbed() |
} |
|
.setColor('#f14a60') |
|
|
.setDescription('No note found') |
|
|
] |
|
|
}); |
|
|
|
|
|
return; |
|
|
} |
|
54 |
|
|
55 |
let user; |
let user; |
56 |
|
|
57 |
try { |
try { |
58 |
user = await msg.guild!.members.fetch(data.user_id); |
user = await client.users.fetch(note.get().user_id); |
59 |
user = { |
} |
60 |
name: user.user.tag, |
catch (e) { |
61 |
iconURL: user.displayAvatarURL() |
console.log(e); |
62 |
}; |
} |
|
} |
|
|
catch(e) { |
|
|
user = { |
|
|
name: "User " + data.user_id |
|
|
}; |
|
|
} |
|
63 |
|
|
64 |
await msg.reply({ |
await msg.reply({ |
65 |
embeds: [ |
embeds: [ |
66 |
new MessageEmbed() |
new MessageEmbed({ |
67 |
.setDescription(data.content) |
author: { |
68 |
.setAuthor(user) |
name: user?.tag ?? note.get().user_id, |
69 |
.setFields([ |
iconURL: user instanceof User ? user.displayAvatarURL() : undefined, |
70 |
|
}, |
71 |
|
description: note.get().content, |
72 |
|
fields: [ |
73 |
{ |
{ |
74 |
name: "ID", |
name: 'Note taken by', |
75 |
value: data.id + '' |
value: note.get().mod_tag |
76 |
} |
} |
77 |
]) |
], |
78 |
.setTimestamp(new Date(data.date)) |
footer: { |
79 |
] |
text: `ID: ${note.get().id}` |
80 |
}); |
}, |
81 |
|
timestamp: note.get().createdAt |
82 |
|
}) |
83 |
|
] |
84 |
}); |
}); |
|
|
|
85 |
} |
} |
86 |
} |
} |