/[sudobot]/trunk/src/commands/moderation/SetChPermsCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/moderation/SetChPermsCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 62 by rakin, Mon Jul 29 17:28:26 2024 UTC revision 393 by rakin, Mon Jul 29 17:29:59 2024 UTC
# Line 1  Line 1 
1  import { CategoryChannel, CommandInteraction, Message, TextChannel, Permissions, PermissionFlags, PermissionString, GuildChannel, Role } from 'discord.js';  /**
2    * This file is part of SudoBot.
3    *
4    * Copyright (C) 2021-2022 OSN Inc.
5    *
6    * SudoBot is free software; you can redistribute it and/or modify it
7    * under the terms of the GNU Affero General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10    *
11    * SudoBot is distributed in the hope that it will be useful, but
12    * WITHOUT ANY WARRANTY; without even the implied warranty of
13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    * GNU Affero General Public License for more details.
15    *
16    * You should have received a copy of the GNU Affero General Public License
17    * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18    */
19    
20    import { CategoryChannel, CommandInteraction, Message, TextChannel, Permissions, PermissionString, GuildChannel, Role, AutocompleteInteraction, Collection } from 'discord.js';
21  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
22  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
23  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
24  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
25  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
 import getUser from '../../utils/getUser';  
 import History from '../../automod/History';  
26  import { fetchEmoji } from '../../utils/Emoji';  import { fetchEmoji } from '../../utils/Emoji';
27  import getRole, { getRoleRaw } from '../../utils/getRole';  import { getRoleRaw } from '../../utils/getRole';
28  import { channelMention } from '@discordjs/builders';  import { channelMention } from '@discordjs/builders';
29    import AutoCompleteOptions from '../../types/AutoCompleteOptions';
30    
31  export default class BanCommand extends BaseCommand {  export default class SetChPermsCommand extends BaseCommand {
32      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
33    
34        permissions = [Permissions.FLAGS.MANAGE_CHANNELS];
35    
36      constructor() {      constructor() {
37          super('setchperms', 'moderation', []);          super('setchperms', 'moderation', []);
38      }      }
39    
40      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async autoComplete(client: DiscordClient, interaction: AutocompleteInteraction, options: AutoCompleteOptions) {
41            if (interaction.commandName === this.getName()) {
42                const focused = interaction.options.getFocused(true);
43    
44                console.log(focused);            
45    
46                if (focused.name === 'permission') {
47                    const { FLAGS } = Permissions;
48                    const responseArray = [];
49                    const perms: (keyof typeof FLAGS)[] = [
50                        'SEND_MESSAGES',
51                        'ATTACH_FILES',
52                        'EMBED_LINKS',
53                        'MANAGE_MESSAGES',
54                        'MENTION_EVERYONE',
55                        'USE_APPLICATION_COMMANDS',
56                        'USE_EXTERNAL_EMOJIS',
57                        'USE_EXTERNAL_STICKERS'
58                    ];
59    
60                    for await (const key of perms) {
61                        if (key.includes(focused.value.toString())) {
62                            responseArray.push({
63                                name: key,
64                                value: key
65                            });
66                        }
67                    }
68    
69                    console.log(responseArray);                
70    
71                    await interaction.respond(responseArray);
72                }
73            }
74        }
75    
76        async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {        
77          if (!options.isInteraction && typeof options.args[3] === 'undefined') {          if (!options.isInteraction && typeof options.args[3] === 'undefined') {
78              await msg.reply({              await msg.reply({
79                  embeds: [                  embeds: [
# Line 60  export default class BanCommand extends Line 116  export default class BanCommand extends
116    
117                  return;                  return;
118              }              }
119                else if (channels[0].type === 'GUILD_CATEGORY') {
120                    const ch = channels[0];
121                    channels = [];
122    
123                    const matching = <Collection<string, TextChannel>> await msg.guild!.channels.cache.filter(c => c.parent?.id === ch.id && c.type === 'GUILD_TEXT');
124                    channels = matching.toJSON();
125                }
126    
127              permKey = <PermissionString> options.options.getString('permission');              permKey = <PermissionString> options.options.getString('permission');
128                
129                if (FLAGS[permKey] === undefined) {
130                    await this.deferReply(msg, {
131                        content: (await fetchEmoji('error'))?.toString() + ' Invalid permission key given.',
132                        embeds: []
133                    }, true);
134    
135                    return;
136                }
137    
138              const permValueInput = <string> options.options.getString('value');              const permValueInput = <string> options.options.getString('value');
139    
140              if (permValueInput === 'true')              if (permValueInput === 'true')

Legend:
Removed from v.62  
changed lines
  Added in v.393

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26