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[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 |
var user = await msg.mentions.users.first(); |
19 |
const argFirst = cm.args.slice(0, 3); |
20 |
|
21 |
const banOptions = {}; |
22 |
|
23 |
console.log(argFirst); |
24 |
|
25 |
// log to #mod-logs |
26 |
// update help command |
27 |
|
28 |
if (!user) { |
29 |
try { |
30 |
user = await app.client.users.fetch(argFirst[0]); |
31 |
} |
32 |
catch (e) { |
33 |
console.log(e); |
34 |
|
35 |
await msg.reply({ |
36 |
embeds: [ |
37 |
new MessageEmbed() |
38 |
.setColor('#f14a60') |
39 |
.setDescription(`Invalid user given.`) |
40 |
] |
41 |
}); |
42 |
|
43 |
return; |
44 |
} |
45 |
} |
46 |
|
47 |
const pos = argFirst.indexOf('-d'); |
48 |
let length = argFirst.length; |
49 |
|
50 |
if (pos !== -1) { |
51 |
const days = argFirst[pos + 1]; |
52 |
|
53 |
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 |
} |
80 |
else { |
81 |
length = 1; |
82 |
} |
83 |
|
84 |
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 |
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 |
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 |
}); |
110 |
} |
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 |
.setDescription(`The user ${user.tag} has been banned`) |
129 |
.addFields([ |
130 |
{ |
131 |
name: "Reason", |
132 |
value: typeof banOptions.reason === 'undefined' ? '*No reason provided*' : banOptions.reason |
133 |
} |
134 |
]) |
135 |
] |
136 |
}); |
137 |
} |
138 |
}; |