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

Annotation of /trunk/commands/warn.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (hide annotations)
Mon Jul 29 17:28:21 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 4164 byte(s)
Release version 1.10.0

* Added -queues command to list all queued jobs
* Added -joke command to fetch random jokes
* Added support of user tags in some user-based commands
1 rakin 25 const History = require("../src/History");
2 rakin 5 const MessageEmbed = require("../src/MessageEmbed");
3 rakin 49 const { getUser } = require("../src/UserInput");
4 rakin 5
5     module.exports = {
6     async handle(msg, cm) {
7     if (typeof cm.args[0] === 'undefined') {
8     await msg.reply({
9     embeds: [
10     new MessageEmbed()
11     .setColor('#f14a60')
12     .setDescription(`This command requires at least one argument.`)
13     ]
14     });
15    
16     return;
17     }
18 rakin 49
19     try {
20     var user = await getUser(cm.args[0], msg);
21 rakin 5
22 rakin 49 console.log(user);
23 rakin 5
24 rakin 49 if (!user) {
25     throw new Error('Invalid User');
26 rakin 5 }
27     }
28 rakin 49 catch (e) {
29     console.log(e);
30 rakin 5
31     await msg.reply({
32     embeds: [
33     new MessageEmbed()
34     .setColor('#f14a60')
35     .setDescription(`Invalid user given.`)
36     ]
37     });
38    
39     return;
40     }
41    
42 rakin 49 let reason;
43    
44     if (typeof cm.args[1] !== 'undefined') {
45     let args = [...cm.args];
46     args.shift();
47    
48     await (reason = args.join(' '));
49     }
50    
51 rakin 5 await this.warn(user, reason, msg, async (data) => {
52     await msg.reply({
53     embeds: [
54     new MessageEmbed()
55     .setDescription(`The user ${user.user.tag} has been warned`)
56     .addFields([
57     {
58     name: "Reason",
59     value: typeof reason === 'undefined' ? '*No reason provided*' : reason
60     },
61     {
62     name: "Strike",
63     value: data.count + ' time(s)'
64     },
65     {
66     name: "ID",
67     value: data.id + ''
68     }
69     ])
70     ]
71     });
72    
73     console.log(data);
74     });
75     },
76 rakin 10 async warn(user, reason, msg, callback, warned_by1) {
77     await app.db.get('INSERT INTO warnings(user_id, guild_id, strike, reason, warned_by) VALUES(?, ?, 1, ?, ?)', [user.id, msg.guild.id, reason === undefined ? '\c\b\c' : reason, warned_by1 === undefined ? msg.author.id : warned_by1], async (err) => {
78 rakin 5 if (err) {
79     console.log(err);
80     }
81    
82     await app.db.get('SELECT id, user_id, guild_id, COUNT(*) AS count FROM warnings WHERE user_id = ? AND guild_id = ? ORDER BY id DESC LIMIT 0, 1', [user.id, msg.guild.id], async (err, data) => {
83     if (err) {
84     console.log(err);
85     }
86    
87 rakin 25 console.log('fr');
88    
89     await app.logger.logWarn(msg, user, warned_by1 === undefined ? msg.author : warned_by1, typeof reason === 'undefined' ? '*No reason provided*' : reason);
90    
91 rakin 37 await History.create(user.id, msg.guild, 'warn', warned_by1 === undefined ? msg.author.id : warned_by1.id, typeof reason === 'undefined' ? null : reason, async (data2) => {
92 rakin 25 await user.send({
93     embeds: [
94     new MessageEmbed()
95     .setAuthor({
96     iconURL: msg.guild.iconURL(),
97     name: `\tYou have been warned in ${msg.guild.name}`
98     })
99     .addFields([
100     {
101     name: "Reason",
102     value: typeof reason === 'undefined' ? '*No reason provided*' : reason
103     },
104     {
105     name: "Strike",
106     value: data.count + ' time(s)'
107     }
108     ])
109     ]
110     });
111    
112     callback(data);
113 rakin 5 });
114     });
115     });
116     }
117     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26