Skip to content

Commit

Permalink
v10.15 (#1068)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtraction authored Apr 8, 2024
2 parents 49f03a0 + 7cba163 commit 5299d38
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 12 deletions.
2 changes: 1 addition & 1 deletion commands.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bastion",
"version": "10.14.0",
"version": "10.15.0",
"description": "Get an enhanced Discord experience!",
"type": "module",
"homepage": "https://bastion.traction.one",
Expand All @@ -24,8 +24,8 @@
"@types/http-errors": "^2.0.4",
"@types/jsdom": "^21.1.6",
"@types/node": "^20.10.2",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"eslint": "^8.55.0",
"typescript": "^5.3.2"
},
Expand All @@ -37,13 +37,13 @@
"dotenv": "^16.3.1",
"emoji-regex": "^10.3.0",
"gamedig": "^4.2.0",
"jsdom": "^23.0.1",
"jsdom": "^24.0.0",
"libsodium-wrappers": "^0.7.13",
"mathjs": "^12.1.0",
"openai": "^4.20.1",
"play-dl": "^1.9.7",
"r6api.js": "^4.4.1",
"undici": "^5.28.2",
"undici": "^6.11.1",
"ytdl-core": "^4.11.5",
"ytpl": "^2.3.0"
},
Expand Down
18 changes: 12 additions & 6 deletions src/commands/config/select-roles/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
* @copyright 2022
*/
import { ApplicationCommandOptionType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
import { Command } from "@bastion/tesseract";
import { Command, Logger } from "@bastion/tesseract";

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

class SelectRolesRemoveCommand extends Command {
constructor() {
super({
name: "remove",
description: "Remove the specified Select Role Group.",
description: "Remove the specified Select Roles Group.",
options: [
{
type: ApplicationCommandOptionType.String,
name: "id",
description: "The Select Role Group ID.",
description: "The Select Roles Group ID.",
required: true,
},
],
Expand All @@ -28,10 +28,16 @@ class SelectRolesRemoveCommand extends Command {
await interaction.deferReply();
const id = interaction.options.getString("id");

// delete the select role group document
await SelectRoleGroupModel.findByIdAndDelete(id);
// delete the select roles group document
const selectRoleGroup = await SelectRoleGroupModel.findByIdAndDelete(id);

await interaction.editReply(`I've deleted the Select Role Group **${ id }**.`);
// delete the select roles group message
const channel = interaction.guild.channels.cache.get(selectRoleGroup?.channel);
if (channel?.isTextBased()) {
await channel.messages.delete(selectRoleGroup.id).catch(Logger.ignore);
}

await interaction.editReply(`I've deleted the Select Roles Group **${ id }**.`);
}
}

Expand Down
118 changes: 118 additions & 0 deletions src/commands/config/select-roles/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*!
* @author TRACTION (iamtraction)
* @copyright 2024
*/
import { ApplicationCommandOptionType, ButtonStyle, ChatInputCommandInteraction, ComponentType, GuildTextBasedChannel, PermissionFlagsBits } from "discord.js";
import { Command, Logger } from "@bastion/tesseract";

import RoleModel from "../../../models/Role.js";
import SelectRoleGroupModel from "../../../models/SelectRoleGroup.js";
import * as arrays from "../../../utils/arrays.js";
import MessageComponents from "../../../utils/components.js";
import { SelectRolesUI } from "../../../utils/constants.js";
import { generate as generateEmbed } from "../../../utils/embeds.js";

class SelectRolesUpdateCommand extends Command {
constructor() {
super({
name: "update",
description: "Update the roles and message for the Select Roles Group.",
options: [
{
type: ApplicationCommandOptionType.String,
name: "id",
description: "The Select Roles Group ID.",
required: true,
},
{
type: ApplicationCommandOptionType.String,
name: "message",
description: "The new message content.",
},
],
userPermissions: [ PermissionFlagsBits.ManageGuild ],
});
}

public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> {
await interaction.deferReply();
const id = interaction.options.getString("id");
const message = generateEmbed(interaction.options.getString("message") || "");

// get the select roles group document
const selectRoleGroup = await SelectRoleGroupModel.findById(id);

// check whether the select roles group exists
if (!selectRoleGroup?.id) {
return interaction.editReply(`The Select Roles Group **${ id }** doesn't exist.`);
}

// fetch the select roles group message
const selectRolesMessage = await (interaction.guild.channels.cache.get(selectRoleGroup.channel) as GuildTextBasedChannel)?.messages.fetch(selectRoleGroup.id).catch(Logger.ignore);

// check whether the select roles group message exists
if (selectRolesMessage) {
// update roles in select roles group
const roleDocuments = await RoleModel.find({
$or: selectRoleGroup.roles.map(id => ({ id })),
});

const selectRoles = selectRoleGroup.roles.map(id => {
const role = interaction.guild.roles.cache.get(id);
const roleDocument = roleDocuments.find(r => r.id === id);

return {
value: id,
label: role?.name,
description: roleDocument?.description,
emoji: roleDocument?.emoji || role?.unicodeEmoji,
};
});

// update select roles group components with select menu
if (selectRoleGroup.ui === SelectRolesUI.SelectMenu) {
await selectRolesMessage.edit({
content: message ? typeof message === "string" ? message : "" : undefined,
embeds: message ? typeof message === "string" ? [] : [ message ] : undefined,
components: [
{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.StringSelect,
customId: MessageComponents.SelectRolesSelect,
placeholder: "Select Roles",
minValues: selectRoleGroup.min || 0,
maxValues: selectRoleGroup.max || selectRoles.length,
options: selectRoles,
},
],
},
],
});
} else {
// update select roles group components with buttons
await selectRolesMessage.edit({
content: message ? typeof message === "string" ? message : "" : undefined,
embeds: message ? typeof message === "string" ? [] : [ message ] : undefined,
components: arrays.chunks(selectRoles, 5).map(roles => ({
type: ComponentType.ActionRow,
components: roles.map(role => ({
customId: MessageComponents.SelectRolesButton + ":" + role.value,
type: ComponentType.Button,
label: role.label,
style: ButtonStyle.Secondary,
emoji: role.emoji,
})),
})),
});
}

return interaction.editReply(`I've updated the Select Roles Group **${ id }**.`);
}

await interaction.editReply(`The Select Roles Group **${ id }** doesn't exist anymore.`);
}
}

export { SelectRolesUpdateCommand as Command };

0 comments on commit 5299d38

Please sign in to comment.