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, 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 |
|
26 |
export default class RoleListCommand extends BaseCommand { |
27 |
supportsInteractions: boolean = true; |
28 |
supportsLegacy = false; |
29 |
|
30 |
constructor() { |
31 |
super('rolelist', 'information', []); |
32 |
} |
33 |
|
34 |
async run(client: DiscordClient, msg: CommandInteraction, options: InteractionOptions) { |
35 |
let role: Role | null = null, page = 1; |
36 |
|
37 |
if (options.options.getRole('role')) |
38 |
role = <Role> options.options.getRole('role'); |
39 |
|
40 |
if (options.options.getInteger('page')) |
41 |
page = <number> options.options.getInteger('page'); |
42 |
|
43 |
if (!role) { |
44 |
const roles = await msg.guild!.roles.cache.toJSON(); |
45 |
|
46 |
let str = ``; |
47 |
let limit = 15, i = 1, offset = (page - 1) * limit; |
48 |
|
49 |
if (offset >= roles.length) { |
50 |
await msg.reply({ |
51 |
content: "Invalid page number.", |
52 |
ephemeral: true |
53 |
}); |
54 |
|
55 |
return; |
56 |
} |
57 |
|
58 |
for await (const role of roles) { |
59 |
if (role.id === msg.guild!.id) |
60 |
continue; |
61 |
|
62 |
i++; |
63 |
|
64 |
if (offset >= (i - 1)) |
65 |
continue; |
66 |
|
67 |
if ((limit + offset) < (i - 1)) |
68 |
break; |
69 |
|
70 |
str += `${role.name} - ${role.id} - ${role.members.size} Members - ${role.hexColor}\n`; |
71 |
} |
72 |
|
73 |
await msg.reply({ |
74 |
content: "**Role List (" + page + ")**:\n\n```" + str + '```', |
75 |
}); |
76 |
} |
77 |
else { |
78 |
await msg.reply({ |
79 |
embeds: [ |
80 |
new MessageEmbed() |
81 |
.setAuthor({ |
82 |
name: `Role Information` |
83 |
}) |
84 |
.setColor(role.hexColor) |
85 |
.addFields([ |
86 |
{ |
87 |
name: 'Name', |
88 |
value: role.name |
89 |
}, |
90 |
{ |
91 |
name: 'Color', |
92 |
value: role.hexColor |
93 |
}, |
94 |
{ |
95 |
name: 'Members', |
96 |
value: role.members.size + '' |
97 |
}, |
98 |
{ |
99 |
name: 'Bot Role', |
100 |
value: role.members.size === 1 && role.members.first()?.user.bot ? 'Yes' : 'No' |
101 |
} |
102 |
]) |
103 |
] |
104 |
}); |
105 |
} |
106 |
} |
107 |
} |