Skip to content

feat: major refactors and adding spotify save functionality - #9

Merged
jaredgrxss merged 3 commits into
mainfrom
addingSpotifySave
Aug 19, 2025
Merged

feat: major refactors and adding spotify save functionality#9
jaredgrxss merged 3 commits into
mainfrom
addingSpotifySave

Conversation

@jaredgrxss

Copy link
Copy Markdown
Owner

No description provided.

@jaredgrxss
jaredgrxss requested a review from Copilot August 18, 2025 22:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds Spotify integration functionality to the Amplify Discord bot, allowing users to save songs and playlists from the current queue to their Spotify accounts. The changes also include refactoring of the environment variable handling and improvements to the audio playback system.

Key changes:

  • Added Spotify OAuth authentication and save functionality for tracks and playlists
  • Refactored environment variable encryption/decryption into a separate module
  • Enhanced audio playback system with lazy resource loading and automatic queue progression

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/index.ts Updated env handling to use new module and added auth server startup
src/helpers/spotify.ts New module implementing Spotify OAuth and save functionality
src/helpers/server.ts New Express server for handling Spotify OAuth callbacks
src/helpers/playback.ts Enhanced with lazy loading, auto-progression, and queue snapshot functions
src/helpers/envs.ts New module extracting env encryption/decryption logic
src/helpers/components.ts Added "Save to Spotify" button to playback controls
src/helpers/buttons.ts Added handler for Spotify save button interactions
package.json Added Express and its type definitions as dependencies

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/helpers/spotify.ts Outdated
return saveMultiTrack(token, songs);
} catch {
return {
msg: "An error occured while attempting to save to spotify",

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a spelling error: 'occured' should be 'occurred'.

Suggested change
msg: "An error occured while attempting to save to spotify",
msg: "An error occurred while attempting to save to spotify",

Copilot uses AI. Check for mistakes.
Comment thread src/helpers/server.ts Outdated
}
});
app.listen(port, () => {
logger.info(`Spotify callback server listening on http:/127.0.0.1:${port}`);

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing forward slash in URL: 'http:/127.0.0.1' should be 'http://127.0.0.1'.

Suggested change
logger.info(`Spotify callback server listening on http:/127.0.0.1:${port}`);
logger.info(`Spotify callback server listening on http://127.0.0.1:${port}`);

Copilot uses AI. Check for mistakes.
Comment thread src/helpers/spotify.ts

const SCOPES = ["user-library-modify", "playlist-modify-private"].join(" ");

const userTokens = new Map<string, TokenInfo>();

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User tokens are stored in memory only. This means tokens will be lost on server restart, requiring users to re-authenticate. Consider persisting tokens to a database or file system for better user experience.

Copilot uses AI. Check for mistakes.
Comment thread src/helpers/spotify.ts
grant_type: "refresh_token",
refresh_token: token.refreshToken,
client_id: process.env.SPOTIFY_CLIENT_ID!,
client_secret: process.env.SPOTIFY_CLIENT_SECRET!,

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing input validation for required environment variables. The function should validate that SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET are set before making the API call.

Suggested change
client_secret: process.env.SPOTIFY_CLIENT_SECRET!,
if (!process.env.SPOTIFY_CLIENT_ID || !process.env.SPOTIFY_CLIENT_SECRET) {
// Required environment variables are missing
return null;
}
const res = await fetch("https://accounts.spotify.com/api/token", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "refresh_token",
refresh_token: token.refreshToken,
client_id: process.env.SPOTIFY_CLIENT_ID,
client_secret: process.env.SPOTIFY_CLIENT_SECRET,

Copilot uses AI. Check for mistakes.
Comment thread src/helpers/spotify.ts
if (songs.length <= 1) return saveSingleTrack(interaction.guildId!, token);

return saveMultiTrack(token, songs);
} catch {

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty catch block discards error information. Consider logging the error to help with debugging when Spotify save operations fail.

Suggested change
} catch {
} catch (err) {
console.error("Error in saveToUsersSpotify:", err);

Copilot uses AI. Check for mistakes.
Comment thread src/helpers/playback.ts Outdated
// player.on(AudioPlayerStatus.Idle, () => {
// endSession(i.guildId!);
// });
nextPlayback(i.guildId!);

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling async function nextPlayback without await in an event handler could lead to unhandled promise rejections if the function throws an error.

Suggested change
nextPlayback(i.guildId!);
nextPlayback(i.guildId!).catch((err) => {
logger.error(`Error in nextPlayback: ${err instanceof Error ? err.message : String(err)}`);
});

Copilot uses AI. Check for mistakes.
@jaredgrxss
jaredgrxss merged commit 742642b into main Aug 19, 2025
1 check passed
@jaredgrxss
jaredgrxss deleted the addingSpotifySave branch August 19, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants