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
|
import { AllowedMentions, BushCommand, Global, type BushMessage, type BushSlashMessage } from '@lib';
export default class DisableCommand extends BushCommand {
public constructor() {
super('disable', {
aliases: ['disable', 'enable'],
category: 'config',
description: {
content: 'A command to disable and enable commands.',
usage: ['disable|enable <command>'],
examples: ['enable ban', 'disable kick']
},
args: [
{
id: 'command',
customType: util.arg.union('commandAlias', 'command'),
prompt: {
start: 'What command would you like to enable/disable?',
retry: '{error} Pick a valid command.',
optional: false
}
},
{
id: 'global',
match: 'flag',
flag: '--global'
}
],
slash: true,
slashOptions: [
{
name: 'action',
description: 'Would you like to disable or enable a command?',
type: 'STRING',
choices: [
{
name: 'enable',
value: 'enable'
},
{
name: 'disable',
value: 'disable'
}
],
required: true
},
{
name: 'command',
description: 'What command would you like to enable/disable?',
type: 'STRING',
required: true
}
],
channel: 'guild',
clientPermissions: (m) => util.clientSendAndPermCheck(m),
userPermissions: ['MANAGE_GUILD']
});
}
blacklistedCommands = ['eval', 'disable'];
public override async exec(
message: BushMessage | BushSlashMessage,
args: { action: 'enable' | 'disable'; command: BushCommand | string; global: boolean }
) {
let action = (args.action ?? message?.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle';
const global = args.global && message.author.isOwner();
const commandID = (args.command as BushCommand).id;
if (global) {
if (action === 'toggle') {
const disabledCommands = (
(await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment }))
).disabledCommands;
action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
}
const success = await util
.insertOrRemoveFromGlobal(action === 'disable' ? 'remove' : 'add', 'disabledCommands', commandID)
.catch(() => false);
if (!success)
return await message.util.reply({
content: `${util.emojis.error} There was an error globally **${action.substr(
0,
action.length - 2
)}ing** the **${commandID}** command.`,
allowedMentions: AllowedMentions.none()
});
else
return await message.util.reply({
content: `${util.emojis.success} Successfully **${action.substr(
0,
action.length - 2
)}ed** the **${commandID}** command globally.`,
allowedMentions: AllowedMentions.none()
});
// guild disable
} else {
const disabledCommands = await message.guild!.getSetting('disabledCommands');
if (action === 'toggle') {
action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
}
const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'remove' : 'add', disabledCommands, commandID);
const success = await message.guild!.setSetting('disabledCommands', newValue, message.member!).catch(() => false);
if (!success)
return await message.util.reply({
content: `${util.emojis.error} There was an error **${action.substr(
0,
action.length - 2
)}ing** the **${commandID}** command.`,
allowedMentions: AllowedMentions.none()
});
else
return await message.util.reply({
content: `${util.emojis.success} Successfully **${action.substr(
0,
action.length - 2
)}ed** the **${commandID}** command.`,
allowedMentions: AllowedMentions.none()
});
}
}
}
|