Skip to content

Commit

Permalink
First bot version. Need to add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Best-Codes committed Aug 20, 2024
0 parents commit 379c76d
Show file tree
Hide file tree
Showing 15 changed files with 893 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# node
node_modules
.npm
*.log
*.pid
*.pid.lock
*.lock
*.pidb
*.pidb.lock

# vscode
.vscode
.vscode-insiders

# npm
package-lock.json
yarn.lock

# git
.git

# docker
.Dockerfile
.Dockerignore

# env
.env
.env.local
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "capybot",
"version": "1.0.0",
"description": "Your friendly Capybara Bot is capyble or fulfilling all your Discord needs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"bot",
"discord",
"capybara"
],
"author": "The-Best-Codes",
"license": "MIT",
"dependencies": {
"axios": "^1.7.4",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
"openai": "^4.56.0",
"perf_hooks": "^0.0.1",
"winston": "^3.14.2"
}
}
62 changes: 62 additions & 0 deletions src/commands/capyfact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

const facts = [
"Capybaras are the largest rodents in the world, weighing up to 150 pounds.",
"Capybaras can hold their breath underwater for up to five minutes.",
"Capybaras are social animals and live in groups of 10-20 individuals called herds.",
"Capybaras can run as fast as 35 km/h (22 mph), almost as fast as a small horse.",
"Capybaras have webbed feet, which helps them swim and walk on muddy ground.",
"Capybaras are herbivores and can eat up to 8 pounds of grass per day.",
"Capybaras are native to South America and are found in dense forests near bodies of water.",
"Capybaras can sleep in water, keeping their noses above the surface.",
"The scientific name for capybara is 'Hydrochoerus hydrochaeris', which means 'water pig'.",
"Capybaras can vocalize in various ways, including barks, whistles, and purrs.",
];

module.exports = {
data: new SlashCommandBuilder()
.setName('capyfact')
.setDescription('Get a random capybara fact'),
async execute(interaction) {
const randomFact = facts[Math.floor(Math.random() * facts.length)];

const embed = new EmbedBuilder()
.setColor('#964B00')
.setTitle('🐹 Capybara Fact 🐹')
.setDescription(randomFact)
.setFooter({ text: 'Capybaras are awesome!' })
.setTimestamp();

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('new_capyfact')
.setLabel('New Fact')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('love_capybara')
.setLabel('❤️')
.setStyle(ButtonStyle.Secondary)
);

await interaction.editReply({ embeds: [embed], components: [row] });

const message = await interaction.fetchReply();
const collector = message.createMessageComponentCollector({ time: 60000 });

collector.on('collect', async i => {
if (i.customId === 'new_capyfact') {
const newFact = facts[Math.floor(Math.random() * facts.length)];
embed.setDescription(newFact);
await i.update({ embeds: [embed], components: [row] });
} else if (i.customId === 'love_capybara') {
await i.reply({ content: 'Capybaras love you too! 🐹❤️', ephemeral: true });
}
});

collector.on('end', () => {
interaction.editReply({ components: [] }).catch(console.error);
});
},
};
86 changes: 86 additions & 0 deletions src/commands/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const axios = require('axios');
const config = require('../config');

const filterPrompt = (prompt) => {
const inappropriateWords = ['nsfw', 'nude', 'explicit'];
return inappropriateWords.some(word => prompt.toLowerCase().includes(word));
};

module.exports = {
data: new SlashCommandBuilder()
.setName('image')
.setDescription('Generate an image based on a prompt')
.addStringOption(option =>
option.setName('prompt')
.setDescription('Describe the image you want to generate')
.setRequired(true))
.addIntegerOption(option =>
option.setName('width')
.setDescription('Image width (default: 1024)')
.setRequired(false)
.setMinValue(256)
.setMaxValue(2048))
.addIntegerOption(option =>
option.setName('height')
.setDescription('Image height (default: 576)')
.setRequired(false)
.setMinValue(256)
.setMaxValue(2048)),

async execute(interaction) {
const prompt = interaction.options.getString('prompt');
const width = interaction.options.getInteger('width') || 1024;
const height = interaction.options.getInteger('height') || 576;

if (filterPrompt(prompt)) {
await interaction.editReply('Sorry, your prompt contains inappropriate content. Please try a different prompt.');
return;
}

const seed = Math.floor(Math.random() * 1000000);
const encodedPrompt = encodeURIComponent(prompt);
const imageUrl = `https://image.pollinations.ai/prompt/${encodedPrompt}?width=${width}&height=${height}&nologo=poll&nofeed=yes&seed=${seed}`;

try {
// Pre-fetch the image
await axios.get(imageUrl, { responseType: 'arraybuffer' });

const embed = new EmbedBuilder()
.setColor('#00FFFF')
.setTitle('Generated Image')
.setDescription(`Prompt: ${prompt}`)
.setImage(imageUrl)
.setFooter({ text: 'Powered by Pollinations AI' })
.setTimestamp();

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('report_image')
.setLabel('Report Image')
.setStyle(ButtonStyle.Danger)
);

const message = await interaction.editReply({ embeds: [embed], components: [row] });

const collector = message.createMessageComponentCollector({ time: 60000 });

collector.on('collect', async i => {
if (i.customId === 'report_image') {
const owner = await interaction.client.users.fetch(config.discord.owner_id);
await owner.send(`Image reported by ${interaction.user.tag}:\nPrompt: ${prompt}\nImage URL: ${imageUrl}`);
await i.reply({ content: 'Image reported. Thank you for your feedback!', ephemeral: true });
}
});

collector.on('end', () => {
interaction.editReply({ components: [] }).catch(console.error);
});

} catch (error) {
console.error('Error generating image:', error);
await interaction.editReply('Sorry, there was an error generating the image. Please try again later.');
}
},
};
104 changes: 104 additions & 0 deletions src/commands/joke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const axios = require('axios');
const config = require('../config');

