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.getString('id'); |
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) { |
guild_id: msg.guild!.id, |
45 |
console.log(err); |
_id: id |
46 |
} |
}); |
|
|
|
|
if (data === undefined) { |
|
|
await msg.reply({ |
|
|
embeds: [ |
|
|
new MessageEmbed() |
|
|
.setColor('#f14a60') |
|
|
.setDescription('No note found') |
|
|
] |
|
|
}); |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
let user; |
|
|
|
|
|
try { |
|
|
user = await msg.guild!.members.fetch(data.user_id); |
|
|
user = { |
|
|
name: user.user.tag, |
|
|
iconURL: user.displayAvatarURL() |
|
|
}; |
|
|
} |
|
|
catch(e) { |
|
|
user = { |
|
|
name: "User " + data.user_id |
|
|
}; |
|
|
} |
|
47 |
|
|
48 |
await msg.reply({ |
if (!note) { |
49 |
embeds: [ |
await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`); |
50 |
new MessageEmbed() |
return; |
51 |
.setDescription(data.content) |
} |
52 |
.setAuthor(user) |
|
53 |
.setFields([ |
let user; |
54 |
|
|
55 |
|
try { |
56 |
|
user = await client.users.fetch(note.user_id); |
57 |
|
} |
58 |
|
catch (e) { |
59 |
|
console.log(e); |
60 |
|
} |
61 |
|
|
62 |
|
await msg.reply({ |
63 |
|
embeds: [ |
64 |
|
new MessageEmbed({ |
65 |
|
author: { |
66 |
|
name: user?.tag ?? note.user_id, |
67 |
|
iconURL: user instanceof User ? user.displayAvatarURL() : undefined, |
68 |
|
}, |
69 |
|
description: note.content, |
70 |
|
fields: [ |
71 |
{ |
{ |
72 |
name: "ID", |
name: 'Note taken by', |
73 |
value: data.id + '' |
value: note.mod_tag |
74 |
} |
} |
75 |
]) |
], |
76 |
.setTimestamp(new Date(data.date)) |
footer: { |
77 |
] |
text: `ID: ${note.id}` |
78 |
}); |
}, |
79 |
|
timestamp: note.createdAt |
80 |
|
}) |
81 |
|
] |
82 |
}); |
}); |
|
|
|
83 |
} |
} |
84 |
} |
} |