diff --git a/src/commands/cat.js b/src/commands/cat.js index 2200da4..e1b68f5 100644 --- a/src/commands/cat.js +++ b/src/commands/cat.js @@ -1,3 +1,4 @@ +const Resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); @@ -46,10 +47,10 @@ module.exports = (bot) => { bot.command("cat", spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); - const apiUrl = "https://cataas.com/cat?json=true"; + const apiUrl = `${Resources.catApi}?json=true`; const response = await axios.get(apiUrl); const data = response.data; - const imageUrl = `https://cataas.com/cat/${data._id}`; + const imageUrl = `${Resources.catApi}/${data._id}`; try { await ctx.replyWithPhoto(imageUrl, { diff --git a/src/commands/codename.js b/src/commands/codename.js index 88c4d7e..4f23137 100644 --- a/src/commands/codename.js +++ b/src/commands/codename.js @@ -1,3 +1,4 @@ +const Resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); @@ -5,7 +6,7 @@ const axios = require('axios'); async function getDeviceList() { try { - const response = await axios.get('https://raw.githubusercontent.com/androidtrackers/certified-android-devices/master/by_device.json'); + const response = await axios.get(Resources.codenameApi); return response.data } catch (error) { const message = Strings.codenameCheck.apiErr diff --git a/src/commands/dog.js b/src/commands/dog.js index 5a8d809..187cfb6 100644 --- a/src/commands/dog.js +++ b/src/commands/dog.js @@ -1,3 +1,4 @@ +const Resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); @@ -6,7 +7,7 @@ const axios = require('axios'); module.exports = (bot) => { bot.command("dog", spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); - const apiUrl = "https://dog.ceo/api/breeds/image/random"; + const apiUrl = Resources.dogApi; const response = await axios.get(apiUrl); const data = response.data; diff --git a/src/commands/fun.js b/src/commands/fun.js index 983c906..ed18910 100644 --- a/src/commands/fun.js +++ b/src/commands/fun.js @@ -1,4 +1,4 @@ -const resources = require('../props/resources.json'); +const Resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); @@ -84,17 +84,17 @@ module.exports = (bot) => { bot.command('idice', spamwatchMiddleware, async (ctx) => { ctx.replyWithSticker( - resources.infiniteDice, { + Resources.infiniteDice, { reply_to_message_id: ctx.message.message_id }); }); bot.command('furry', spamwatchMiddleware, async (ctx) => { - sendRandomReply(ctx, resources.furryGif, 'isFurry', 'isNtFurry'); + sendRandomReply(ctx, Resources.furryGif, 'isFurry', 'isNtFurry'); }); bot.command('gay', spamwatchMiddleware, async (ctx) => { - sendRandomReply(ctx, resources.gayFlag, 'isGay', 'isNtGay'); + sendRandomReply(ctx, Resources.gayFlag, 'isGay', 'isNtGay'); }); bot.command(['soggy', 'soggycat'], spamwatchMiddleware, async (ctx) => { @@ -103,8 +103,8 @@ module.exports = (bot) => { switch (true) { case (userInput === "2" || userInput === "thumb"): ctx.replyWithPhoto( - resources.soggyCat2, { - caption: resources.soggyCat2, + Resources.soggyCat2, { + caption: Resources.soggyCat2, parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id }); @@ -112,15 +112,15 @@ module.exports = (bot) => { case (userInput === "3" || userInput === "sticker"): ctx.replyWithSticker( - resources.soggyCatSticker, { + Resources.soggyCatSticker, { reply_to_message_id: ctx.message.message_id }); break; case (userInput === "4" || userInput === "alt"): ctx.replyWithPhoto( - resources.soggyCatAlt, { - caption: resources.soggyCatAlt, + Resources.soggyCatAlt, { + caption: Resources.soggyCatAlt, parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id }); @@ -128,8 +128,8 @@ module.exports = (bot) => { default: ctx.replyWithPhoto( - resources.soggyCat, { - caption: resources.soggyCat, + Resources.soggyCat, { + caption: Resources.soggyCat, parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id }); diff --git a/src/commands/http.js b/src/commands/http.js index 07a6e3f..13bd2ea 100644 --- a/src/commands/http.js +++ b/src/commands/http.js @@ -1,3 +1,4 @@ +const Resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); @@ -7,7 +8,7 @@ module.exports = (bot) => { bot.command("http", spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); const userInput = ctx.message.text.split(' ')[1]; - const apiUrl = "https://status.js.org/codes.json"; + const apiUrl = Resources.httpApi; if (!userInput || isNaN(userInput)) { return ctx.reply(Strings.httpCodes.invalidCode, { @@ -57,7 +58,7 @@ module.exports = (bot) => { }); } - const apiUrl = `https://http.cat/${userInput}`; + const apiUrl = `${Resources.httpCatApi}${userInput}`; try { await ctx.replyWithPhoto(apiUrl, { diff --git a/src/commands/lastfm.js b/src/commands/lastfm.js index 07d5554..1f15f5a 100644 --- a/src/commands/lastfm.js +++ b/src/commands/lastfm.js @@ -1,10 +1,11 @@ +const Resources = require('../props/resources.json'); const fs = require('fs'); const axios = require('axios'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); -const scrobbler_url = 'http://ws.audioscrobbler.com/2.0/'; +const scrobbler_url = Resources.lastFmApi; const api_key = process.env.lastKey; const dbFile = 'src/props/lastfm.json'; @@ -36,7 +37,7 @@ function saveUsers() { async function getFromMusicBrainz(mbid) { try { - const response = await axios.get(`https://coverartarchive.org/release/${mbid}`); + const response = await axios.get(`${Resources.musicBrainzApi}${mbid}`); const imgObjLarge = response.data.images[0]?.thumbnails?.['1200']; const imgObjMid = response.data.images[0]?.thumbnails?.large; const imageUrl = imgObjLarge || imgObjMid || ''; @@ -89,7 +90,7 @@ module.exports = (bot) => { const userId = ctx.from.id; const Strings = getStrings(ctx.from.language_code); const lastfmUser = users[userId]; - const genericImg = "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png"; + const genericImg = Resources.lastFmGenericImg; const botInfo = await ctx.telegram.getMe(); if (!lastfmUser) { diff --git a/src/commands/modarchive.js b/src/commands/modarchive.js index 3a10244..86d3c99 100644 --- a/src/commands/modarchive.js +++ b/src/commands/modarchive.js @@ -1,3 +1,4 @@ +const Resources = require('../props/resources.json'); const axios = require('axios'); const fs = require('fs'); const path = require('path'); @@ -7,7 +8,7 @@ const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(is async function downloadModule(moduleId) { try { - const downloadUrl = `https://api.modarchive.org/downloads.php?moduleid=${moduleId}`; + const downloadUrl = `${Resources.modArchiveApi}${moduleId}`; const response = await axios({ url: downloadUrl, method: 'GET', diff --git a/src/commands/ponyapi.js b/src/commands/ponyapi.js index 4e78473..8b59eb2 100644 --- a/src/commands/ponyapi.js +++ b/src/commands/ponyapi.js @@ -1,3 +1,4 @@ +const Resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); @@ -31,7 +32,7 @@ module.exports = (bot) => { }; const capitalizedInput = capitalizeFirstLetter(userInput); - const apiUrl = `http://ponyapi.net/v1/character/${capitalizedInput}`; + const apiUrl = `${Resources.ponyApi}/character/${capitalizedInput}`; try { const response = await axios(apiUrl); @@ -105,7 +106,7 @@ module.exports = (bot) => { return; }; - const apiUrl = `http://ponyapi.net/v1/episode/by-overall/${userInput}`; + const apiUrl = `${Resources.ponyApi}/episode/by-overall/${userInput}`; try { const response = await axios(apiUrl); @@ -174,7 +175,7 @@ module.exports = (bot) => { return; }; - const apiUrl = `http://ponyapi.net/v1/comics-story/${userInput}`; + const apiUrl = `${Resources.ponyApi}/comics-story/${userInput}`; try { const response = await axios(apiUrl); diff --git a/src/commands/quotes.js b/src/commands/quotes.js index 16c49f9..5e97b1f 100644 --- a/src/commands/quotes.js +++ b/src/commands/quotes.js @@ -1,3 +1,4 @@ +const Resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); @@ -8,7 +9,7 @@ module.exports = (bot) => { const Strings = getStrings(ctx.from.language_code); try { - const response = await axios.get('https://quotes-api-self.vercel.app/quote'); + const response = await axios.get(Resources.quoteApi); const data = response.data; const escapedQuote = data.quote.replace(/([\\_*~`>.!-])/g, '\\$1'); const escapedAuthor = `- ${data.author}.`.replace(/([\\_*~`>.!-])/g, '\\$1'); diff --git a/src/commands/weather.js b/src/commands/weather.js index 42c62bd..3818dad 100644 --- a/src/commands/weather.js +++ b/src/commands/weather.js @@ -2,6 +2,7 @@ // Copyright (c) 2024 BubbalooTeam. (https://github.com/BubbalooTeam) // Minor code changes by lucmsilva (https://github.com/lucmsilva651) +const Resources = require('../props/resources.json'); const axios = require('axios'); const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); @@ -46,7 +47,7 @@ module.exports = (bot) => { const apiKey = process.env.weatherKey; try { - const locationResponse = await axios.get('https://api.weather.com/v3/location/search', { + const locationResponse = await axios.get(`${Resources.weatherApi}/location/search`, { params: { apiKey: apiKey, format: 'json', @@ -69,7 +70,7 @@ module.exports = (bot) => { const countryCode = locationData.countryCode[0]; const { temperatureUnit, speedUnit, apiUnit } = getLocaleUnit(countryCode); - const weatherResponse = await axios.get('https://api.weather.com/v3/aggcommon/v3-wx-observations-current', { + const weatherResponse = await axios.get(`${Resources.weatherApi}/aggcommon/v3-wx-observations-current`, { params: { apiKey: apiKey, format: 'json', diff --git a/src/props/resources.json b/src/props/resources.json index eb35918..92449c8 100644 --- a/src/props/resources.json +++ b/src/props/resources.json @@ -5,5 +5,17 @@ "soggyCatSticker": "CAACAgEAAxkBAAJ9SWb0vY0Xgg4RtNQeU5iLOx3iTVRAAAKgAwACN-NRRFf8v9p0Nz1INgQ", "infiniteDice": "CAACAgQAAxkBAAJxjWbSSP-8ZNEhEpAJjQsHsGf-UuEPAAJCAAPI-uwTAAEBVWWh4ucINQQ", "gayFlag": "https://c.tenor.com/VTBe5BFc73sAAAAC/tenor.gif", - "furryGif": "https://c.tenor.com/_V_k0BVj48IAAAAd/tenor.gif" + "furryGif": "https://c.tenor.com/_V_k0BVj48IAAAAd/tenor.gif", + "codenameApi": "https://raw.githubusercontent.com/androidtrackers/certified-android-devices/master/by_device.json", + "catApi": "https://cataas.com/cat", + "dogApi": "https://dog.ceo/api/breeds/image/random", + "httpCatApi": "https://http.cat/", + "httpApi": "https://status.js.org/codes.json", + "lastFmApi": "http://ws.audioscrobbler.com/2.0/", + "musicBrainzApi": "https://coverartarchive.org/release/", + "lastFmGenericImg": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png", + "modArchiveApi": "https://api.modarchive.org/downloads.php?moduleid=", + "ponyApi": "http://ponyapi.net/v1", + "quoteApi": "https://quotes-api-self.vercel.app/quote", + "weatherApi": "https://api.weather.com/v3" } \ No newline at end of file