🚑 Fix api

This commit is contained in:
Axel Olausson Holtenäs 2022-03-09 21:20:35 +01:00
parent 99565f78a3
commit 11627f1d73
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
3 changed files with 21 additions and 21 deletions

View file

@ -9,18 +9,19 @@ module.exports = async (interaction) => {
try {
const user = await interaction.options.getUser('user');
logger.debug(i18next.t('commands:credits:general:key', { count: 1 }));
await credits
// eslint-disable-next-line max-len
.findOne({
userId: user ? user.id : interaction.user.id,
guildId: interaction.member.guild.id,
})
.findOne(
{
userId: user
? user.id
: interaction.user.id,
guildId: interaction.member.guild.id,
},
)
.then(async (data) => {
if (!data) {
const embed = {
title: `${i18next.t('commands:credits:addons:balance:embed:title')}`,
title: 'Balance',
description: `${user} has no credits.`,
color: config.colors.success,
timestamp: new Date(),
@ -32,8 +33,8 @@ module.exports = async (interaction) => {
const { balance } = data;
const embed = {
title: `${i18next.t('commands:credits:addons:balance:embed:title')}`,
description: `${user ? `${user} has` : 'You have'} ${i18next.t('commands:credits:general:credits', { count: balance })}.`,
title: 'Balance',
description: `${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`,
color: config.colors.success,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },

View file

@ -19,7 +19,7 @@ module.exports = async (interaction) => {
if (user.id === interaction.user.id) {
const embed = {
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
title: 'Gift',
description: "You can't pay yourself.",
color: 0xbb2124,
timestamp: new Date(),
@ -29,7 +29,7 @@ module.exports = async (interaction) => {
}
if (amount <= 0) {
const embed = {
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
title: 'Gift',
description: "You can't pay zero or below.",
color: 0xbb2124,
timestamp: new Date(),
@ -39,7 +39,7 @@ module.exports = async (interaction) => {
}
if (data.balance < amount) {
const embed = {
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
title: 'Gift',
description: `You have insufficient credits. Your balance is ${data.balance}`,
color: 0xbb2124,
timestamp: new Date(),
@ -56,7 +56,7 @@ module.exports = async (interaction) => {
if (!toUser) {
const embed = {
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
title: 'Gift',
description: 'That user has no credits, I can not gift credits to the user',
color: config.colors.error,
timestamp: new Date(),
@ -70,7 +70,7 @@ module.exports = async (interaction) => {
await saveUser(fromUser, toUser);
const interactionEmbed = {
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
title: 'Gift',
description: `You sent ${creditNoun(amount)} to ${user}${
reason ? ` with reason: ${reason}` : ''
}. Your new balance is ${creditNoun(fromUser.balance)}.`,
@ -79,7 +79,7 @@ module.exports = async (interaction) => {
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
const dmEmbed = {
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
title: 'Gift',
description: `You received ${creditNoun(amount)} from ${interaction.user}${
reason ? ` with reason: ${reason}` : ''
}. Your new balance is ${creditNoun(toUser.balance)}.`,

View file

@ -3,8 +3,7 @@ const axios = require('axios');
const config = require('../../../../config.json');
const logger = require('../../../handlers/logger');
const guilds = require('../../../helpers/database/models/guildSchema');
const credits = require('../../../helpers/database/models/creditSchema');
const { guilds, credits, apis } = require('../../../helpers/database/models');
const creditNoun = require('../../../helpers/creditNoun');
// const api = require('../../../handlers/api');
@ -62,11 +61,11 @@ module.exports = async (interaction) => {
}
const code = uuidv4();
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
const apiCredentials = await apis.findOne({ guildId: interaction.member.guild.id });
const api = axios.create({
baseURL: guild.credits.url,
headers: { Authorization: `Bearer ${guild.credits.token}` },
baseURL: apiCredentials.url,
headers: { Authorization: `Bearer ${apiCredentials.token}` },
});
await api