Skip to content

Commit

Permalink
Format with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
TecEash1 committed Apr 11, 2024
1 parent 2898342 commit 435d65c
Show file tree
Hide file tree
Showing 25 changed files with 1,601 additions and 1,285 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github
package.json
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
</p>

## 🤔 What is this bot?

The **Taurus Discord Bot** is a small bot, it can be used for several things such as:

- Image Generation
- AI GPT chats and personality customisations

## 💾 Install

1. fill in the token and other values in ``config.json.example``
1. fill in the token and other values in `config.json.example`

2. Rename the file to ``config.json``
2. Rename the file to `config.json`

3. Run ``npm i``
3. Run `npm i`

4. Run ``node bot``
4. Run `node bot`

**Note** - Alternatively **instead of steps 3 & 4** you can **run one of the startbot/start scripts.**

- All PR's are welcome for improvements.

### ℹ️ Getting API Keys:

- https://ai.google.dev
- https://app.prodia.com/api

### 🏗️ Additional Credits

- This bot utilizes a modified version of the [discord bot template](https://github.com/NamVr/DiscordBot-Template) made
by [Naman Vrati](https://github.com/NamVr)! [\[Apache License 2.0\]](https://github.com/NamVr/DiscordBot-Template/blob/master/LICENSE)
by [Naman Vrati](https://github.com/NamVr)! [\[Apache License 2.0\]](https://github.com/NamVr/DiscordBot-Template/blob/master/LICENSE)
56 changes: 29 additions & 27 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
Partials,
REST,
Routes,
SlashCommandBuilder
SlashCommandBuilder,
} = require("discord.js");
const { token, client_id } = require("./config.json");

Expand Down Expand Up @@ -58,7 +58,7 @@ for (const file of eventFiles) {
} else {
client.on(
event.name,
async (...args) => await event.execute(...args, client)
async (...args) => await event.execute(...args, client),
);
}
}
Expand Down Expand Up @@ -114,7 +114,9 @@ for (const module of autocompleteInteractions) {
.filter((file) => file.endsWith(".js"));

for (const interactionFile of files) {
const interaction = require(`./interactions/autocomplete/${module}/${interactionFile}`);
const interaction = require(
`./interactions/autocomplete/${module}/${interactionFile}`,
);
client.autocompleteInteractions.set(interaction.name, interaction);
}
}
Expand Down Expand Up @@ -142,7 +144,6 @@ for (const folder of contextMenus) {
}
}


/**********************************************************************/
// Registration of Modal-Command Interactions.

Expand Down Expand Up @@ -179,11 +180,11 @@ const functionFiles = fs.readdirSync("./functions");
// Loop through all files and store functions in functions collection.

for (const functionFile of functionFiles) {
if (functionFile.endsWith(".js")) {
const func = require(`./functions/${functionFile}`);
client.functions.set(functionFile.replace('.js', ''), func);
func(client);
}
if (functionFile.endsWith(".js")) {
const func = require(`./functions/${functionFile}`);
client.functions.set(functionFile.replace(".js", ""), func);
func(client);
}
}

/**********************************************************************/
Expand All @@ -192,18 +193,19 @@ for (const functionFile of functionFiles) {
const rest = new REST({ version: "9" }).setToken(token);

const commandJsonData = [
...Array.from(client.slashCommands.values()).map((c) => {
const commandData = c.data instanceof SlashCommandBuilder ? c.data.toJSON() : c.data;
commandData.integration_types = [1];
commandData.contexts = [0, 1, 2];
return commandData;
}),
...Array.from(client.slashCommands.values()).map((c) => {
const commandData =
c.data instanceof SlashCommandBuilder ? c.data.toJSON() : c.data;
commandData.integration_types = [1];
commandData.contexts = [0, 1, 2];
return commandData;
}),
...Array.from(client.contextCommands.values()).map((c) => {
const commandData = c.data;
commandData.integration_types = [1];
commandData.contexts = [0, 1, 2];
return commandData;
})
const commandData = c.data;
commandData.integration_types = [1];
commandData.contexts = [0, 1, 2];
return commandData;
}),
];

