Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
XboxBedrock committed Oct 26, 2023
1 parent f12586e commit 8b51315
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 108 deletions.
10 changes: 7 additions & 3 deletions src/commands/modpack.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -98,7 +102,7 @@ export default new Command({
{
description: "### Store\n" + store,
color: hexToNum(client.config.colors.success)
},
}
]
})
} else if (subcommand === "set") {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/reactionrole.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
4 changes: 1 addition & 3 deletions src/commands/team.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -103,6 +103,4 @@ export async function runBtCommand(
cInfo.executor = message.author.id
await cInfo.save()
}


}
78 changes: 43 additions & 35 deletions src/dropdowns/language.dropdown.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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})
}
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<any> {

Check warning on line 8 in src/dropdowns/language.dropdown.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
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 })
}
16 changes: 7 additions & 9 deletions src/entities/CommandAction.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
21 changes: 10 additions & 11 deletions src/entities/ReactionRole.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<string, ReactionRole>> {
Expand Down Expand Up @@ -60,7 +60,7 @@ export default class ReactionRole extends typeorm.BaseEntity {
requireType: boolean = true,
blacklistType: boolean = true
): Promise<boolean> {
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
Expand All @@ -78,14 +78,14 @@ export default class ReactionRole extends typeorm.BaseEntity {

public static async removeEmoji(emoji: string, messageId: string): Promise<boolean> {
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<boolean> {
const has = await this.findOne({ emoji: emoji, messageId: messageId })
return has? true: false
return has ? true : false
}

public static async addBlacklistedRole(
Expand Down Expand Up @@ -175,24 +175,23 @@ 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"

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
}
Expand Down
10 changes: 6 additions & 4 deletions src/events/interactionCreate.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export default async function (
): Promise<unknown> {
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(
Expand All @@ -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
}
Expand All @@ -56,7 +59,6 @@ export default async function (
this
)
}

}
if (interaction.isButton()) {
if (_.startsWith(interaction.customId, "modmenu.")) {
Expand Down
18 changes: 16 additions & 2 deletions src/events/messageReactionAdd.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/events/messageReactionRemove.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
60 changes: 34 additions & 26 deletions src/menus/team.menu.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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)

}
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<any> {
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)
}
Loading

0 comments on commit 8b51315

Please sign in to comment.