1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
import { stripIndent } from 'common-tags';
import { Argument } from 'discord-akairo';
import { Message, MessageEmbed } from 'discord.js';
import moment from 'moment';
import { BushCommand } from '../../lib/extensions/BushCommand';
import { ModLog } from '../../lib/models';
export default class ModlogCommand extends BushCommand {
constructor() {
super('modlog', {
aliases: ['modlog', 'modlogs'],
category: 'moderation',
args: [
{
id: 'search',
prompt: {
start: 'What modlog id or user would you like to see?'
}
},
{
id: 'page',
type: 'number'
}
],
userPermissions: ['MANAGE_MESSAGES'],
description: {
content: "View a user's modlogs, or view a specific modlog entry",
usage: 'warn <search> [page]',
examples: ['modlogs @Tyman', 'modlogs @Tyman 3']
}
});
}
*args(): unknown {
const search = yield {
id: 'search',
type: Argument.union('user', 'string'),
prompt: {
start: 'What modlog id or user would you like to see?',
retry: '{error} Choose a valid modlog id or user.'
}
};
if (typeof search === 'string') return { search, page: null };
else {
const page = yield {
id: 'page',
type: 'number',
prompt: {
start: 'What page?',
retry: '{error} Choose a valid page to view.',
optional: true
}
};
return { search, page };
}
}
async exec(message: Message, { search, page }: { search: string; page: number }): Promise<void> {
const foundUser = await this.client.util.resolveUserAsync(search);
if (foundUser) {
const logs = await ModLog.findAll({
where: {
guild: message.guild.id,
user: foundUser.id
},
order: [['createdAt', 'ASC']]
});
const niceLogs: string[] = [];
for (const log of logs) {
niceLogs.push(stripIndent`
**Case ID**: ${log.id}
**Type**: ${log.type.toLowerCase()}
**User**: <@!${log.user}> (${log.user})
**Moderator**: <@!${log.moderator}> (${log.moderator})
**Duration**: ${log.duration ? moment.duration(log.duration, 'milliseconds').humanize() : 'N/A'}
**Reason**: ${log.reason || 'None given'}
**${this.client.util.ordinal(logs.indexOf(log) + 1)}** action
`);
}
const chunked: string[][] = this.client.util.chunk(niceLogs, 3);
const embedPages = chunked.map(
(e, i) =>
new MessageEmbed({
title: foundUser.tag,
description: e.join('\n**---------------------------**\n'),
footer: {
text: `Page ${i + 1}/${chunked.length}`
},
color: this.client.util.colors.default
})
);
if (page) {
await message.util.send({ embeds: [embedPages[page - 1]] });
return;
} else {
await message.util.send({ embeds: [embedPages[0]] });
return;
}
} else if (search) {
const entry = await ModLog.findByPk(search);
if (!entry) {
await message.util.send(`${this.client.util.emojis.error} That modlog does not exist.`);
return;
}
await message.util.send({
embeds: [
new MessageEmbed({
title: `${entry.id}`,
fields: [
{
name: 'Type',
value: entry.type.toLowerCase(),
inline: true
},
{
name: 'Duration',
value: `${entry.duration ? moment.duration(entry.duration, 'milliseconds').humanize() : 'N/A'}`,
inline: true
},
{
name: 'Reason',
value: `${entry.reason || 'None given'}`,
inline: true
},
{
name: 'Moderator',
value: `<@!${entry.moderator}> (${entry.moderator})`,
inline: true
},
{
name: 'User',
value: `<@!${entry.user}> (${entry.user})`,
inline: true
}
]
})
]
});
}
}
}
|