Skip to content

Commit 5299d38

Browse files
authored
v10.15 (#1068)
2 parents 49f03a0 + 7cba163 commit 5299d38

File tree

4 files changed

+136
-12
lines changed

4 files changed

+136
-12
lines changed

commands.json

+1-1
Large diffs are not rendered by default.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bastion",
3-
"version": "10.14.0",
3+
"version": "10.15.0",
44
"description": "Get an enhanced Discord experience!",
55
"type": "module",
66
"homepage": "https://bastion.traction.one",
@@ -24,8 +24,8 @@
2424
"@types/http-errors": "^2.0.4",
2525
"@types/jsdom": "^21.1.6",
2626
"@types/node": "^20.10.2",
27-
"@typescript-eslint/eslint-plugin": "^6.13.1",
28-
"@typescript-eslint/parser": "^6.13.1",
27+
"@typescript-eslint/eslint-plugin": "^7.5.0",
28+
"@typescript-eslint/parser": "^7.5.0",
2929
"eslint": "^8.55.0",
3030
"typescript": "^5.3.2"
3131
},
@@ -37,13 +37,13 @@
3737
"dotenv": "^16.3.1",
3838
"emoji-regex": "^10.3.0",
3939
"gamedig": "^4.2.0",
40-
"jsdom": "^23.0.1",
40+
"jsdom": "^24.0.0",
4141
"libsodium-wrappers": "^0.7.13",
4242
"mathjs": "^12.1.0",
4343
"openai": "^4.20.1",
4444
"play-dl": "^1.9.7",
4545
"r6api.js": "^4.4.1",
46-
"undici": "^5.28.2",
46+
"undici": "^6.11.1",
4747
"ytdl-core": "^4.11.5",
4848
"ytpl": "^2.3.0"
4949
},

