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

Contents of /trunk/commands/history.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (show annotations)
Mon Jul 29 17:28:18 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 3334 byte(s)
Fixed issues and improved logging
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.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}]**\n`;
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 === 'bean') {
85 type = 'Beaned';
86 }
87 else if (row.type === 'warn') {
88 type = 'Warned';
89 }
90 else if (row.type === 'warndel') {
91 type = 'Deleted warning for';
92 }
93
94 str += ` ${type} ${user} [Reason: ${row.reason == null ? 'No reason' : row.reason}]\n\n`;
95 }
96
97 let a = {
98 name: user === undefined ? (u.user?.tag !== undefined ? u.user.tag : u.id) : user,
99 };
100
101 if (str === '') {
102 str = 'No history.';
103 }
104
105 console.log(user);
106
107 await msg.reply({
108 embeds: [
109 new MessageEmbed()
110 .setAuthor(a)
111 .setDescription(str)
112 ]
113 });
114 });
115 }
116 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26