const filterJoke = (joke) => {
const inappropriateWords = ['inappropriate', 'offensive', 'nsfw']; // Add more words as needed
return inappropriateWords.some(word => joke.toLowerCase().includes(word)) ? null : joke;
};

module.exports = {
data: new SlashCommandBuilder()
.setName('joke')
.setDescription('Get a random joke')
.addStringOption(option =>
option.setName('category')
.setDescription('Choose your joke category')
.setRequired(false)
.addChoices(
{ name: '😂 General', value: 'general' },
{ name: '💻 Programming', value: 'programming' },
{ name: '🤓 Dad', value: 'dad' },
)),

async execute(interaction) {
const category = interaction.options.getString('category') || 'general';
const jokeApi = {
general: 'https://official-joke-api.appspot.com/random_joke',
programming: 'https://v2.jokeapi.dev/joke/Programming?type=twopart&safe-mode',
dad: 'https://icanhazdadjoke.com/',
};

try {
const response = await axios.get(jokeApi[category], {
headers: category === 'dad' ? { Accept: 'application/json' } : {}
});

let setup, punchline;

switch (category) {
case 'general':
({ setup, punchline } = response.data);
break;
case 'programming':
({ setup, delivery: punchline } = response.data);
break;
case 'dad':
setup = response.data.joke;
punchline = "The punchline is missing. 🤷‍♂️";
break;
}

// Filter the joke
setup = filterJoke(setup);
punchline = filterJoke(punchline);

if (!setup || !punchline) {
throw new Error('Inappropriate content filtered');
}

const embed = new EmbedBuilder()
.setColor('#FFA500')
.setTitle('🎭 Joke Time!')
.setDescription(setup)
.addFields({ name: 'Punchline', value: punchline })
.setFooter({ text: `Category: ${category.charAt(0).toUpperCase() + category.slice(1)}` })
.setTimestamp();

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('report_joke')
.setLabel('Report Joke')
.setStyle(ButtonStyle.Danger)
);

await interaction.editReply({ embeds: [embed], components: [row] });

// Create a message component collector
const message = await interaction.fetchReply();
const filter = i => i.customId === 'report_joke' && i.user.id === interaction.user.id;
const collector = message.createMessageComponentCollector({ filter, time: 60000 });

collector.on('collect', async i => {
const owner = await interaction.client.users.fetch(config.discord.owner_id);
await owner.send(`Joke reported by ${interaction.user.tag}:\n\nSetup: ${setup}\nPunchline: ${punchline}`);
await i.reply({ content: 'Joke reported. Thank you for your feedback!', ephemeral: true });
});

// Easter egg: 5% chance of a groan reaction
if (Math.random() < 0.05) {
await interaction.followUp("😩 That was terrible! But hey, at least you didn't have to pay for it!");
}

} catch (error) {
console.error(error);
const errorMessage = error.message === 'Inappropriate content filtered'
? 'Sorry, that joke didn\'t pass our content filter. Let me find you a better one!'
: 'Sorry, I couldn\'t fetch a joke. My comedy career is in shambles!';

await interaction.editReply({ content: errorMessage, ephemeral: true });
}
},
};
61 changes: 61 additions & 0 deletions src/commands/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Unleash the power of PONG!')
.addStringOption(option =>
option.setName('style')
.setDescription('Choose your ping style')
.setRequired(false)
.addChoices(
{ name: '🎾 Tennis', value: 'tennis' },
{ name: '🏓 Table Tennis', value: 'table_tennis' },
{ name: '🏐 Volleyball', value: 'volleyball' },
{ name: '🧠 Telepathic', value: 'telepathic' },
)),

async execute(interaction) {
const pingStyles = {
tennis: { emoji: '🎾', sound: 'Pop!' },
table_tennis: { emoji: '🏓', sound: 'Tik-tok!' },
volleyball: { emoji: '🏐', sound: 'Boing!' },
telepathic: { emoji: '🧠', sound: '...' },
};

const style = interaction.options.getString('style') || 'tennis';
const { emoji, sound } = pingStyles[style];

const startTime = Date.now();

const response = async () => {
const endTime = Date.now();
const latency = endTime - startTime;

const embed = new EmbedBuilder()
.setColor('#FF1493')
.setTitle(`${emoji} Super Pong-tastic!`)
.setDescription(`**${sound}** Your ping bounced back in style!`)
.addFields(
{ name: 'Latency', value: `${latency}ms`, inline: true },
{ name: 'Pong Power', value: `${Math.max(0, 100 - latency)}%`, inline: true },
)
.setFooter({ text: 'Powered by quantum entanglement' })
.setTimestamp();

return { embeds: [embed], content: "" };
};

if (interaction.deferred) {
await interaction.editReply(await response());
} else {
await interaction.reply(await response());
}

// Easter egg: 1% chance of a surprise reaction
if (Math.random() < 0.01) {
await interaction.followUp("🎉 Wow! You've discovered the secret pong! \nThere's a 1% chance of receiving this message.");
}
},
};
Loading

0 comments on commit 379c76d

Please sign in to comment.