forked from GeorgeCiesinski/poke-guesser-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.js
344 lines (341 loc) · 12.2 KB
/
settings.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
const { ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js');
const language = require('./language.js');
const util = require('./util.js');
async function settings(interaction, db) {
await interaction.deferReply({ ephemeral: true }); // PokeBot is thinking
const lang = await language.getLanguage(interaction.guildId, db);
if (!interaction.guild.available)
return;
// https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags
console.log(`Owner:${interaction.guild.ownerId == interaction.user.id}; Administrator:${interaction.memberPermissions?.has('Administrator', false)}`);
if (interaction.guild.ownerId != interaction.user.id/*Owner*/ && !interaction.memberPermissions?.has('Administrator', false)/*Administrator-Permission*/) {
interaction.editReply({
embeds: [util.returnEmbed(lang.obj['settings_command_forbidden_error_title'], lang.obj['settings_command_forbidden_error_description'])],
ephemeral: true
});
return;
}
let title = '';
let description = '';
let subcommandgroup = null;
const subcommand = interaction.options.getSubcommand();
switch (subcommand) {
case 'add':
subcommandgroup = interaction.options.getSubcommandGroup(false);
switch (subcommandgroup) {
case 'mods': // /settings mods add
try {
await db.addMod(interaction.options.getMentionable('mentionable'));
title = lang.obj['settings_mods_add_title_success'];
description = lang.obj['settings_mods_add_description_success'];
} catch (err) {
title = lang.obj['settings_mods_add_title_failed'];
description = `${lang.obj['settings_mods_add_description_failed']}${err}`;
}
break;
case 'channels': // /settings channels add
try {
await db.addChannel(interaction.options.getChannel('channel'));
title = lang.obj['settings_channels_add_title_success'];
description = lang.obj['settings_channels_add_description_success'];
} catch (err) {
title = lang.obj['settings_channels_add_title_failed'];
description = `${lang.obj['settings_channels_add_description_failed']}${err}`;
}
break;
default:
break;
}
break;
case 'remove':
subcommandgroup = interaction.options.getSubcommandGroup(false);
switch (subcommandgroup) {
case 'mods': // /settings mods remove
try {
await db.removeMod(interaction.options.getMentionable('mentionable'));
title = lang.obj['settings_mods_remove_title_success'];
description = lang.obj['settings_mods_remove_description_success'];
} catch (err) {
title = lang.obj['settings_mods_remove_title_failed'];
description = `${lang.obj['settings_mods_remove_description_failed']}${err}`;
}
break;
case 'channels': // /settings channels remove
try {
await db.removeChannel(interaction.options.getChannel('channel'));
title = lang.obj['settings_channels_remove_title_success'];
description = lang.obj['settings_channels_remove_description_success'];
} catch (err) {
title = lang.obj['settings_channels_remove_title_failed'];
description = `${lang.obj['settings_channels_remove_description_failed']}${err}`;
}
break;
default:
break;
}
break;
case 'show':
subcommandgroup = interaction.options.getSubcommandGroup(false);
switch (subcommandgroup) {
case 'mods': // /settings mods show
title = lang.obj['settings_mods_show_title'];
const mods = await db.listMods(interaction.guildId);
for (let i = 0; i < mods.length; i++) {
description += `<@${mods[i].getDataValue('isUser') ? '!' + mods[i].getDataValue('mentionableId') : '&' + mods[i].get('mentionableId')}> (${mods[i].get('mentionableId')})\n`;
}
if (description.length < 20)
description = lang.obj['settings_mods_show_none'];
break;
case 'channels': // /settings channels show
title = lang.obj['settings_channels_show_title'];
const channels = await db.listChannels(interaction.guildId);
for (let i = 0; i < channels.length; i++) {
description += `<#${channels[i].get('channelId')}> (${channels[i].get('channelId')})\n`;
}
if (description.length < 20)
description = lang.obj['settings_channels_show_none'];
break;
case 'language': // /settings language show
title = lang.obj['settings_language_show_title'];
description = await db.getLanguageCode(interaction.guildId);
break;
}
break;
case 'set':
subcommandgroup = interaction.options.getSubcommandGroup(false);
switch (subcommandgroup) {
case 'language': // /settings language set
try {
await db.setLanguage(interaction.guildId, interaction.options.getString('language'));
title = lang.obj['settings_language_set_title_success'];
description = lang.obj['settings_language_set_description_success'];
} catch (err) {
title = lang.obj['settings_language_set_title_failed'];
description = `${lang.obj['settings_language_set_description_failed']}${err}`;
}
break;
default:
break;
}
break;
case 'unset':
subcommandgroup = interaction.options.getSubcommandGroup(false);
switch (subcommandgroup) {
case 'language': // /settings language unset
try {
await db.unsetLanguage(interaction.guildId);
title = lang.obj['settings_language_unset_title_success'];
description = lang.obj['settings_language_unset_description_success'];
} catch (err) {
title = lang.obj['settings_language_unset_title_failed'];
description = `${lang.obj['settings_language_unset_description_failed']}${err}`;
}
break;
default:
break;
}
break;
case 'reset': // /settings reset
try {
await db.resetMods(interaction.guildId);
await db.resetChannels(interaction.guildId);
try {
await db.unsetLanguage(interaction.guildId);
} catch (e) {}
title = lang.obj['settings_reset_title_success'];
description = lang.obj['settings_reset_description_success'];
} catch (err) {
title = lang.obj['settings_reset_title_failed'];
description = `${lang.obj['settings_reset_description_failed']}${err}`;
}
break;
case 'help': // /settings ? help
subcommandgroup = interaction.options.getSubcommandGroup(false);
switch (subcommandgroup) {
case 'mods': // /settings mods help
title = lang.obj['settings_mods_help'];
description = `
\`/settings mods add <role or user>\` - ${lang.obj['settings_mods_add']}
\`/settings mods remove <role or user>\` - ${lang.obj['settings_mods_remove']}
\`/settings mods show\` - ${lang.obj['settings_mods_show']}`;
break;
case 'channels': // /settings channels help
title = lang.obj['settings_channels_help'];
description = `
\`/settings channels add <role or user>\` - ${lang.obj['settings_channels_add']}
\`/settings channels remove <role or user>\` - ${lang.obj['settings_channels_remove']}
\`/settings channels show\` - ${lang.obj['settings_channels_show']}`;
break;
case 'language': // /settings language help
title = lang.obj['settings_language_help'];
description = `
\`/settings language set <language code>\` - ${lang.obj['settings_language_set']}
\`/settings language unset\` - ${lang.obj['settings_language_unset']}
\`/settings language show\` - ${lang.obj['settings_language_show']}`;
break;
default: // /settings help
title = lang.obj['settings_help'];
description = `
\`/settings mods add <role or user>\` - ${lang.obj['settings_mods_add']}
\`/settings mods remove <role or user>\` - ${lang.obj['settings_mods_remove']}
\`/settings mods show\` - ${lang.obj['settings_mods_show']}
\`/settings channels add <role or user>\` - ${lang.obj['settings_channels_add']}
\`/settings channels remove <role or user>\` - ${lang.obj['settings_channels_remove']}
\`/settings channels show\` - ${lang.obj['settings_channels_show']}
\`/settings language set <language code>\` - ${lang.obj['settings_language_set']}
\`/settings language unset\` - ${lang.obj['settings_language_unset']}
\`/settings language show\` - ${lang.obj['settings_language_show']}
\`/settings reset\` - ${lang.obj['settings_reset']}
\`/settings show\` - ${lang.obj['settings_show']}`;
break;
}
break;
}
// returnEmbed(title, message, image=null)
interaction.editReply({
embeds: [util.returnEmbed(title, description)],
ephemeral: true
});
}
function getRegisterObject() {
return {
name: 'settings',
description: 'View or set settings in an ephemeral message',
type: ApplicationCommandType.ChatInput,
options: [
{
name: 'mods',
description: 'View, add or remove bot mods',
type: ApplicationCommandOptionType.SubcommandGroup,
options: [
{
name: 'add',
description: 'Add a bot mod',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'mentionable',
description: 'The user or role to add as a bot mod',
required: true,
type: ApplicationCommandOptionType.Mentionable
}
]
},
{
name: 'remove',
description: 'Remove a bot mod',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'mentionable',
description: 'The user or role to remove from the bot mods',
required: true,
type: ApplicationCommandOptionType.Mentionable
}
]
},
{
name: 'show',
description: 'Shows the current mods',
type: ApplicationCommandOptionType.Subcommand
},
{
name: 'help',
description: 'Shows help for mod settings',
type: ApplicationCommandOptionType.Subcommand
}
]
},
{
name: 'channels',
description: 'View, add or remove channels in which the bot responds',
type: ApplicationCommandOptionType.SubcommandGroup,
options: [
{
name: 'add',
description: 'Add a channel in which the bot responds',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'channel',
description: 'The channel in which the bot should start responding',
required: true,
type: ApplicationCommandOptionType.Channel
}
]
},
{
name: 'remove',
description: 'Remove a channel from the channels in which the bot responds',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'channel',
description: 'The channel in which the bot should stop responding',
required: true,
type: ApplicationCommandOptionType.Channel
}
]
},
{
name: 'show',
description: 'Shows the current channels in which the bot responds',
type: ApplicationCommandOptionType.Subcommand
},
{
name: 'help',
description: 'Shows help for mod settings',
type: ApplicationCommandOptionType.Subcommand
}
]
},
{
name: 'language',
description: 'View, set or unset a preferred language',
type: ApplicationCommandOptionType.SubcommandGroup,
options: [
{
name: 'set',
description: 'Set the preferred language for this server',
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: 'language',
description: 'The language code of your preferred language (e.g. en_US)',
required: true,
type: ApplicationCommandOptionType.String
}
]
},
{
name: 'unset',
description: 'Unsets your preferred language for this server',
type: ApplicationCommandOptionType.Subcommand
},
{
name: 'show',
description: 'Shows your currently set preferred language for this server',
type: ApplicationCommandOptionType.Subcommand
},
{
name: 'help',
description: 'Shows help for language settings',
type: ApplicationCommandOptionType.Subcommand
}
]
},
{
name: 'reset',
description: 'Resets the current settings',
type: ApplicationCommandOptionType.Subcommand
},
{
name: 'help',
description: 'Shows Help for the /settings command',
type: ApplicationCommandOptionType.Subcommand
}
]
};
}
module.exports.settings = settings;
module.exports.getRegisterObject = getRegisterObject;