From f997d52235f89993aeb40d67c49e547a4d14dc1b Mon Sep 17 00:00:00 2001 From: coopw1 <48886919+coopw1@users.noreply.github.com> Date: Tue, 9 Jan 2024 23:11:57 -0500 Subject: [PATCH] Added proper useragents --- src/commands/general/brainz.js | 3 ++- src/commands/general/util/getAlbumCover.js | 3 +++ src/commands/general/util/getCurrentlyPlaying.js | 1 + src/commands/general/util/getMBID.js | 3 +++ src/commands/general/util/getRecentlyPlayed.js | 1 + src/commands/general/util/getSongInfo.js | 1 + src/commands/general/util/getTopStatistics.js | 1 + src/commands/general/util/getTotalScrobbles.js | 1 + src/commands/userSettings/login.js | 2 ++ src/commands/userSettings/settings.js | 1 + src/commands/util/convertSvgToPng.js | 4 +++- src/commands/util/getAuth.js | 1 + 12 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/commands/general/brainz.js b/src/commands/general/brainz.js index 84818d9..49c2939 100644 --- a/src/commands/general/brainz.js +++ b/src/commands/general/brainz.js @@ -9,7 +9,6 @@ const { ComponentType, } = require("discord.js"); const axios = require("axios").default; -require("dotenv").config(); const getCurrentlyPlaying = require("./util/getCurrentlyPlaying"); const getRecentlyPlayed = require("./util/getRecentlyPlayed"); @@ -68,6 +67,7 @@ async function checkIfLoved( const BASE_URL = `https://api.listenbrainz.org/1/feedback/user/${brainzUsername}/get-feedback-for-recordings`; const AUTH_HEADER = { Authorization: `Token ${listenBrainzToken}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; const PARAMS = { params: { @@ -165,6 +165,7 @@ async function sendFeedback(feedback, listenBrainzToken, MBID, MSID) { const BASE_URL = `https://api.listenbrainz.org/1/feedback/recording-feedback`; const AUTH_HEADER = { Authorization: `Token ${listenBrainzToken}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; const PARAMS = { recording_mbid: MBID, diff --git a/src/commands/general/util/getAlbumCover.js b/src/commands/general/util/getAlbumCover.js index 7a1351b..304e90b 100644 --- a/src/commands/general/util/getAlbumCover.js +++ b/src/commands/general/util/getAlbumCover.js @@ -11,6 +11,9 @@ module.exports = async (MBID) => { try { const BASE_URL = "http://musicbrainz.org/ws/2/recording/"; const PARAMS = { + headers: { + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", + }, params: { query: `rid:${MBID}`, }, diff --git a/src/commands/general/util/getCurrentlyPlaying.js b/src/commands/general/util/getCurrentlyPlaying.js index 39ce14a..a842c6a 100644 --- a/src/commands/general/util/getCurrentlyPlaying.js +++ b/src/commands/general/util/getCurrentlyPlaying.js @@ -12,6 +12,7 @@ module.exports = async (listenBrainzToken, brainzUsername) => { const BASE_URL = `https://api.listenbrainz.org/1/user/${brainzUsername}/playing-now`; const AUTH_HEADER = { Authorization: `Token ${listenBrainzToken}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; // Make request to ListenBrainz diff --git a/src/commands/general/util/getMBID.js b/src/commands/general/util/getMBID.js index 87ab070..bd49e3a 100644 --- a/src/commands/general/util/getMBID.js +++ b/src/commands/general/util/getMBID.js @@ -21,6 +21,9 @@ module.exports = async ( params: { query: ``, }, + headers: { + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", + }, }; if (artistName) { PARAMS.params.query = PARAMS.params.query + `artist:${artistName}`; diff --git a/src/commands/general/util/getRecentlyPlayed.js b/src/commands/general/util/getRecentlyPlayed.js index 78ab15f..a7520e2 100644 --- a/src/commands/general/util/getRecentlyPlayed.js +++ b/src/commands/general/util/getRecentlyPlayed.js @@ -12,6 +12,7 @@ module.exports = async (listenBrainzToken, brainzUsername) => { const BASE_URL = `https://api.listenbrainz.org/1/user/${brainzUsername}/listens`; const AUTH_HEADER = { Authorization: `Token ${listenBrainzToken}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; // Make request to ListenBrainz diff --git a/src/commands/general/util/getSongInfo.js b/src/commands/general/util/getSongInfo.js index f4b62cc..6460554 100644 --- a/src/commands/general/util/getSongInfo.js +++ b/src/commands/general/util/getSongInfo.js @@ -18,6 +18,7 @@ module.exports = async ( const BASE_URL = `https://api.listenbrainz.org/1/metadata/lookup/`; const AUTH_HEADER = { Authorization: `Token ${listenBrainzToken}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; const PARAMS = { params: { diff --git a/src/commands/general/util/getTopStatistics.js b/src/commands/general/util/getTopStatistics.js index e6df1ad..e91fd6b 100644 --- a/src/commands/general/util/getTopStatistics.js +++ b/src/commands/general/util/getTopStatistics.js @@ -24,6 +24,7 @@ module.exports = async ( try { const AUTH_HEADER = { Authorization: `Token ${listenBrainzToken}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; let BASE_URL; diff --git a/src/commands/general/util/getTotalScrobbles.js b/src/commands/general/util/getTotalScrobbles.js index c3cf086..7281d8c 100644 --- a/src/commands/general/util/getTotalScrobbles.js +++ b/src/commands/general/util/getTotalScrobbles.js @@ -12,6 +12,7 @@ module.exports = async (listenBrainzToken, brainzUsername) => { const BASE_URL = `https://api.listenbrainz.org/1/user/${brainzUsername}/listen-count`; const AUTH_HEADER = { Authorization: `Token ${listenBrainzToken}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; // Make request to ListenBrainz diff --git a/src/commands/userSettings/login.js b/src/commands/userSettings/login.js index 86dd81e..59d5c59 100644 --- a/src/commands/userSettings/login.js +++ b/src/commands/userSettings/login.js @@ -131,6 +131,7 @@ module.exports = { "https://api.listenbrainz.org/1/validate-token"; const AUTH_HEADER = { Authorization: `Token ${token}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; // Make request to ListenBrainz @@ -224,6 +225,7 @@ module.exports = { const BASE_URL = "https://api.listenbrainz.org/1/validate-token"; const AUTH_HEADER = { Authorization: `Token ${token}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; // Make request to ListenBrainz diff --git a/src/commands/userSettings/settings.js b/src/commands/userSettings/settings.js index 964782b..c6e1fd2 100644 --- a/src/commands/userSettings/settings.js +++ b/src/commands/userSettings/settings.js @@ -42,6 +42,7 @@ module.exports = { const BASE_URL = `https://api.listenbrainz.org/1/search/users/`; const AUTH_HEADER = { Authorization: `Token ${process.env.LISTENBRAINZ_TOKEN}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; const PARAMS = { diff --git a/src/commands/util/convertSvgToPng.js b/src/commands/util/convertSvgToPng.js index ed92ea7..94cfa5b 100644 --- a/src/commands/util/convertSvgToPng.js +++ b/src/commands/util/convertSvgToPng.js @@ -19,7 +19,9 @@ const preset = presets.node({ * @return {promise} - The converted PNG image. */ module.exports = async (link) => { - const response = await axios.get(link); + const response = await axios.get(link, { + headers: { "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)" }, + }); const svg = response.data; const canvas = preset.createCanvas(800, 600); const ctx = canvas.getContext("2d"); diff --git a/src/commands/util/getAuth.js b/src/commands/util/getAuth.js index 7379625..cc2e2f0 100644 --- a/src/commands/util/getAuth.js +++ b/src/commands/util/getAuth.js @@ -38,6 +38,7 @@ module.exports = async (interaction, noAuthNeeded) => { const BASE_URL = `https://api.listenbrainz.org/1/search/users/`; const AUTH_HEADER = { Authorization: `Token ${process.env.LISTENBRAINZ_TOKEN}`, + "User-Agent": "DiscordBrainzBot/1.0.0 (coopwd@skiff.com)", }; const PARAMS = {