src/commands/config/select-roles/remove.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
* @copyright 2022
44
*/
55
import { ApplicationCommandOptionType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
6-
import { Command } from "@bastion/tesseract";
6+
import { Command, Logger } from "@bastion/tesseract";
77

88
import SelectRoleGroupModel from "../../../models/SelectRoleGroup.js";
99

1010
class SelectRolesRemoveCommand extends Command {
1111
constructor() {
1212
super({
1313
name: "remove",
14-
description: "Remove the specified Select Role Group.",
14+
description: "Remove the specified Select Roles Group.",
1515
options: [
1616
{
1717
type: ApplicationCommandOptionType.String,
1818
name: "id",
19-
description: "The Select Role Group ID.",
19+
description: "The Select Roles Group ID.",
2020
required: true,
2121
},
2222
],
@@ -28,10 +28,16 @@ class SelectRolesRemoveCommand extends Command {
2828
await interaction.deferReply();
2929
const id = interaction.options.getString("id");
3030

31-
// delete the select role group document
32-
await SelectRoleGroupModel.findByIdAndDelete(id);
31+
// delete the select roles group document
32+
const selectRoleGroup = await SelectRoleGroupModel.findByIdAndDelete(id);
3333

34-
await interaction.editReply(`I've deleted the Select Role Group **${ id }**.`);
34+
// delete the select roles group message
35+
const channel = interaction.guild.channels.cache.get(selectRoleGroup?.channel);
36+
if (channel?.isTextBased()) {
37+
await channel.messages.delete(selectRoleGroup.id).catch(Logger.ignore);
38+
}
39+
40+
await interaction.editReply(`I've deleted the Select Roles Group **${ id }**.`);
3541
}
3642
}
3743

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*!
2+
* @author TRACTION (iamtraction)
3+
* @copyright 2024
4+
*/
5+
import { ApplicationCommandOptionType, ButtonStyle, ChatInputCommandInteraction, ComponentType, GuildTextBasedChannel, PermissionFlagsBits } from "discord.js";
6+
import { Command, Logger } from "@bastion/tesseract";
7+
8+
import RoleModel from "../../../models/Role.js";
9+
import SelectRoleGroupModel from "../../../models/SelectRoleGroup.js";
10+
import * as arrays from "../../../utils/arrays.js";
11+
import MessageComponents from "../../../utils/components.js";
12+
import { SelectRolesUI } from "../../../utils/constants.js";
13+
import { generate as generateEmbed } from "../../../utils/embeds.js";
14+
15+
class SelectRolesUpdateCommand extends Command {
16+
constructor() {
17+
super({
18+
name: "update",
19+
description: "Update the roles and message for the Select Roles Group.",
20+
options: [
21+
{
22+
type: ApplicationCommandOptionType.String,
23+
name: "id",
24+
description: "The Select Roles Group ID.",
25+
required: true,
26+
},
27+
{
28+
type: ApplicationCommandOptionType.String,
29+
name: "message",
30+
description: "The new message content.",
31+
},
32+
],
33+
userPermissions: [ PermissionFlagsBits.ManageGuild ],
34+
});
35+
}
36+
37+
public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> {
38+
await interaction.deferReply();
39+
const id = interaction.options.getString("id");
40+
const message = generateEmbed(interaction.options.getString("message") || "");
41+
42+
// get the select roles group document
43+
const selectRoleGroup = await SelectRoleGroupModel.findById(id);
44+
45+
// check whether the select roles group exists
46+
if (!selectRoleGroup?.id) {
47+
return interaction.editReply(`The Select Roles Group **${ id }** doesn't exist.`);
48+
}
49+
50+
// fetch the select roles group message
51+
const selectRolesMessage = await (interaction.guild.channels.cache.get(selectRoleGroup.channel) as GuildTextBasedChannel)?.messages.fetch(selectRoleGroup.id).catch(Logger.ignore);
52+
53+
// check whether the select roles group message exists
54+
if (selectRolesMessage) {
55+
// update roles in select roles group
56+
const roleDocuments = await RoleModel.find({
57+
$or: selectRoleGroup.roles.map(id => ({ id })),
58+
});
59+
60+
const selectRoles = selectRoleGroup.roles.map(id => {
61+
const role = interaction.guild.roles.cache.get(id);
62+
const roleDocument = roleDocuments.find(r => r.id === id);
63+
64+
return {
65+
value: id,
66+
label: role?.name,
67+
description: roleDocument?.description,
68+
emoji: roleDocument?.emoji || role?.unicodeEmoji,
69+
};
70+
});
71+
72+
// update select roles group components with select menu
73+
if (selectRoleGroup.ui === SelectRolesUI.SelectMenu) {
74+
await selectRolesMessage.edit({
75+
content: message ? typeof message === "string" ? message : "" : undefined,
76+
embeds: message ? typeof message === "string" ? [] : [ message ] : undefined,
77+
components: [
78+
{
79+
type: ComponentType.ActionRow,
80+
components: [
81+
{
82+
type: ComponentType.StringSelect,
83+
customId: MessageComponents.SelectRolesSelect,
84+
placeholder: "Select Roles",
85+
minValues: selectRoleGroup.min || 0,
86+
maxValues: selectRoleGroup.max || selectRoles.length,
87+
options: selectRoles,
88+
},
89+
],
90+
},
91+
],
92+
});
93+
} else {
94+
// update select roles group components with buttons
95+
await selectRolesMessage.edit({
96+
content: message ? typeof message === "string" ? message : "" : undefined,
97+
embeds: message ? typeof message === "string" ? [] : [ message ] : undefined,
98+
components: arrays.chunks(selectRoles, 5).map(roles => ({
99+
type: ComponentType.ActionRow,
100+
components: roles.map(role => ({
101+
customId: MessageComponents.SelectRolesButton + ":" + role.value,
102+
type: ComponentType.Button,
103+
label: role.label,
104+
style: ButtonStyle.Secondary,
105+
emoji: role.emoji,
106+
})),
107+
})),
108+
});
109+
}
110+
111+
return interaction.editReply(`I've updated the Select Roles Group **${ id }**.`);
112+
}
113+
114+
await interaction.editReply(`The Select Roles Group **${ id }** doesn't exist anymore.`);
115+
}
116+
}
117+
118+
export { SelectRolesUpdateCommand as Command };

0 commit comments

Comments
 (0)