(async () => {
Expand All @@ -213,7 +215,7 @@ const commandJsonData = [
await rest.put(
Routes.applicationCommands(client_id),

{ body: commandJsonData }
{ body: commandJsonData },
);

console.log("Successfully reloaded application (/) commands.");
Expand All @@ -233,15 +235,15 @@ process.on("unhandledRejection", (reason, promise) => {

// Uncomment the below lines below to see the full error details. - ADVANCED DEBUGGING //

// console.dir(reason, { showHidden: true, depth: null });
// console.log("Promise: ", promise);
// console.dir(reason, { showHidden: true, depth: null });
// console.log("Promise: ", promise);
});

process.on("uncaughtException", (error, origin) => {
console.error(`🚫 Critical Error detected:\n\n`, error, origin);

// Uncomment the below lines below to see the full error details. - ADVANCED DEBUGGING //

// console.dir(error, { showHidden: true, depth: null });
// console.log("Origin: ", origin);
});
// console.dir(error, { showHidden: true, depth: null });
// console.log("Origin: ", origin);
});
4 changes: 2 additions & 2 deletions events/autocompleteInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
// Checks if the request is available in our code.

const request = client.autocompleteInteractions.get(
interaction.commandName
interaction.commandName,
);

// If the interaction is not a request in cache return.
Expand All @@ -43,4 +43,4 @@ module.exports = {
return Promise.reject(err);
}
},
};
};
22 changes: 12 additions & 10 deletions events/contextInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {

if (interaction.isUserContextMenuCommand()) {
const command = client.contextCommands.get(
"USER " + interaction.commandName
"USER " + interaction.commandName,
);

// A try to execute the interaction.
Expand All @@ -39,26 +39,28 @@ module.exports = {
} catch (err) {
console.error(err);
await interaction.reply({
content: "There was an issue while executing that context command! If the issue persists please contact the bot owners.",
ephemeral: true
content:
"There was an issue while executing that context command! If the issue persists please contact the bot owners.",
ephemeral: true,
});
}
}
// Checks if the interaction target was a message
else if (interaction.isMessageContextMenuCommand()) {
const command = client.contextCommands.get(
"MESSAGE " + interaction.commandName
"MESSAGE " + interaction.commandName,
);

// A try to execute the interaction.

try {
return await command.execute(interaction);
} catch (err) {
console.dir(err, { showHidden: true });
console.error(err);
await interaction.reply({
content: "There was an issue while executing that context command! If the issue persists please contact the bot owners.",
ephemeral: true
content:
"There was an issue while executing that context command! If the issue persists please contact the bot owners.",
ephemeral: true,
});
}
}
Expand All @@ -67,8 +69,8 @@ module.exports = {
// Possible Fix is a restart!
else {
return console.log(
"Something weird happening in context menu. Received a context menu of unknown type. If the issue persists please contact the bot owners."
"Something weird happening in context menu. Received a context menu of unknown type. If the issue persists please contact the bot owners.",
);
}
}
};
},
};
10 changes: 7 additions & 3 deletions events/modalInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ module.exports = {

if (!interaction.isModalSubmit()) return;

if (interaction.customId === 'taurus_ai_personality') return;
if (interaction.customId === "taurus_ai_personality") return;

const command = client.modalCommands.get(interaction.customId);

// If the interaction is not a command in cache, return error message.
// You can modify the error message at ./messages/defaultModalError.js file!

if (!command) {
return await require("../messages/defaultModalError").execute(interaction);
return await require("../messages/defaultModalError").execute(
interaction,
);
}

// A try to execute the interaction.

const error = new EmbedBuilder()
.setDescription("**There was an issue while understanding this modal!\n\nPlease contact the Developers.**")
.setDescription(
"**There was an issue while understanding this modal!\n\nPlease contact the Developers.**",
)
.setColor("Red");

try {
Expand Down
11 changes: 5 additions & 6 deletions events/onMention.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@

const { Events, EmbedBuilder } = require("discord.js");


module.exports = {
name: Events.MessageCreate,


async execute(message) {

const {client} = message;
const { client } = message;

if (
message.content == `<@${client.user.id}>` ||
message.content == `<@!${client.user.id}>`
) {
const bot_message = new EmbedBuilder()
.setDescription(`Hi ${message.author}! I am Taurus. Chat to me by mentioning me and typing your message! Or alternatively run \`/taurus\`!`)
.setDescription(
`Hi ${message.author}! I am Taurus. Chat to me by mentioning me and typing your message! Or alternatively run \`/taurus\`!`,
)
.setColor("Gold");

return message.reply({embeds: [bot_message]});
return message.reply({ embeds: [bot_message] });
}
},
};
15 changes: 8 additions & 7 deletions events/onReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ module.exports = {
* @param {import('../typings').Client} client Main Application Client.
*/
execute(client) {

client.user.setPresence({
activities: [{
type: ActivityType.Custom,
name: "Status",
state: "💾 Chilling on my owners computer!"
}]
})
activities: [
{
type: ActivityType.Custom,
name: "Status",
state: "💾 Chilling on my owners computer!",
},
],
});

console.log(`Ready! Logged in as ${client.user.tag}`);
},
Expand Down
30 changes: 21 additions & 9 deletions events/slashCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

const { Collection, EmbedBuilder, Events } = require("discord.js"),
{ botInGuild } = require("../utils"),
{ owner } = require("../config.json");
{ botInGuild } = require("../utils"),
{ owner } = require("../config.json");

module.exports = {
name: Events.InteractionCreate,
Expand Down Expand Up @@ -45,7 +45,11 @@ module.exports = {
if (interaction.inGuild()) {
if (botInGuild(interaction)) {
allowedRoleIds = ["...", "..."];
if (interaction.member.roles.cache.some(role => allowedRoleIds.includes(role.id))) {
if (
interaction.member.roles.cache.some((role) =>
allowedRoleIds.includes(role.id),
)
) {
const cooldownPercentage = 0.5;
cooldownAmount = Math.floor(cooldownAmount * cooldownPercentage);
}
Expand All @@ -54,10 +58,13 @@ module.exports = {

const isOwner = owner.includes(interaction.user.id);
if (!isOwner && timestamps.has(interaction.user.id)) {
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount * 1000;
const expirationTime =
timestamps.get(interaction.user.id) + cooldownAmount * 1000;
const timeLeft = (expirationTime - now) / 1000;
const embed = new EmbedBuilder()
.setDescription(`Please wait \`\`${timeLeft.toFixed(1)}\`\` more second(s) before reusing the \`${interaction.commandName}\` command.`)
.setDescription(
`Please wait \`\`${timeLeft.toFixed(1)}\`\` more second(s) before reusing the \`${interaction.commandName}\` command.`,
)
.setColor("Orange");
if (now < expirationTime) {
const expiredTimestamp = Math.round(expirationTime / 1000);
Expand All @@ -66,19 +73,24 @@ module.exports = {
}

timestamps.set(interaction.user.id, now);
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount * 1000);
setTimeout(
() => timestamps.delete(interaction.user.id),
cooldownAmount * 1000,
);

const error = new EmbedBuilder()
.setDescription("**There was an issue while executing that command!\n\nPlease contact the Developers.**")
.setDescription(
"**There was an issue while executing that command!\n\nPlease contact the Developers.**",
)
.setColor("Red");

try {
await command.execute(interaction);
} catch (err) {
await interaction.reply({
embeds: [error],
ephemeral: true
ephemeral: true,
});
}
}
},
};
Loading

0 comments on commit 435d65c

Please sign in to comment.