mirror of
https://github.com/TheShadowEevee/Konpeki-Discord-Bot.git
synced 2025-01-11 14:38:49 -06:00
Initial Commit
This commit is contained in:
commit
d4e3b0c2c2
13 changed files with 2844 additions and 0 deletions
49
.eslintrc.json
Normal file
49
.eslintrc.json
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
{
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2021
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"arrow-spacing": ["warn", { "before": true, "after": true }],
|
||||||
|
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
||||||
|
"comma-dangle": ["error", "always-multiline"],
|
||||||
|
"comma-spacing": "error",
|
||||||
|
"comma-style": "error",
|
||||||
|
"curly": ["error", "multi-line", "consistent"],
|
||||||
|
"dot-location": ["error", "property"],
|
||||||
|
"handle-callback-err": "off",
|
||||||
|
"indent": ["error", "tab"],
|
||||||
|
"keyword-spacing": "error",
|
||||||
|
"max-nested-callbacks": ["error", { "max": 4 }],
|
||||||
|
"max-statements-per-line": ["error", { "max": 2 }],
|
||||||
|
"no-console": "off",
|
||||||
|
"no-empty-function": "error",
|
||||||
|
"no-floating-decimal": "error",
|
||||||
|
"no-inline-comments": "error",
|
||||||
|
"no-lonely-if": "error",
|
||||||
|
"no-multi-spaces": "error",
|
||||||
|
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
|
||||||
|
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
|
||||||
|
"no-trailing-spaces": ["error"],
|
||||||
|
"no-var": "error",
|
||||||
|
"object-curly-spacing": ["error", "always"],
|
||||||
|
"prefer-const": "error",
|
||||||
|
"quotes": ["error", "single"],
|
||||||
|
"semi": ["error", "always"],
|
||||||
|
"space-before-blocks": "error",
|
||||||
|
"space-before-function-paren": ["error", {
|
||||||
|
"anonymous": "never",
|
||||||
|
"named": "never",
|
||||||
|
"asyncArrow": "always"
|
||||||
|
}],
|
||||||
|
"space-in-parens": "error",
|
||||||
|
"space-infix-ops": "error",
|
||||||
|
"space-unary-ops": "error",
|
||||||
|
"spaced-comment": "error",
|
||||||
|
"yoda": "error"
|
||||||
|
}
|
||||||
|
}
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
config.json
|
||||||
|
node_modules
|
7
LICENSE
Normal file
7
LICENSE
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Copyright © 2022 TheShadowEevee and Contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
70
commands/avatar.js
Normal file
70
commands/avatar.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Konpeki Shiho - Slash Command Definition File
|
||||||
|
* avatar.js - A primative Discord avatar grabbing function
|
||||||
|
*
|
||||||
|
* Todo: Allow users to choose between the sizes as an optional dropdown
|
||||||
|
* Todo: Allow users to choose if they want to avatar to be ephemeral or sent in the channel
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('avatar')
|
||||||
|
.setDescription('Shares a users current avatar')
|
||||||
|
|
||||||
|
// Optional user selection for avatar target; target selves if none.
|
||||||
|
.addUserOption(option =>
|
||||||
|
option.setName('user')
|
||||||
|
.setDescription('The user to get the avatar from'))
|
||||||
|
|
||||||
|
// Optional choice for user to choose avatar size; 4096 if no selection.
|
||||||
|
.addStringOption(option =>
|
||||||
|
option.setName('format')
|
||||||
|
.setDescription('The gif category')
|
||||||
|
.addChoices(
|
||||||
|
{ name: '4096px', value: '4096' },
|
||||||
|
{ name: '2048px', value: '2048' },
|
||||||
|
{ name: '1024px', value: '1024' },
|
||||||
|
{ name: '600px', value: '600' },
|
||||||
|
{ name: '512px', value: '512' },
|
||||||
|
{ name: '300px', value: '300' },
|
||||||
|
{ name: '256px', value: '256' },
|
||||||
|
{ name: '128px', value: '128' },
|
||||||
|
{ name: '96px', value: '96' },
|
||||||
|
{ name: '64px', value: '64' },
|
||||||
|
{ name: '56px', value: '56' },
|
||||||
|
{ name: '32px', value: '32' },
|
||||||
|
{ name: '16px', value: '16' },
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
// Optional choice for user to choose avatar format; webp if no selection.
|
||||||
|
.addStringOption(option =>
|
||||||
|
option.setName('size')
|
||||||
|
.setDescription('The gif category')
|
||||||
|
.addChoices(
|
||||||
|
{ name: 'WebP', value: 'webp' },
|
||||||
|
{ name: 'PNG', value: 'png' },
|
||||||
|
{ name: 'JPEG', value: 'jpg' },
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
// Optional Ephemeral check to allow user to choose command results to be shared publicly or private; send to self only if no selection.
|
||||||
|
.addStringOption(option =>
|
||||||
|
option.setName('ephemeral')
|
||||||
|
.setDescription('Post the avatar in the current channel')
|
||||||
|
.addChoices(
|
||||||
|
{ name: 'Send to me only', value: 'true' },
|
||||||
|
{ name: 'Send in channel', value: 'false' },
|
||||||
|
)),
|
||||||
|
|
||||||
|
async execute(interaction) {
|
||||||
|
const discordUser = interaction.options.getUser('user') ?? interaction.user;
|
||||||
|
const avatarFormat = interaction.options.getString('format') ?? 'webp';
|
||||||
|
const avatarSize = interaction.options.getString('size') ?? 4096;
|
||||||
|
const isEphemeral = interaction.options.getString('ephemeral') ?? true;
|
||||||
|
|
||||||
|
await interaction.reply({ content: `${discordUser.avatarURL({ format:avatarFormat, size:avatarSize, dynamic:true })}`, ephemeral: isEphemeral });
|
||||||
|
},
|
||||||
|
};
|
24
commands/embed-sample.js.disabled
Normal file
24
commands/embed-sample.js.disabled
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Konpeki Shiho - Slash Command Definition File
|
||||||
|
* embed-sample.js - A simple generator for embeds to test the possibilities avalible
|
||||||
|
*
|
||||||
|
* See https://discordjs.guide/popular-topics/embeds.html for more information on embeds
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('embed-sample')
|
||||||
|
.setDescription('Sample Embed Generator'),
|
||||||
|
async execute(interaction) {
|
||||||
|
const exampleEmbed = new EmbedBuilder()
|
||||||
|
.setColor(0x0099FF)
|
||||||
|
.setTitle('Sample Embed')
|
||||||
|
.setAuthor({ name: `${interaction.client.user.username}`, iconURL: `${interaction.client.user.avatarURL({ size:4096, dynamic:true })}` })
|
||||||
|
.setDescription('Some Embed Text');
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [exampleEmbed], ephemeral: true });
|
||||||
|
},
|
||||||
|
};
|
17
commands/ping.js
Normal file
17
commands/ping.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Konpeki Shiho - Slash Command Definition File
|
||||||
|
* ping.js - A simple ping function
|
||||||
|
*
|
||||||
|
* Function modified from https://discordjs.guide/creating-your-bot/slash-commands.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('ping')
|
||||||
|
.setDescription('Checks to see if the you or the bot is online'),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.reply({ content: 'Pong!', ephemeral: true });
|
||||||
|
},
|
||||||
|
};
|
16
commands/rtd-ephemeral.js
Normal file
16
commands/rtd-ephemeral.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* Konpeki Shiho - Slash Command Definition File
|
||||||
|
* rtd-ephemeral.js - In-Dev function
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('rtd-ephemeral')
|
||||||
|
.setDescription('Currently being integrated. Outputs a XKCD valid random number.'),
|
||||||
|
async execute(interaction) {
|
||||||
|
const xkcdRandomNumber = 4;
|
||||||
|
await interaction.reply({ content: `${interaction.client.user.tag} - Integration test of RTD command: XKCD random number is ${xkcdRandomNumber}.\nThis number is chosen by a fair dice roll and guaranteed to be random.\nSee <https://xkcd.com/221/>`, ephemeral: true });
|
||||||
|
},
|
||||||
|
};
|
16
commands/rtd.js
Normal file
16
commands/rtd.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* Konpeki Shiho - Slash Command Definition File
|
||||||
|
* rtd.js - In-Dev function
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('rtd')
|
||||||
|
.setDescription('Currently being integrated. Outputs a XKCD valid random number.'),
|
||||||
|
async execute(interaction) {
|
||||||
|
const xkcdRandomNumber = 4;
|
||||||
|
await interaction.reply({ content: `${interaction.client.user.tag} - Integration test of RTD command: XKCD random number is ${xkcdRandomNumber}.\nThis number is chosen by a fair dice roll and guaranteed to be random.\nSee <https://xkcd.com/221/>`, ephemeral: false });
|
||||||
|
},
|
||||||
|
};
|
22
delete-commands.js
Normal file
22
delete-commands.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
const { REST, Routes } = require('discord.js');
|
||||||
|
const { clientId, token } = require('./config.json');
|
||||||
|
|
||||||
|
// Construct and prepare an instance of the REST module
|
||||||
|
const rest = new REST({ version: '10' }).setToken(token);
|
||||||
|
|
||||||
|
// and deploy your commands!
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log('Started deleting all application (/) commands.');
|
||||||
|
|
||||||
|
// The put method is used to fully refresh all commands
|
||||||
|
rest.put(Routes.applicationCommands(clientId), { body: [] })
|
||||||
|
.then(() => console.log('Successfully deleted all application (/) commands.'))
|
||||||
|
.catch(console.error);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// And of course, make sure you catch and log any errors!
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
35
deploy-commands.js
Normal file
35
deploy-commands.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
const { REST, Routes } = require('discord.js');
|
||||||
|
const { clientId, token } = require('./config.json');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
// Grab all the command files from the commands directory you created earlier
|
||||||
|
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const command = require(`./commands/${file}`);
|
||||||
|
commands.push(command.data.toJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct and prepare an instance of the REST module
|
||||||
|
const rest = new REST({ version: '10' }).setToken(token);
|
||||||
|
|
||||||
|
// and deploy your commands!
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||||
|
|
||||||
|
// The put method is used to fully refresh all commands
|
||||||
|
const data = await rest.put(
|
||||||
|
Routes.applicationCommands(clientId),
|
||||||
|
{ body: commands },
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// And of course, make sure you catch and log any errors!
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
63
index.js
Normal file
63
index.js
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Konpeki Shiho - Main Bot File
|
||||||
|
* All base level bot setup is done here
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Require filesystem libraries
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
// Require the necessary discord.js classes
|
||||||
|
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
|
||||||
|
const { token, botOwner } = require('./config.json');
|
||||||
|
|
||||||
|
// Create a new client instance
|
||||||
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||||
|
|
||||||
|
// Setup the commands collection
|
||||||
|
client.commands = new Collection();
|
||||||
|
|
||||||
|
const commandsPath = path.join(__dirname, 'commands');
|
||||||
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const filePath = path.join(commandsPath, file);
|
||||||
|
const command = require(filePath);
|
||||||
|
// Set a new item in the Collection with the key as the command name and the value as the exported module
|
||||||
|
if ('data' in command && 'execute' in command) {
|
||||||
|
client.commands.set(command.data.name, command);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the client is ready, run this code (only once)
|
||||||
|
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
|
||||||
|
client.once(Events.ClientReady, c => {
|
||||||
|
console.log(`Ready! Logged in as ${c.user.tag}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Client "on" Events
|
||||||
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
const command = interaction.client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||||
|
await interaction.reply({ content: `This command no longer exists! Please contact ${botOwner} to report that this is happening!`, ephemeral: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await command.execute(interaction);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Log in to Discord with your client's token
|
||||||
|
client.login(token);
|
2489
package-lock.json
generated
Normal file
2489
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
34
package.json
Normal file
34
package.json
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"discord.js": "^14.7.1",
|
||||||
|
"dotenv": "^16.0.3"
|
||||||
|
},
|
||||||
|
"name": "rollthedice-discordbot",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A Discord Bot that throws out random scenarios based on a premade list",
|
||||||
|
"main": "index.js",
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^8.29.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/TheShadowEevee/RollTheDice-DiscordBot.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"RTD",
|
||||||
|
"Discord",
|
||||||
|
"Bot",
|
||||||
|
"Roll",
|
||||||
|
"The",
|
||||||
|
"Dice"
|
||||||
|
],
|
||||||
|
"author": "TheShadowEevee",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/TheShadowEevee/RollTheDice-DiscordBot/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/TheShadowEevee/RollTheDice-DiscordBot#readme"
|
||||||
|
}
|
Loading…
Reference in a new issue