/[sudobot]/branches/4.x/src/commands/information/RoleListCommand.ts
ViewVC logotype

Contents of /branches/4.x/src/commands/information/RoleListCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months, 3 weeks ago) by rakinar2
File MIME type: application/typescript
File size: 5047 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /**
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 { CommandInteraction, Interaction, Message, Permissions, Role } from 'discord.js';
21 import BaseCommand from '../../utils/structures/BaseCommand';
22 import DiscordClient from '../../client/Client';
23 import InteractionOptions from '../../types/InteractionOptions';
24 import MessageEmbed from '../../client/MessageEmbed';
25 import Pagination from '../../utils/Pagination';
26 import CommandOptions from '../../types/CommandOptions';
27 import getRole from '../../utils/getRole';
28
29 export default class RoleListCommand extends BaseCommand {
30 permissions = [Permissions.FLAGS.MANAGE_ROLES];
31 supportsInteractions: boolean = true;
32
33 constructor() {
34 super('rolelist', 'information', []);
35 }
36
37 async run(client: DiscordClient, message: CommandInteraction | Message, options: InteractionOptions | CommandOptions) {
38 let role: Role | null = null, order = "d";
39
40 if (options.isInteraction && options.options.getRole('role'))
41 role = <Role> options.options.getRole('role');
42 else if (!options.isInteraction && options.args[0])
43 role = (await getRole(message as Message, options, 1)) ?? null;
44
45 if (options.isInteraction && options.options.getString('order'))
46 order = <string> options.options.getString('order');
47
48 if (!role) {
49 message instanceof CommandInteraction ? await message.deferReply() : null;
50
51 const roles = message.guild!.roles.cache.sort((role1, role2) => order === 'a' ? role1.position - role2.position : role2.position - role1.position).toJSON();
52 const popped = roles.pop();
53
54 if (popped && popped.id !== message.guild!.id) {
55 roles.push(popped);
56 }
57
58 const pagination = new Pagination(roles, {
59 channel_id: message.channel!.id,
60 guild_id: message.guild!.id,
61 user_id: message.member!.user.id,
62 limit: 20,
63 timeout: 120_000,
64 embedBuilder({ data, currentPage, maxPages }) {
65 let description = '';
66
67 for (const role of data) {
68 description += `${role} • \`${role.id}\` • ${role.hexColor}\n`;
69 // description += `${role}\n**ID**: ${role.id}\n**Color**: ${role.hexColor}\n**Hoisting**: ${role.hoist ? 'Enabled' : 'Disabled'}\n**Position**: ${role.position}\n\n`;
70 }
71
72 return new MessageEmbed({
73 author: {
74 name: "Roles",
75 iconURL: message.guild!.iconURL() ?? undefined
76 },
77 description,
78 footer: { text: `Page ${currentPage} of ${maxPages} • ${roles.length} roles total` }
79 });
80 },
81 });
82
83 let reply = await this.deferReply(message, await pagination.getMessageOptions(1));
84
85 if (message instanceof Interaction) {
86 reply = (await message.fetchReply()) as Message;
87 }
88
89 pagination.start(reply! as Message).catch(console.error);
90 }
91 else {
92 await message.reply({
93 embeds: [
94 new MessageEmbed()
95 .setAuthor({
96 name: `Role Information`
97 })
98 .setColor(role.hexColor)
99 .addFields([
100 {
101 name: 'Name',
102 value: role.name,
103 inline: true
104 },
105 {
106 name: 'Color',
107 value: role.hexColor,
108 inline: true
109 },
110 {
111 name: 'Members',
112 value: role.members.size + ''
113 },
114 {
115 name: 'Bot Role',
116 value: role.members.size === 1 && role.members.first()?.user.bot ? 'Yes' : 'No',
117 inline: true
118 }
119 ])
120 ]
121 });
122 }
123 }
124 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26