diff --git a/index.js b/index.js index f15e81b..c6c68e5 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,19 @@ const config = require('./config.json'); const state = require('./state.json'); // the basic discord setup stuff yoinked from their guide -const { Client, Collection, Events, GatewayIntentBits, SlashCommandBuilder } = require('discord.js'); -const client = new Client({ intents: [GatewayIntentBits.Guilds] }); +const { Client, Collection, Events, GatewayIntentBits, EmbedBuilder, Partials } = require('discord.js'); +const client = new Client({ + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.DirectMessages, + GatewayIntentBits.MessageContent + ], + partials: [ + Partials.Channel, + Partials.Message + ] +}); client.once(Events.ClientReady, readyClient => { console.log(`Connected to Discord as ${readyClient.user.tag}`); }); @@ -68,3 +79,45 @@ client.on(Events.InteractionCreate, async interaction => { } } }); + + +client.on(Events.MessageCreate, message => { + // if we smell a profile link, resolve it + const regexProfile = /https?:\/\/(?:www\.)?torn\.com\/profiles.*?[?&]XID=(\d+)/; + if (message.content.match(regexProfile)) { + const profileId = message.content.match(regexProfile)[1] + torn.user.profile(profileId).then(data => { + if (data.name) { // copied from commands/utility/profile.js + switch (data.status.color) { + case 'green': + data.status.hex = 0x69A829 + break + case 'orange': + data.status.hex = 0xF6B200 + break + case 'red': + data.status.hex = 0xF78483 + break + case 'blue': + data.status.hex = 0x4A91B2 + } + // the embed is also copied from the profile command, + // but this way we can tweak it + const userEmbed = new EmbedBuilder() + .setColor(data.status.hex) + .setTitle(`${data.name} [${data.player_id}]`) + .setURL(`https://torn.com/profiles.php?XID=${data.player_id}`) + .setImage(data.profile_image) + .setDescription(data.rank) + .addFields( + { name: data.status.description, value: data.status.details }, + { name: 'Level', value: `${data.level}`, inline: true }, + { name: 'Age', value: `${data.age} days`, inline: true }, + { name: `${data.last_action.status}`, value: `${data.last_action.relative}`, inline: true }, + ); + console.log(userEmbed) + message.reply({ embeds: [userEmbed] }) + } + }); + } +}); diff --git a/profile.png b/profile.png new file mode 100644 index 0000000..39f1b9c Binary files /dev/null and b/profile.png differ diff --git a/tasks/example.js b/tasks/example.js index d37c5bb..e57fc76 100644 --- a/tasks/example.js +++ b/tasks/example.js @@ -1,4 +1,6 @@ -module.exports = (client, config, state) => { +module.exports = async (client, torn, config, state) => { //console.log(`example log ${client.user.tag}`); + //const alertChannel = client.channels.resolve(config.alerts) + //alertChannel.send('test') }; module.exports.schedule = '*/5 * * * * *'; \ No newline at end of file