From 8b51315a4db891d3998e406406f5e7a55aaf068a Mon Sep 17 00:00:00 2001 From: XboxBedrock <68715625+XboxBedrock@users.noreply.github.com> Date: Wed, 25 Oct 2023 22:26:35 -0700 Subject: [PATCH] format --- src/commands/modpack.command.ts | 10 ++- src/commands/reactionrole.command.ts | 2 +- src/commands/team.command.ts | 4 +- src/dropdowns/language.dropdown.ts | 78 +++++++++++++---------- src/entities/CommandAction.entity.ts | 16 ++--- src/entities/ReactionRole.entity.ts | 21 +++--- src/events/interactionCreate.event.ts | 10 +-- src/events/messageReactionAdd.event.ts | 18 +++++- src/events/messageReactionRemove.event.ts | 8 ++- src/menus/team.menu.ts | 60 +++++++++-------- src/struct/client/AssetList.ts | 18 ++---- 11 files changed, 137 insertions(+), 108 deletions(-) diff --git a/src/commands/modpack.command.ts b/src/commands/modpack.command.ts index 76b8f439..845e99f3 100644 --- a/src/commands/modpack.command.ts +++ b/src/commands/modpack.command.ts @@ -13,7 +13,10 @@ export default new Command({ name: "modpack", aliases: ["mp"], description: "Manage the modpack's background images.", - permission: [globalThis.client.roles.MANAGER, globalThis.client.roles.BUILDER_COUNCIL], + permission: [ + globalThis.client.roles.MANAGER, + globalThis.client.roles.BUILDER_COUNCIL + ], subcommands: [ { name: "list", @@ -89,7 +92,8 @@ export default new Command({ const queue = format("queue") const store = format("store") - message.send({ embeds: [ + message.send({ + embeds: [ { author: { name: "Image list" }, description: "### Queue\n" + queue, @@ -98,7 +102,7 @@ export default new Command({ { description: "### Store\n" + store, color: hexToNum(client.config.colors.success) - }, + } ] }) } else if (subcommand === "set") { diff --git a/src/commands/reactionrole.command.ts b/src/commands/reactionrole.command.ts index ee75d722..cbb971c0 100644 --- a/src/commands/reactionrole.command.ts +++ b/src/commands/reactionrole.command.ts @@ -373,7 +373,7 @@ export default new Command({ let roles console.log(client.reactionRoles.keys()) - + if (subcommandGroup == "blacklist") { roles = client.reactionRoles.get( `${realEmoji}.${messageProps.messageId}` diff --git a/src/commands/team.command.ts b/src/commands/team.command.ts index 48661986..7cd1985b 100644 --- a/src/commands/team.command.ts +++ b/src/commands/team.command.ts @@ -93,7 +93,7 @@ export async function runBtCommand( message .reply({ content: snippet.body, allowedMentions: { parse: [] } }) .catch(() => null) - + const cInfo = new CommandAction() cInfo.channel = message.channel.id cInfo.command = "executed_team" @@ -103,6 +103,4 @@ export async function runBtCommand( cInfo.executor = message.author.id await cInfo.save() } - - } diff --git a/src/dropdowns/language.dropdown.ts b/src/dropdowns/language.dropdown.ts index f1c3ae4a..3c9276b3 100644 --- a/src/dropdowns/language.dropdown.ts +++ b/src/dropdowns/language.dropdown.ts @@ -1,35 +1,43 @@ -import Discord from "discord.js"; -import Client from "../struct/Client.js"; -import { noop } from "@buildtheearth/bot-utils"; - -export default async function languageDropdown(client: Client, interaction: Discord.StringSelectMenuInteraction): Promise { - const roles = interaction.values.map((e) => e.replace("language.", "")) - - const languageRoles = [ - "696121533663281205", - "696123149606977628", - "696123325344251995", - "696123331673587742", - "696123338774544475", - "696123339063820329", - "696123339990892584", - "696123340468781136", - "696139193029492757", - ] - - const member = await client.customGuilds.main().members.fetch(interaction.user).catch(noop) - - if (!member) return await interaction.reply("Unknown Error") - - const currRoles = member.roles.cache.filter((e) => languageRoles.includes(e.id)).map((e) => e.id) - - for (const role of currRoles) { - if (!roles.includes(role)) await member.roles.remove(role) - } - - for (const role of roles) { - if (!currRoles.includes(role)) await member.roles.add(role) - } - - return await interaction.reply({content: "Roles have been given!", ephemeral: true}) -} \ No newline at end of file +import Discord from "discord.js" +import Client from "../struct/Client.js" +import { noop } from "@buildtheearth/bot-utils" + +export default async function languageDropdown( + client: Client, + interaction: Discord.StringSelectMenuInteraction +): Promise { + const roles = interaction.values.map(e => e.replace("language.", "")) + + const languageRoles = [ + "696121533663281205", + "696123149606977628", + "696123325344251995", + "696123331673587742", + "696123338774544475", + "696123339063820329", + "696123339990892584", + "696123340468781136", + "696139193029492757" + ] + + const member = await client.customGuilds + .main() + .members.fetch(interaction.user) + .catch(noop) + + if (!member) return await interaction.reply("Unknown Error") + + const currRoles = member.roles.cache + .filter(e => languageRoles.includes(e.id)) + .map(e => e.id) + + for (const role of currRoles) { + if (!roles.includes(role)) await member.roles.remove(role) + } + + for (const role of roles) { + if (!currRoles.includes(role)) await member.roles.add(role) + } + + return await interaction.reply({ content: "Roles have been given!", ephemeral: true }) +} diff --git a/src/entities/CommandAction.entity.ts b/src/entities/CommandAction.entity.ts index 4363cf5d..1b5241f2 100644 --- a/src/entities/CommandAction.entity.ts +++ b/src/entities/CommandAction.entity.ts @@ -4,29 +4,27 @@ import unicode from "./transformers/unicode.transformer.js" @typeorm.Entity({ name: "command_action" }) export default class CommandAction extends typeorm.BaseEntity { - @typeorm.PrimaryGeneratedColumn() id!: number - @typeorm.Column({nullable: false}) + @typeorm.Column({ nullable: false }) command!: string - @typeorm.Column({nullable: true}) + @typeorm.Column({ nullable: true }) subcommandGroup?: string - @typeorm.Column({nullable: true}) + @typeorm.Column({ nullable: true }) subcommand?: string - @SnowflakeColumn({nullable: false}) + @SnowflakeColumn({ nullable: false }) executor!: string - @SnowflakeColumn({nullable: false}) + @SnowflakeColumn({ nullable: false }) guild!: string - @SnowflakeColumn({nullable: false}) + @SnowflakeColumn({ nullable: false }) channel!: string - @typeorm.CreateDateColumn({nullable: false}) + @typeorm.CreateDateColumn({ nullable: false }) created!: Date - } diff --git a/src/entities/ReactionRole.entity.ts b/src/entities/ReactionRole.entity.ts index 18f8c2f8..9abdd008 100644 --- a/src/entities/ReactionRole.entity.ts +++ b/src/entities/ReactionRole.entity.ts @@ -24,13 +24,13 @@ export default class ReactionRole extends typeorm.BaseEntity { @typeorm.Column({ name: "required_roles", nullable: true, type: "simple-array" }) requiredRoles?: string[] | null - @typeorm.Column({ default: true}) + @typeorm.Column({ default: true }) requireType!: boolean @typeorm.Column({ name: "blacklisted_roles", nullable: true, type: "simple-array" }) blackListedRoles?: string[] | null - @typeorm.Column({ default: true}) + @typeorm.Column({ default: true }) blacklistType!: boolean public static async load(client: Client): Promise> { @@ -60,7 +60,7 @@ export default class ReactionRole extends typeorm.BaseEntity { requireType: boolean = true, blacklistType: boolean = true ): Promise { - const has = await this.findOne({where: { emoji: emoji, messageId: messageId }}) + const has = await this.findOne({ where: { emoji: emoji, messageId: messageId } }) if (has?.emoji === emoji && has?.messageId === messageId) return false const rRole = new ReactionRole() rRole.emoji = emoji @@ -78,14 +78,14 @@ export default class ReactionRole extends typeorm.BaseEntity { public static async removeEmoji(emoji: string, messageId: string): Promise { if (!ReactionRole.exists(emoji, messageId)) return false - await ReactionRole.delete({emoji: emoji, messageId: messageId}).catch(noop) + await ReactionRole.delete({ emoji: emoji, messageId: messageId }).catch(noop) client.reactionRoles.delete(`${emoji}.${messageId}`) return true } public static async exists(emoji: string, messageId: string): Promise { const has = await this.findOne({ emoji: emoji, messageId: messageId }) - return has? true: false + return has ? true : false } public static async addBlacklistedRole( @@ -175,7 +175,7 @@ export default class ReactionRole extends typeorm.BaseEntity { if (!react) return false const reqRoles = react?.requiredRoles const unreqRoles = react?.blackListedRoles - + let wFn: "every" | "some" = "some" let bFn: "every" | "some" = "some" @@ -183,16 +183,15 @@ export default class ReactionRole extends typeorm.BaseEntity { if (!react.requireType) wFn = "every" if (!react.blacklistType) bFn = "every" - - - if ((unreqRoles && reqRoles) && ((unreqRoles.length != 0) && (reqRoles.length != 0))) + if (unreqRoles && reqRoles && unreqRoles.length != 0 && reqRoles.length != 0) return ( unreqRoles[bFn](e => !guildMember.roles.cache.has(e)) && reqRoles[wFn](e => guildMember.roles.cache.has(e)) ) - if (unreqRoles && (unreqRoles.length != 0)) + if (unreqRoles && unreqRoles.length != 0) return unreqRoles[bFn](e => !guildMember.roles.cache.has(e)) - if (reqRoles && (reqRoles.length != 0)) return reqRoles[wFn](e => guildMember.roles.cache.has(e)) + if (reqRoles && reqRoles.length != 0) + return reqRoles[wFn](e => guildMember.roles.cache.has(e)) return true } diff --git a/src/events/interactionCreate.event.ts b/src/events/interactionCreate.event.ts index 82ee36f9..56e22e86 100644 --- a/src/events/interactionCreate.event.ts +++ b/src/events/interactionCreate.event.ts @@ -25,11 +25,11 @@ export default async function ( ): Promise { if (interaction.user.bot) return - if (interaction.type === Discord.InteractionType.MessageComponent) { if (interaction.isStringSelectMenu()) { if (interaction.customId.split(".")[0] === "info") { - if (interaction.customId === "info.languages") return await languageDropdown(this, interaction) + if (interaction.customId === "info.languages") + return await languageDropdown(this, interaction) } else { if ( !GuildMember.hasRole( @@ -45,7 +45,10 @@ export default async function ( await interaction.deferUpdate() await interaction.followUp({ ephemeral: true, - content: client.messages.getMessage("noPermsMod", interaction.locale) + content: client.messages.getMessage( + "noPermsMod", + interaction.locale + ) }) return } @@ -56,7 +59,6 @@ export default async function ( this ) } - } if (interaction.isButton()) { if (_.startsWith(interaction.customId, "modmenu.")) { diff --git a/src/events/messageReactionAdd.event.ts b/src/events/messageReactionAdd.event.ts index e3d06653..2d7a2026 100644 --- a/src/events/messageReactionAdd.event.ts +++ b/src/events/messageReactionAdd.event.ts @@ -170,8 +170,22 @@ export default async function messageReactionAdd( const rolereactId = `${trueId}.${reaction.message.id}` if (this.reactionRoles.has(rolereactId)) { - if (await ReactionRole.canReact(this, trueId, channel.id, reaction.message.id, member)) { - await ReactionRole.react(this, trueId, channel.id, reaction.message.id, member) + if ( + await ReactionRole.canReact( + this, + trueId, + channel.id, + reaction.message.id, + member + ) + ) { + await ReactionRole.react( + this, + trueId, + channel.id, + reaction.message.id, + member + ) return } } diff --git a/src/events/messageReactionRemove.event.ts b/src/events/messageReactionRemove.event.ts index a8be06a4..bfb0b078 100644 --- a/src/events/messageReactionRemove.event.ts +++ b/src/events/messageReactionRemove.event.ts @@ -67,7 +67,13 @@ export default async function messageReactionRemove( console.log(rolereactId) if (this.reactionRoles.has(rolereactId)) { - await ReactionRole.unreact(this, trueId, channel.id, reaction.message.id, member) + await ReactionRole.unreact( + this, + trueId, + channel.id, + reaction.message.id, + member + ) return } } diff --git a/src/menus/team.menu.ts b/src/menus/team.menu.ts index 772620bb..98c64b94 100644 --- a/src/menus/team.menu.ts +++ b/src/menus/team.menu.ts @@ -1,26 +1,34 @@ -import { noop } from "@buildtheearth/bot-utils" -import Client from "../struct/Client.js" -import Discord from "discord.js" - -export default async function teamMenu(client: Client, interaction: Discord.ButtonInteraction): Promise { - const continent = interaction.customId - - const validContinents = [ - "info.teams.NA", - "info.teams.LA", - "info.teams.EU", - "info.teams.AF", - "info.teams.AS", - "info.teams.OC", - "info.teams.OT" - ] - - if (!validContinents.includes(continent)) return await interaction.reply({content: "Invalid Region", ephemeral: true}).catch(noop) - - const data = client.assets.getAsset(continent) - - if (!data) return await interaction.reply({content: "Invalid Region", ephemeral: true}).catch(noop) - - return await interaction.reply(data).catch(noop) - -} \ No newline at end of file +import { noop } from "@buildtheearth/bot-utils" +import Client from "../struct/Client.js" +import Discord from "discord.js" + +export default async function teamMenu( + client: Client, + interaction: Discord.ButtonInteraction +): Promise { + const continent = interaction.customId + + const validContinents = [ + "info.teams.NA", + "info.teams.LA", + "info.teams.EU", + "info.teams.AF", + "info.teams.AS", + "info.teams.OC", + "info.teams.OT" + ] + + if (!validContinents.includes(continent)) + return await interaction + .reply({ content: "Invalid Region", ephemeral: true }) + .catch(noop) + + const data = client.assets.getAsset(continent) + + if (!data) + return await interaction + .reply({ content: "Invalid Region", ephemeral: true }) + .catch(noop) + + return await interaction.reply(data).catch(noop) +} diff --git a/src/struct/client/AssetList.ts b/src/struct/client/AssetList.ts index 346c88b1..8e58d0be 100644 --- a/src/struct/client/AssetList.ts +++ b/src/struct/client/AssetList.ts @@ -15,10 +15,8 @@ function getFiles(source: fs.PathLike): string[] { // eslint-disable-next-line @typescript-eslint/ban-types export default class AssetList { client: Client - collection: Discord.Collection< - string, - { [key: string]: any } - > = new Discord.Collection() + collection: Discord.Collection = + new Discord.Collection() constructor(client: Client) { this.client = client } @@ -28,22 +26,16 @@ export default class AssetList { pathModule.dirname(url.fileURLToPath(import.meta.url)) + "/../../../config/extensions/templates/" ) - const files = await fs.promises.readdir( - url.pathToFileURL(dir) - ) + const files = await fs.promises.readdir(url.pathToFileURL(dir)) for (const file of files) { - const data = loadSyncJSON5( - pathModule.join(dir, file) - ) + const data = loadSyncJSON5(pathModule.join(dir, file)) const trueName = file.replace(/.json5$/, "") this.collection.set(trueName, data) } } - getAsset( - name: string - ): any | undefined { + getAsset(name: string): any | undefined { return this.collection.get(name) } }