🚑 Fix api
This commit is contained in:
parent
99565f78a3
commit
11627f1d73
3 changed files with 21 additions and 21 deletions
|
@ -9,18 +9,19 @@ module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
const user = await interaction.options.getUser('user');
|
const user = await interaction.options.getUser('user');
|
||||||
|
|
||||||
logger.debug(i18next.t('commands:credits:general:key', { count: 1 }));
|
|
||||||
|
|
||||||
await credits
|
await credits
|
||||||
// eslint-disable-next-line max-len
|
.findOne(
|
||||||
.findOne({
|
{
|
||||||
userId: user ? user.id : interaction.user.id,
|
userId: user
|
||||||
guildId: interaction.member.guild.id,
|
? user.id
|
||||||
})
|
: interaction.user.id,
|
||||||
|
guildId: interaction.member.guild.id,
|
||||||
|
},
|
||||||
|
)
|
||||||
.then(async (data) => {
|
.then(async (data) => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: `${i18next.t('commands:credits:addons:balance:embed:title')}`,
|
title: 'Balance',
|
||||||
description: `${user} has no credits.`,
|
description: `${user} has no credits.`,
|
||||||
color: config.colors.success,
|
color: config.colors.success,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
|
@ -32,8 +33,8 @@ module.exports = async (interaction) => {
|
||||||
const { balance } = data;
|
const { balance } = data;
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
title: `${i18next.t('commands:credits:addons:balance:embed:title')}`,
|
title: 'Balance',
|
||||||
description: `${user ? `${user} has` : 'You have'} ${i18next.t('commands:credits:general:credits', { count: balance })}.`,
|
description: `${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`,
|
||||||
color: config.colors.success,
|
color: config.colors.success,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
|
|
@ -19,7 +19,7 @@ module.exports = async (interaction) => {
|
||||||
|
|
||||||
if (user.id === interaction.user.id) {
|
if (user.id === interaction.user.id) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
|
title: 'Gift',
|
||||||
description: "You can't pay yourself.",
|
description: "You can't pay yourself.",
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
|
@ -29,7 +29,7 @@ module.exports = async (interaction) => {
|
||||||
}
|
}
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
|
title: 'Gift',
|
||||||
description: "You can't pay zero or below.",
|
description: "You can't pay zero or below.",
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
|
@ -39,7 +39,7 @@ module.exports = async (interaction) => {
|
||||||
}
|
}
|
||||||
if (data.balance < amount) {
|
if (data.balance < amount) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
|
title: 'Gift',
|
||||||
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
|
@ -56,7 +56,7 @@ module.exports = async (interaction) => {
|
||||||
|
|
||||||
if (!toUser) {
|
if (!toUser) {
|
||||||
const embed = {
|
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',
|
description: 'That user has no credits, I can not gift credits to the user',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
|
@ -70,7 +70,7 @@ module.exports = async (interaction) => {
|
||||||
await saveUser(fromUser, toUser);
|
await saveUser(fromUser, toUser);
|
||||||
|
|
||||||
const interactionEmbed = {
|
const interactionEmbed = {
|
||||||
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
|
title: 'Gift',
|
||||||
description: `You sent ${creditNoun(amount)} to ${user}${
|
description: `You sent ${creditNoun(amount)} to ${user}${
|
||||||
reason ? ` with reason: ${reason}` : ''
|
reason ? ` with reason: ${reason}` : ''
|
||||||
}. Your new balance is ${creditNoun(fromUser.balance)}.`,
|
}. Your new balance is ${creditNoun(fromUser.balance)}.`,
|
||||||
|
@ -79,7 +79,7 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
const dmEmbed = {
|
const dmEmbed = {
|
||||||
title: `${i18next.t('commands:credits:addons:gift:embed:title')}`,
|
title: 'Gift',
|
||||||
description: `You received ${creditNoun(amount)} from ${interaction.user}${
|
description: `You received ${creditNoun(amount)} from ${interaction.user}${
|
||||||
reason ? ` with reason: ${reason}` : ''
|
reason ? ` with reason: ${reason}` : ''
|
||||||
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
||||||
|
|
|
@ -3,8 +3,7 @@ const axios = require('axios');
|
||||||
const config = require('../../../../config.json');
|
const config = require('../../../../config.json');
|
||||||
const logger = require('../../../handlers/logger');
|
const logger = require('../../../handlers/logger');
|
||||||
|
|
||||||
const guilds = require('../../../helpers/database/models/guildSchema');
|
const { guilds, credits, apis } = require('../../../helpers/database/models');
|
||||||
const credits = require('../../../helpers/database/models/creditSchema');
|
|
||||||
const creditNoun = require('../../../helpers/creditNoun');
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
// const api = require('../../../handlers/api');
|
// const api = require('../../../handlers/api');
|
||||||
|
@ -62,11 +61,11 @@ module.exports = async (interaction) => {
|
||||||
}
|
}
|
||||||
const code = uuidv4();
|
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({
|
const api = axios.create({
|
||||||
baseURL: guild.credits.url,
|
baseURL: apiCredentials.url,
|
||||||
headers: { Authorization: `Bearer ${guild.credits.token}` },
|
headers: { Authorization: `Bearer ${apiCredentials.token}` },
|
||||||
});
|
});
|
||||||
|
|
||||||
await api
|
await api
|
||||||
|
|
Loading…
Add table
Reference in a new issue