All APIs on resources.json

This commit is contained in:
Lucas Gabriel 2025-02-07 23:37:09 -03:00
parent b0d9e55edf
commit 2d02e6213f
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985
11 changed files with 49 additions and 28 deletions

View File

@ -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, {

View File

@ -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

View File

@ -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;

View File

@ -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
});

View File

@ -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, {

View File

@ -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) {

View File

@ -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',

View File

@ -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);

View File

@ -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');

View File

@ -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',

View File

@ -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"
}