-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
533 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { | ||
EmbedBuilder, | ||
PermissionFlagsBits, | ||
SlashCommandBuilder, | ||
} from "discord.js"; | ||
import ms from "ms"; | ||
import Command from "../Command"; | ||
|
||
export default class extends Command { | ||
public constructor() { | ||
super("giveaway"); | ||
|
||
this.applicationCommands.push( | ||
new SlashCommandBuilder() | ||
.setName("giveaway") | ||
.setDescription("Module giveaway") | ||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) | ||
.addSubcommand((subcommand) => | ||
subcommand | ||
.setName("start") | ||
.setDescription("Bắt đầu một đợt giveaway mới") | ||
.addStringOption((option) => | ||
option | ||
.setName("prize") | ||
.setDescription("Tên giveaway") | ||
.setRequired(true) | ||
.setMaxLength(50), | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName("duration") | ||
.setDescription( | ||
"Thời gian giveaway kết thúc (5d, 5h, 5m, 5s, ...)", | ||
) | ||
.setRequired(true), | ||
) | ||
.addIntegerOption((option) => | ||
option | ||
.setName("winners") | ||
.setDescription("Số lượng người thắng giveaway") | ||
.setRequired(true) | ||
.setMinValue(1) | ||
.setMaxValue(15), | ||
), | ||
) | ||
.toJSON(), | ||
); | ||
|
||
this.subcommands["giveaway"] = [ | ||
{ | ||
name: "start", | ||
target: "start", | ||
}, | ||
]; | ||
} | ||
|
||
protected async _start(interaction: Command.ChatInput) { | ||
const { channel, guildId, user, options, client } = interaction; | ||
const { config, modules } = client; | ||
|
||
const prize = options.getString("prize", true); | ||
const duration: number | undefined = ms( | ||
options.getString("duration", true), | ||
); | ||
const winners = options.getInteger("winners", true); | ||
|
||
if (typeof duration === "undefined") { | ||
await interaction.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setDescription( | ||
"❌ Cú pháp thời gian không hợp lệ (5d, 5h, 5m, 5s).", | ||
) | ||
.setColor(config.colors.error), | ||
], | ||
ephemeral: true, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
if (duration < 5_000 || duration >= 30 * 24 * 60 * 60 * 1_000) { | ||
await interaction.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setDescription( | ||
"❌ Thời gian tối thiểu là 5 giây và tối đa là 30 ngày.", | ||
) | ||
.setColor(config.colors.error), | ||
], | ||
ephemeral: true, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
await modules.giveaway.create( | ||
guildId, | ||
channel!.id, | ||
user.id, | ||
prize, | ||
winners, | ||
new Date(Date.now() + duration), | ||
); | ||
|
||
await interaction.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setDescription("✅ Đã tạo giveaway mới.") | ||
.setColor(config.colors.default), | ||
], | ||
ephemeral: true, | ||
}); | ||
} | ||
} |
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,85 @@ | ||
import { | ||
ActionRowBuilder, | ||
ButtonBuilder, | ||
ButtonStyle, | ||
EmbedBuilder, | ||
} from "discord.js"; | ||
import Component from "../Component"; | ||
|
||
export default class Giveaway extends Component { | ||
static joinButton(disabled = false, amount = 0) { | ||
return new ButtonBuilder() | ||
.setCustomId(`giveaway|join`) | ||
.setLabel(`Tham gia (${amount})`) | ||
.setEmoji("🎉") | ||
.setStyle(ButtonStyle.Secondary) | ||
.setDisabled(disabled); | ||
} | ||
|
||
public constructor() { | ||
super("giveaway"); | ||
} | ||
|
||
public override async executeButton( | ||
interaction: Component.Button, | ||
args: string[], | ||
) { | ||
const { channelId, client, message, user } = interaction; | ||
const { modules, config } = client; | ||
|
||
const [choice] = args; | ||
|
||
switch (choice) { | ||
case "join": { | ||
const [status, userCount] = await modules.giveaway.passUser( | ||
channelId, | ||
message.id, | ||
user.id, | ||
); | ||
|
||
if (status === -1) { | ||
await interaction.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setDescription( | ||
"❌ Giveaway này không có trong dữ liệu của tớ.", | ||
) | ||
.setColor(config.colors.error), | ||
], | ||
ephemeral: true, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
if (status === 0) { | ||
await interaction.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setDescription("✅ Đã rời khỏi giveaway này!") | ||
.setColor(config.colors.default), | ||
], | ||
ephemeral: true, | ||
}); | ||
} else { | ||
await interaction.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setDescription("✅ Đã tham gia giveaway này!") | ||
.setColor(config.colors.default), | ||
], | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
await message.edit({ | ||
components: [ | ||
new ActionRowBuilder<any>().setComponents( | ||
Giveaway.joinButton(false, userCount), | ||
), | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
} |
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,15 @@ | ||
import type { Client } from "discord.js"; | ||
import Listener from "../Listener"; | ||
|
||
export default class extends Listener { | ||
public constructor() { | ||
super("ready"); | ||
} | ||
|
||
public override async execute(client: Client<true>) { | ||
const { modules } = client; | ||
|
||
modules.giveaway.start(); | ||
modules.tempVoice.start(); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...nts/modules/TempVoice/VoiceStateUpdate.ts → src/events/modules/TempVoice.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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import type { Client } from "discord.js"; | ||
import TempVoiceManager from "./modules/TempVoiceManager"; | ||
import GiveawayManager from "./modules/GiveawayManager"; | ||
|
||
export default class ModuleManager { | ||
public tempVoice: TempVoiceManager; | ||
public giveaway: GiveawayManager; | ||
|
||
public constructor(client: Client<true>) { | ||
this.tempVoice = new TempVoiceManager(client); | ||
this.giveaway = new GiveawayManager(client); | ||
} | ||
} |
Oops, something went wrong.