initial commit
This commit is contained in:
commit
6adb1bebe7
10 changed files with 1627 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": {
|
||||
"no-unused-vars": "warn",
|
||||
"arrow-spacing": ["warn", { "before": true, "after": 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": ["off"],
|
||||
"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": "warn",
|
||||
"no-multiple-empty-lines": ["warn", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
|
||||
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
|
||||
"no-trailing-spaces": ["warn"],
|
||||
"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 @@
|
|||
/node_modules
|
||||
config.json
|
0
README.md
Normal file
0
README.md
Normal file
45
commands/boss_warner_cmd.js
Normal file
45
commands/boss_warner_cmd.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
const { SlashCommandBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('bosswarner')
|
||||
.setDescription('Checks how long until the next boss spawn.')
|
||||
.addNumberOption(option =>
|
||||
option
|
||||
.setName('roundlength')
|
||||
.setDescription('Current round length. Get this by using /roundlength in-game.')
|
||||
.setRequired(true))
|
||||
.addBooleanOption(option =>
|
||||
option
|
||||
.setName('alert')
|
||||
.setDescription('Whether or not you want to be alerted three minutes before the boss spawns.')
|
||||
.default(false)
|
||||
.setRequired(false)),
|
||||
async execute(interaction) {
|
||||
const boss_dict = {
|
||||
'Punisher': 28.3,
|
||||
'X-0': 60,
|
||||
'Decimator': 60,
|
||||
'Galleon': 70,
|
||||
'Kodiak': 120,
|
||||
};
|
||||
const roundlength = interaction.options.getNumber('roundlength');
|
||||
if (interaction.options.getNumber('roundlength') < 0) {
|
||||
interaction.reply('Round length cannot be negative.');
|
||||
return;
|
||||
}
|
||||
if (interaction.options.getBoolean('alert') === true) {
|
||||
interaction.reply('Alerts are not yet implemented.');
|
||||
return;
|
||||
}
|
||||
if (interaction.options.getBoolean('alert') === false) {
|
||||
const spawnTimes = {};
|
||||
for (const boss in boss_dict) {
|
||||
const timeUntilSpawn = boss_dict[boss] - (roundlength % boss_dict[boss]);
|
||||
spawnTimes[boss] = timeUntilSpawn;
|
||||
}
|
||||
|
||||
interaction.reply(`Time until next boss spawn: ${JSON.stringify(spawnTimes)}`);
|
||||
}
|
||||
},
|
||||
};
|
12
commands/ping_cmd.js
Normal file
12
commands/ping_cmd.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
const { SlashCommandBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Replies with Pong!'),
|
||||
async execute(interaction) {
|
||||
interaction.reply('🏓').then (async (msg) => {
|
||||
msg.edit(`🏓Latency is \`${Date.now() - msg.createdTimestamp}ms\``);
|
||||
});
|
||||
},
|
||||
};
|
5
config.json.example
Normal file
5
config.json.example
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"token": "Token",
|
||||
"clientId": "Client ID",
|
||||
"guildId": "Guild ID"
|
||||
}
|
46
deploy.js
Normal file
46
deploy.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const { REST, Routes } = require('discord.js');
|
||||
const { clientId, guildId, token } = require('./config.json');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const commands = [];
|
||||
// Grab all the command files from the commands directory you created earlier
|
||||
const foldersPath = path.join(__dirname, 'commands');
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
// Grab all the command files from the commands directory you created earlier
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('_cmd.js'));
|
||||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
if ('data' in command && 'execute' in command) {
|
||||
commands.push(command.data.toJSON());
|
||||
} else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Construct and prepare an instance of the REST module
|
||||
const rest = new REST().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 in the guild with the current set
|
||||
const data = await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ 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 @@
|
|||
// Require the necessary discord.js classes
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
|
||||
const { token } = require('./config.json');
|
||||
|
||||
// Create a new client instance
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
// Handle dynamically reading and executing commands.
|
||||
client.commands = new Collection();
|
||||
|
||||
// Retrieve the commands directory and the files inside of it, including subdirectories.
|
||||
const foldersPath = path.join(__dirname, 'commands');
|
||||
const commandDirectories = fs.readdirSync(foldersPath);
|
||||
|
||||
// Load the command files.
|
||||
for (const directory of commandDirectories) {
|
||||
const commandsPath = path.join(foldersPath, directory);
|
||||
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's 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}`);
|
||||
});
|
||||
|
||||
// Create a listener to respond to interaction 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.`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deffered) {
|
||||
await interaction.followUp({ content: 'There was an error while executing this command!', epheremal: true });
|
||||
} else {
|
||||
await interaction.reply({ content: 'There was an error while executing this command!', epheremal: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Log in to Discord with your client's token
|
||||
client.login(token);
|
1384
package-lock.json
generated
Normal file
1384
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
21
package.json
Normal file
21
package.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "galaxybotspawnwarner",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://coastalcommits.com/SeaswimmerTheFsh/GalaxyBotSpawnWarner"
|
||||
},
|
||||
"author": "SeaswimmerTheFsh",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"discord.js": "^14.13.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.47.0"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue