/[sudobot]/trunk/commands/note.js
ViewVC logotype

Contents of /trunk/commands/note.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (show annotations)
Mon Jul 29 17:28:18 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 1813 byte(s)
Fixed issues and improved logging
1 const History = require("../src/History");
2 const MessageEmbed = require("../src/MessageEmbed");
3
4 module.exports = {
5 async handle(msg, cm) {
6 if (typeof cm.args[1] === 'undefined') {
7 await msg.reply({
8 embeds: [
9 new MessageEmbed()
10 .setColor('#f14a60')
11 .setDescription(`This command requires at least two arguments.`)
12 ]
13 });
14
15 return;
16 }
17
18 var user = await msg.mentions.members.first();
19 let content;
20
21 let args = [...cm.args];
22 args.shift();
23
24 await (content = args.join(' '));
25
26 if (typeof user !== 'object') {
27 try {
28 user = await msg.guild.members.fetch(cm.args[0]);
29 }
30 catch(e) {
31
32 }
33 }
34
35 if (typeof user !== 'object') {
36 await msg.reply({
37 embeds: [
38 new MessageEmbed()
39 .setColor('#f14a60')
40 .setDescription(`Invalid user given.`)
41 ]
42 });
43
44 return;
45 }
46
47 await History.create(user.id, msg.guild, 'note', msg.author.id, null, async (data2) => {
48 this.note(user, content, msg);
49 });
50
51 await msg.reply({
52 embeds: [
53 new MessageEmbed()
54 .setDescription(`A note has been added for ${user.user.tag}`) // TODO
55 ]
56 });
57 },
58 async note(user, content, msg) {
59 await app.db.get("INSERT INTO notes(user_id, guild_id, content, date) VALUES(?, ?, ?, ?)", [user.id, msg.guild.id, content, (new Date().toISOString())], async (err) => {
60 if (err) {
61 console.log(err);
62 }
63 });
64 }
65 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26