profile command
This commit is contained in:
52
commands/utility/profile.js
Normal file
52
commands/utility/profile.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||||
|
const torn = require('../../torn.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('profile')
|
||||||
|
.setDescription('Get your Torn profile')
|
||||||
|
.addIntegerOption(option =>
|
||||||
|
option.setName('id')
|
||||||
|
.setDescription('User ID')),
|
||||||
|
async execute(interaction) {
|
||||||
|
let id
|
||||||
|
console.log(interaction.options.getInteger('id'))
|
||||||
|
if (!interaction.options.getInteger('id')) {
|
||||||
|
id = await torn.self.id()
|
||||||
|
console.log(id + " yes")
|
||||||
|
} else {
|
||||||
|
id = interaction.options.getInteger('id');
|
||||||
|
console.log(id + " no");
|
||||||
|
}
|
||||||
|
userdata = await torn.user.profile(id);
|
||||||
|
console.log(userdata)
|
||||||
|
switch (userdata.status.color) {
|
||||||
|
case 'green':
|
||||||
|
userdata.status.hex = 0x69A829
|
||||||
|
break
|
||||||
|
case 'orange':
|
||||||
|
userdata.status.hex = 0xF6B200
|
||||||
|
break
|
||||||
|
case 'red':
|
||||||
|
userdata.status.hex = 0xF78483
|
||||||
|
break
|
||||||
|
case 'blue':
|
||||||
|
userdata.status.hex = 0x4A91B2
|
||||||
|
}
|
||||||
|
|
||||||
|
const userEmbed = new EmbedBuilder()
|
||||||
|
.setColor(userdata.status.hex)
|
||||||
|
.setTitle(`${userdata.name} [${userdata.player_id}]`)
|
||||||
|
.setURL(`https://torn.com/profiles.php?XID=${userdata.player_id}`)
|
||||||
|
.setImage(userdata.profile_image)
|
||||||
|
.setDescription(userdata.rank)
|
||||||
|
.addFields(
|
||||||
|
{ name: userdata.status.description, value: userdata.status.details },
|
||||||
|
{ name: 'Level', value: `${userdata.level}`, inline: true },
|
||||||
|
{ name: 'Age', value: `${userdata.age} days`, inline: true },
|
||||||
|
{ name: `${userdata.last_action.status}`, value: `${userdata.last_action.relative}`, inline: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [userEmbed] });
|
||||||
|
},
|
||||||
|
};
|
||||||
1
index.js
1
index.js
@@ -44,6 +44,7 @@ const commandFolders = fs.readdirSync(foldersPath);
|
|||||||
const command = require(filePath);
|
const command = require(filePath);
|
||||||
if ('data' in command && 'execute' in command) {
|
if ('data' in command && 'execute' in command) {
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
|
console.log(`Registered command "${command.data.name}"`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||||
}
|
}
|
||||||
|
|||||||
27
torn.js
27
torn.js
@@ -19,3 +19,30 @@ module.exports.api = async (url) => {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return(data);
|
return(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.user = {
|
||||||
|
async basic(user) {
|
||||||
|
const response = await fetch(`https://api.torn.com/user/${user}?selections=basic&key=${config.torn}`);
|
||||||
|
const data = await response.json();
|
||||||
|
return(data);
|
||||||
|
},
|
||||||
|
async profile(user) {
|
||||||
|
const response = await fetch(`https://api.torn.com/user/${user}?selections=profile&key=${config.torn}`);
|
||||||
|
const data = await response.json();
|
||||||
|
return(data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.self = {
|
||||||
|
async id() {
|
||||||
|
if (!config.tornid) {
|
||||||
|
const url = `https://api.torn.com/user/?selections=basic&key=${config.torn}`
|
||||||
|
const response = await fetch(url);
|
||||||
|
const data = await response.json();
|
||||||
|
config.tornid = data.player_id;
|
||||||
|
console.log('retreived player id: ' + data.player_id)
|
||||||
|
return(data.player_id);
|
||||||
|
} else return config.tornid;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user