This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bc4ed3
commit 7018d78
Showing
13 changed files
with
651 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { RoleSelectMenuBuilder } from "discord.js"; | ||
import getHandlerId from "../utils/getHandlerId.js"; | ||
|
||
export default class RoleSelect extends RoleSelectMenuBuilder { | ||
public static readonly GENERIC_ID = getHandlerId(RoleSelect.name); | ||
|
||
constructor(id: string) { | ||
super(); | ||
this.setCustomId(id) | ||
.setPlaceholder("Select a role") | ||
.setMinValues(1) | ||
.setMaxValues(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
packages/discord/src/interaction-handlers/admin/quota/AdminQuotaRoleHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { | ||
Interaction, | ||
Colors, | ||
italic, | ||
ButtonBuilder, | ||
ButtonStyle, | ||
InteractionResponse, | ||
Message, | ||
} from "discord.js"; | ||
import getHandlerId from "../../../utils/getHandlerId.js"; | ||
import reply from "../../../utils/reply.js"; | ||
import AdminQuotaSnowflakeHandler from "./AdminQuotaSnowflakeHandler.js"; | ||
|
||
export default class AdminQuotaRoleHandler extends AdminQuotaSnowflakeHandler { | ||
public static readonly ID = getHandlerId(AdminQuotaRoleHandler.name); | ||
|
||
constructor() { | ||
super(AdminQuotaRoleHandler.ID); | ||
} | ||
|
||
public get name(): string { | ||
return AdminQuotaRoleHandler.name; | ||
} | ||
|
||
protected async getCurrentQuota( | ||
interaction: Interaction, | ||
roleId: string | ||
): Promise<number> { | ||
const { quotaManager } = interaction.client; | ||
return ( | ||
(await quotaManager.getRoleQuota(roleId)) ?? | ||
(await quotaManager.getDefaultQuota()) | ||
); | ||
} | ||
|
||
protected async getInitialReply( | ||
interaction: Interaction, | ||
roleId: string | ||
): Promise<Message<boolean> | InteractionResponse<boolean> | null> { | ||
const { quotaManager } = interaction.client; | ||
|
||
const quota = await this.getCurrentQuota(interaction, roleId); | ||
const hasQuota = await quotaManager.hasRoleQuota(roleId); | ||
|
||
const quotaFormat = Intl.NumberFormat("en-US", { | ||
style: "decimal", | ||
maximumFractionDigits: 0, | ||
}).format(quota); | ||
const quotaType = (() => { | ||
if (hasQuota) { | ||
return ""; | ||
} | ||
return `(${italic("default")})`; | ||
})(); | ||
|
||
const row = this.createMessageActionRow().addComponents( | ||
new ButtonBuilder() | ||
.setCustomId(AdminQuotaSnowflakeHandler.BUTTON_SET_ID) | ||
.setLabel("Set Quota") | ||
.setStyle(ButtonStyle.Primary) | ||
.setEmoji("🔧") | ||
); | ||
|
||
if (hasQuota) { | ||
row.addComponents( | ||
new ButtonBuilder() | ||
.setCustomId(AdminQuotaSnowflakeHandler.BUTTON_RESET_ID) | ||
.setLabel("Reset Quota") | ||
.setStyle(ButtonStyle.Primary) | ||
.setEmoji("🔄") | ||
); | ||
} | ||
|
||
return reply(interaction, { | ||
ephemeral: true, | ||
embeds: [ | ||
{ | ||
title: "Role Quota Information", | ||
fields: [ | ||
{ | ||
name: "Current Quota", | ||
value: `${quotaFormat} ${quotaType}`, | ||
inline: true, | ||
}, | ||
], | ||
color: Colors.Blue, | ||
}, | ||
], | ||
components: [row], | ||
}); | ||
} | ||
|
||
protected async deleteQuota( | ||
interaction: Interaction, | ||
roleId: string | ||
): Promise<void> { | ||
const { quotaManager } = interaction.client; | ||
await quotaManager.deleteRoleQuota(roleId); | ||
} | ||
|
||
protected getModalTitle(): string { | ||
return "Set Role Quota"; | ||
} | ||
|
||
protected async setQuota( | ||
interaction: Interaction, | ||
roleId: string, | ||
quota: number | ||
): Promise<void> { | ||
const { quotaManager } = interaction.client; | ||
await quotaManager.setRoleQuota(roleId, quota); | ||
} | ||
} |
Oops, something went wrong.