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

Annotation of /trunk/commands/history.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Mon Jul 29 17:28:16 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 3168 byte(s)
More improvements
1 rakin 25 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.members.first();
19    
20     if (!user || user === null) {
21     try {
22     user = {
23     id: cm.args[0]
24     };
25     }
26     catch(e) {
27     console.log(e);
28     }
29     }
30    
31     if (!user || user === null) {
32     await msg.reply({
33     embeds: [
34     new MessageEmbed()
35     .setColor('#f14a60')
36     .setDescription(`Invalid user given.`)
37     ]
38     });
39    
40     return;
41     }
42    
43     let u = user;
44    
45     History.get(user.id, msg.guild, async (data) => {
46     let str = '';
47    
48     for await (let row of data) {
49     try {
50     var mod = await msg.guild.members.cache.find(m => m.id === row.mod_id).user.tag;
51     // = mod.user.tag;
52     var user = await msg.guild.members.cache.find(m => m.id === row.user_id).user.tag;
53     }
54     catch(e) {
55     console.log(e);
56     }
57    
58     if (!mod) {
59     console.log(mod);
60     mod = row.mod_id;
61     }
62     if (!user) {
63     user = row.user_id;
64     }
65    
66     str += `\`[${new Date(row.date).toLocaleString()}] [${mod}]`;
67     let type;
68    
69     if (row.type === 'ban') {
70     type = 'Banned';
71     }
72     else if (row.type === 'unban') {
73     type = 'Unbanned';
74     }
75     else if (row.type === 'kick') {
76     type = 'Kicked';
77     }
78     else if (row.type === 'mute') {
79     type = 'Muted';
80     }
81     else if (row.type === 'unmute') {
82     type = 'Unmuted';
83     }
84     else if (row.type === 'warn') {
85     type = 'Warned';
86     }
87     else if (row.type === 'warndel') {
88     type = 'Deleted warning for';
89     }
90    
91     str += ` ${type} ${user}\`\n`;
92     }
93    
94     let a = {
95     name: user === undefined ? (u.user?.tag !== undefined ? u.user.tag : u.id) : user,
96     };
97    
98     if (str === '') {
99     str = 'No history.';
100     }
101    
102     console.log(user);
103    
104     await msg.reply({
105     embeds: [
106     new MessageEmbed()
107     .setAuthor(a)
108     .setDescription(str)
109     ]
110     });
111     });
112     }
113     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26