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

Diff of /trunk/commands/ban.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by rakin, Mon Jul 29 17:28:11 2024 UTC revision 37 by rakin, Mon Jul 29 17:28:18 2024 UTC
# Line 1  Line 1 
1    const History = require("../src/History");
2  const MessageEmbed = require("../src/MessageEmbed");  const MessageEmbed = require("../src/MessageEmbed");
3    
4  module.exports = {  module.exports = {
# Line 14  module.exports = { Line 15  module.exports = {
15              return;              return;
16          }          }
17    
18          var user = await msg.mentions.members.first();          var user = await msg.mentions.users.first();
19          let reason = {};          const argFirst = cm.args.slice(0, 3);
20    
21          if (typeof cm.args[1] !== 'undefined') {          const banOptions = {};
             let args = [...cm.args];  
             args.shift();  
22    
23              await (reason.reason = args.join(' '));          console.log(argFirst);
24          }          
25            // log to #mod-logs
26            // update help command
27    
28          if (typeof user !== 'object') {          if (!user) {
29              try {              try {
30                  user = await msg.guild.members.fetch(cm.args[0]);                  user = await app.client.users.fetch(argFirst[0]);
31              }              }
32              catch(e) {              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          if (typeof user !== 'object') {          const pos = argFirst.indexOf('-d');
48              await msg.reply({          let length = argFirst.length;
49                  embeds: [          
50                      new MessageEmbed()          if (pos !== -1) {
51                      .setColor('#f14a60')              const days = argFirst[pos + 1];
                     .setDescription(`Invalid user given.`)  
                 ]  
             });  
52    
53              return;              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 {          try {
95              if (typeof user.bannable === 'boolean' && user.bannable === false) {              if (typeof user.bannable === 'boolean' && user.bannable === false) {
# Line 58  module.exports = { Line 104  module.exports = {
104                  return;                  return;
105              }              }
106    
107              await user.ban(reason);              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) {          catch(e) {
112              console.log(e);              console.log(e);
# Line 77  module.exports = { Line 125  module.exports = {
125          await msg.reply({          await msg.reply({
126              embeds: [              embeds: [
127                  new MessageEmbed()                  new MessageEmbed()
128                  .setDescription(`The user ${user.user.tag} has been banned`)                  .setDescription(`The user ${user.tag} has been banned`)
129                  .addFields([                  .addFields([
130                      {                      {
131                          name: "Reason",                          name: "Reason",
132                          value: typeof reason.reason === 'undefined' ? '*No reason provided*' : reason.reason                          value: typeof banOptions.reason === 'undefined' ? '*No reason provided*' : banOptions.reason
133                      }                      }
134                  ])                  ])
135              ]              ]

Legend:
Removed from v.5  
changed lines
  Added in v.37

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26