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

Annotation of /trunk/commands/ban.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (hide annotations)
Mon Jul 29 17:28:18 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 3922 byte(s)
Fixed issues and improved logging
1 rakin 25 const History = require("../src/History");
2 rakin 5 const MessageEmbed = require("../src/MessageEmbed");
3    
4     module.exports = {
5     async handle(msg, cm) {
6     if (typeof cm.args[0] === 'undefined') {
7     await msg.reply({
8     embeds: [
9     new MessageEmbed()
10     .setColor('#f14a60')
11     .setDescription(`This command requires at least one argument.`)
12     ]
13     });
14    
15     return;
16     }
17    
18 rakin 25 var user = await msg.mentions.users.first();
19 rakin 37 const argFirst = cm.args.slice(0, 3);
20 rakin 5
21 rakin 37 const banOptions = {};
22 rakin 5
23 rakin 37 console.log(argFirst);
24    
25     // log to #mod-logs
26     // update help command
27 rakin 5
28 rakin 37 if (!user) {
29 rakin 5 try {
30 rakin 37 user = await app.client.users.fetch(argFirst[0]);
31 rakin 5 }
32 rakin 37 catch (e) {
33     console.log(e);
34 rakin 5
35 rakin 37 await msg.reply({
36     embeds: [
37     new MessageEmbed()
38     .setColor('#f14a60')
39     .setDescription(`Invalid user given.`)
40     ]
41     });
42    
43     return;
44 rakin 5 }
45     }
46    
47 rakin 37 const pos = argFirst.indexOf('-d');
48     let length = argFirst.length;
49    
50     if (pos !== -1) {
51     const days = argFirst[pos + 1];
52 rakin 5
53 rakin 37 if (days === undefined || !parseInt(days)) {
54     await msg.reply({
55     embeds: [
56     new MessageEmbed()
57     .setColor('#f14a60')
58     .setDescription(`Option \`-d\` requires a valid numeric argument.`)
59     ]
60     });
61    
62     return;
63     }
64    
65     if (days < 0 || days > 7) {
66     await msg.reply({
67     embeds: [
68     new MessageEmbed()
69     .setColor('#f14a60')
70     .setDescription(`Days must be in range 0-7.`)
71     ]
72     });
73    
74     return;
75     }
76    
77     banOptions.days = parseInt(days);
78     argFirst.splice(1, 2);
79 rakin 5 }
80 rakin 37 else {
81     length = 1;
82     }
83 rakin 5
84 rakin 37 const args1 = [...cm.args];
85     args1.splice(0, length);
86     const reason = args1.join(' ');
87    
88     if (reason.trim() !== '') {
89     banOptions.reason = reason;
90     }
91    
92     console.log(argFirst, banOptions);
93    
94 rakin 5 try {
95     if (typeof user.bannable === 'boolean' && user.bannable === false) {
96     await msg.reply({
97     embeds: [
98     new MessageEmbed()
99     .setColor('#f14a60')
100     .setDescription(`This user isn't bannable.`)
101     ]
102     });
103    
104     return;
105     }
106    
107 rakin 37 await History.create(user.id, msg.guild, 'ban', msg.author.id, typeof banOptions.reason === 'undefined' ? null : banOptions.reason, async (data2) => {
108     await msg.guild.bans.create(user.id, banOptions);
109 rakin 25 });
110 rakin 5 }
111     catch(e) {
112     console.log(e);
113    
114     await msg.reply({
115     embeds: [
116     new MessageEmbed()
117     .setColor('#f14a60')
118     .setDescription(`I don't have enough permission to ban this user.`)
119     ]
120     });
121    
122     return;
123     }
124    
125     await msg.reply({
126     embeds: [
127     new MessageEmbed()
128 rakin 25 .setDescription(`The user ${user.tag} has been banned`)
129 rakin 5 .addFields([
130     {
131     name: "Reason",
132 rakin 37 value: typeof banOptions.reason === 'undefined' ? '*No reason provided*' : banOptions.reason
133 rakin 5 }
134     ])
135     ]
136     });
137     }
138     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26