Skip to content

Commit

Permalink
chore: add prettier config & cleanup comments
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecornejo1 committed Feb 15, 2024
1 parent 977bd5d commit cb8e8f6
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 161 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true
}
73 changes: 35 additions & 38 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
import dotenv from 'dotenv';
dotenv.config();
import pkg, { Interaction, InteractionCollector, InteractionCollectorOptions } from 'discord.js';
import pkg, { Interaction } from 'discord.js';
import { processPostRequest } from './scrapeProfileData';
const { Client, IntentsBitField, AttachmentBuilder } = pkg;

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
]
})
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on('ready', (c) => {
console.log(`✅ ${c.user.tag} is online `)
})

// client.on('messageCreate', (message) => {
// console.log(message.content)
// if (message.author.bot) return
// if (message.content === 'Hola' || message.content === 'hola') {
// message.reply('Hola!!')
// }
// })
console.log(`✅ ${c.user.tag} is online `);
});

client.on('interactionCreate', async (interaction: Interaction) => {
if (!interaction.isChatInputCommand()) return;
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}

if (interaction.commandName === 'perfil') {
const url = interaction.options.get('url')?.value as string;
if (interaction.commandName === 'perfil') {
const url = interaction.options.get('url')?.value as string;

await interaction.deferReply();
await interaction.deferReply();

console.log("url enviada por el usuario: ", url)
console.log('url enviada por el usuario: ', url);

const res = await processPostRequest(url);
const res = await processPostRequest(url);

console.log("datos obtenidos: ", res);
console.log('datos obtenidos: ', res);

const resString = JSON.stringify(res, null, 2);
if (resString.length <= 2000) {
await interaction.editReply(resString);
} else {
const buffer = Buffer.from(resString, 'utf-8');
const attachment = new AttachmentBuilder(buffer, { name: 'profile.json' });
await interaction.editReply({ content: 'The response is too large to display here. Please see the file.', files: [attachment] });
}
const resString = JSON.stringify(res, null, 2);
if (resString.length <= 2000) {
await interaction.editReply(resString);
} else {
const buffer = Buffer.from(resString, 'utf-8');
const attachment = new AttachmentBuilder(buffer, {
name: 'profile.json',
});
await interaction.editReply({
content:
'The response is too large to display here. Please see the file.',
files: [attachment],
});
}

}
});

client.login(process.env.TOKEN);

client.login(process.env.TOKEN)
Loading

0 comments on commit cb8e8f6

Please sign in to comment.