-
Notifications
You must be signed in to change notification settings - Fork 0
feat: adding buttons to random command #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f23fd4c
getting main random command finished
jaredgrxss 1d52f12
working on vibe commands
jaredgrxss b520260
fixing linting rules
jaredgrxss 8f32593
Update src/helpers/open-ai.ts
jaredgrxss 332af2e
minor bug fixes
jaredgrxss 0b524e2
major refactors for better readability and maintainability
jaredgrxss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,10 @@ | ||
| import "discord.js"; | ||
| import type { Collection } from "discord.js"; | ||
| import type { DiscordCommand, CommandCooldowns } from "./commands.ts"; | ||
| import type { CommandCooldowns, SlashCommand } from "./commands.ts"; | ||
|
|
||
| declare module "discord.js" { | ||
| interface Client { | ||
| commands: Collection<string, DiscordCommand>; | ||
| commands: Collection<string, SlashCommand>; | ||
| cooldowns: CommandCooldowns; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
| import { describe, test, expect } from "@jest/globals"; | ||
|
|
||
| describe("src/index.ts", () => { | ||
| test("sayHello function should return a greeting with the given name", () => { | ||
| // Arrange | ||
| const name = "Hello World"; | ||
|
|
||
| // Assert | ||
| expect(name).toBe("Hello World"); | ||
| }); | ||
| }); |
This file contains hidden or 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,44 @@ | ||
| import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js"; | ||
| import type { SlashCommand } from "../../@types/commands.js"; | ||
| import { logger } from "../../helpers/logger.js"; | ||
| import { getPlaylistsByVibe } from "../../helpers/open-ai.js"; | ||
| import { SongPick } from "../../@types/open-ai.js"; | ||
| // import { playSongFromYoutube } from "../../helpers/playback.js"; | ||
|
|
||
| async function execute( | ||
| interaction: ChatInputCommandInteraction, | ||
| ): Promise<void> { | ||
| try { | ||
| await interaction.deferReply(); | ||
| const songs: SongPick[] = await getPlaylistsByVibe( | ||
| interaction.options.getString("vibe")!, | ||
| ); | ||
| logger.info( | ||
| `The songs we picked are ${songs.map((song) => song.title).join(", ")}`, | ||
| ); | ||
| } catch (err) { | ||
| logger.error(`Error in execute function for command [VIBE]: ${err}`); | ||
| await interaction.editReply({ | ||
| content: "An unexpected error occured, try again later.", | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export const command: SlashCommand = { | ||
| cooldown: 20, | ||
| data: new SlashCommandBuilder() | ||
| .setName("vibe") | ||
| .setDescription( | ||
| "Generates a curated playlist to listen to based on the desired vibe.", | ||
| ) | ||
| .addStringOption((option) => | ||
| option | ||
| .setName("vibe") | ||
| .setDescription( | ||
| "Give a brief description of the vibe you are going for.", | ||
| ) | ||
| .setRequired(true) | ||
| .setMaxLength(200), | ||
| ), | ||
| execute, | ||
| }; |
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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,101 @@ | ||
| import { ButtonInteraction, CacheType } from "discord.js"; | ||
| import { | ||
| pausePlayback, | ||
| resumePlayback, | ||
| removePlayback, | ||
| } from "../helpers/playback.js"; | ||
|
|
||
| export async function handleButtonInteraction( | ||
| interaction: ButtonInteraction<CacheType>, | ||
| ) { | ||
| if (!interaction.guildId) return; | ||
| switch (interaction.customId) { | ||
| case "play": | ||
| await handlePlayButton(interaction); | ||
| break; | ||
| case "remove": | ||
| await handleRemoveButton(interaction); | ||
| break; | ||
| case "pause": | ||
| await handlePauseButton(interaction); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| async function handlePlayButton(interaction: ButtonInteraction<CacheType>) { | ||
| const msg = resumePlayback(interaction.guildId!); | ||
| await interaction.update({ | ||
| content: msg, | ||
| components: [ | ||
| { | ||
| type: 1, | ||
| components: [ | ||
| { | ||
| type: 2, | ||
| custom_id: "remove", | ||
| label: "Remove", | ||
| style: 4, | ||
| disabled: false, | ||
| }, | ||
| { | ||
| type: 2, | ||
| custom_id: "pause", | ||
| label: "Pause", | ||
| style: 2, | ||
| disabled: false, | ||
| }, | ||
| { | ||
| type: 2, | ||
| custom_id: "play", | ||
| label: "Play", | ||
| style: 1, | ||
| disabled: true, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| async function handleRemoveButton(interaction: ButtonInteraction<CacheType>) { | ||
| const msg = removePlayback(interaction.guildId!); | ||
| await interaction.update({ | ||
| content: msg, | ||
| components: [], | ||
| }); | ||
| } | ||
|
|
||
| async function handlePauseButton(interaction: ButtonInteraction<CacheType>) { | ||
| const msg = pausePlayback(interaction.guildId!); | ||
| await interaction.update({ | ||
| content: msg, | ||
| components: [ | ||
| { | ||
| type: 1, | ||
| components: [ | ||
| { | ||
| type: 2, | ||
| custom_id: "remove", | ||
| label: "Remove", | ||
| style: 4, | ||
| disabled: false, | ||
| }, | ||
| { | ||
| type: 2, | ||
| custom_id: "pause", | ||
| label: "Pause", | ||
| style: 2, | ||
| disabled: true, | ||
| }, | ||
| { | ||
| type: 2, | ||
| custom_id: "play", | ||
| label: "Play", | ||
| style: 1, | ||
| disabled: false, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interaction.editReply is called twice (lines 28 and 54-57), which will cause an error since the interaction can only be edited once after being deferred.