added slash command and basic functionality

This commit is contained in:
Carter Penterman 2022-05-12 14:56:35 -05:00
parent e536d6b61c
commit fda4a09112
7 changed files with 298 additions and 40 deletions

20
README.md Normal file
View File

@ -0,0 +1,20 @@
## maptest bot
to setup (requires node.js):
* create a copy of example_config.json named config.json
* fill out empty values with correct values in config.json (token is discord token, cookie is .ROBLOSECURITY cookie, clientId is the bot's ID (right click bot in discord then choose copy ID with developer mode enabled))
* install dependencies
```
npm install
```
* register slash commands globally (this only needs to be ran once)
```
node deploy-commands.js
```
* run the bot
```
node bot.js
```
also, the bot requires the applications.commands scope, which can be found in developer portal -> bot -> oauth2 -> url generator -> scopes, simply generate link with applications.commands scope checked then add bot to server (can be done if bot already in server)

40
bot.js
View File

@ -1,19 +1,33 @@
const noblox = require("noblox.js"); const fs = require('node:fs');
const { Client, Intents } = require("discord.js"); const { Client, Collection, Intents } = require("discord.js");
const {cookie, token} = require("./config.json"); const {token} = require("./config.json");
function buyAsset(id) { const client = new Client({ intents: [Intents.FLAGS.GUILDS]});
noblox.setCookie(cookie)
.then(async () => { client.commands = new Collection();
noblox.buy(921233306, 0) const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
.catch(async (error) => {
console.log("Could not purchase, error: ") for (const file of commandFiles) {
console.log(error) const command = require(`./commands/${file}`);
}); // Set a new item in the Collection
}); // With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
} }
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]}); client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) 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 });
}
});
client.once("ready", () => { client.once("ready", () => {
console.log("Ready"); console.log("Ready");

27
commands/take.js Normal file
View File

@ -0,0 +1,27 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const noblox = require("noblox.js");
const {cookie} = require("../config.json");
module.exports = {
data: new SlashCommandBuilder()
.setName('take')
.setDescription('Takes an asset ID')
.addIntegerOption(option =>
option.setName("asset_id")
.setDescription("The asset ID of the model")
.setRequired(true))
,
async execute(interaction) {
const id = interaction.options.getInteger("asset_id");
await noblox.setCookie(cookie)
.then(async () => {
noblox.buy(id, 0)
.catch(async (error) => {
await interaction.reply("Could not take model!");
console.log("Could not take model: ")
console.log(error)
});
});
await interaction.reply("Model was taken successfully!");
},
};

30
deploy-commands.js Normal file
View File

@ -0,0 +1,30 @@
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, token } = require('./config.json');
const fs = require('node:fs');
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();

View File

@ -1,4 +1,5 @@
{ {
"token": "", "token": "",
"clientId": "",
"cookie": "" "cookie": ""
} }

217
package-lock.json generated
View File

@ -5,26 +5,34 @@
"packages": { "packages": {
"": { "": {
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.13.0",
"@discordjs/rest": "^0.4.1",
"discord-api-types": "^0.32.1",
"discord.js": "^13.6.0", "discord.js": "^13.6.0",
"noblox.js": "^4.13.1" "noblox.js": "^4.13.1"
} }
}, },
"node_modules/@discordjs/builders": { "node_modules/@discordjs/builders": {
"version": "0.11.0", "version": "0.13.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", "integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==",
"dependencies": { "dependencies": {
"@sindresorhus/is": "^4.2.0", "@sapphire/shapeshift": "^2.0.0",
"discord-api-types": "^0.26.0", "@sindresorhus/is": "^4.6.0",
"ts-mixer": "^6.0.0", "discord-api-types": "^0.31.1",
"tslib": "^2.3.1", "fast-deep-equal": "^3.1.3",
"zod": "^3.11.6" "ts-mixer": "^6.0.1",
"tslib": "^2.3.1"
}, },
"engines": { "engines": {
"node": ">=16.0.0", "node": ">=16.9.0"
"npm": ">=7.0.0"
} }
}, },
"node_modules/@discordjs/builders/node_modules/discord-api-types": {
"version": "0.31.2",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.31.2.tgz",
"integrity": "sha512-gpzXTvFVg7AjKVVJFH0oJGC0q0tO34iJGSHZNz9u3aqLxlD6LfxEs9wWVVikJqn9gra940oUTaPFizCkRDcEiA=="
},
"node_modules/@discordjs/collection": { "node_modules/@discordjs/collection": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz",
@ -34,6 +42,50 @@
"npm": ">=7.0.0" "npm": ">=7.0.0"
} }
}, },
"node_modules/@discordjs/rest": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-0.4.1.tgz",
"integrity": "sha512-rtWy+AIfNlfjGkAgA2TJLASdqli07aTNQceVGT6RQQiQaEqV0nsfBO4WtDlDzk7PmO3w+InP3dpwEolJI5jz0A==",
"dependencies": {
"@discordjs/collection": "^0.7.0-dev",
"@sapphire/async-queue": "^1.3.1",
"@sapphire/snowflake": "^3.2.1",
"@types/node-fetch": "^2.6.1",
"discord-api-types": "^0.29.0",
"form-data": "^4.0.0",
"node-fetch": "^2.6.7",
"tslib": "^2.3.1"
},
"engines": {
"node": ">=16.9.0"
}
},
"node_modules/@discordjs/rest/node_modules/@discordjs/collection": {
"version": "0.7.0-dev.1652350334-4515a1e",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0-dev.1652350334-4515a1e.tgz",
"integrity": "sha512-fBlyAUGP2Rhc083eLVniSMJSDV76c9YdgEK4gdfw5F+7T1PlixEomo5su+XhuwhMa5VIhPT1FfC3vsQAFg4ZQA==",
"engines": {
"node": ">=16.9.0"
}
},
"node_modules/@discordjs/rest/node_modules/discord-api-types": {
"version": "0.29.0",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.29.0.tgz",
"integrity": "sha512-Ekq1ICNpOTVajXKZguNFrsDeTmam+ZeA38txsNLZnANdXUjU6QBPIZLUQTC6MzigFGb0Tt8vk4xLnXmzv0shNg=="
},
"node_modules/@discordjs/rest/node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/@sapphire/async-queue": { "node_modules/@sapphire/async-queue": {
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.1.tgz", "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.1.tgz",
@ -43,6 +95,24 @@
"npm": ">=7.0.0" "npm": ">=7.0.0"
} }
}, },
"node_modules/@sapphire/shapeshift": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-2.2.0.tgz",
"integrity": "sha512-UEnKgMlQyI0yY/q+lCMX0VJft9y86IsesgbIQj6e62FBYSaMVr+IaMNpi4z45Q14VnuMACbK0yrbHISNqgUYcQ==",
"engines": {
"node": ">=v15.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/@sapphire/snowflake": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.2.2.tgz",
"integrity": "sha512-ula2O0kpSZtX9rKXNeQMrHwNd7E4jPDJYUXmEGTFdMRfyfMw+FPyh04oKMjAiDuOi64bYgVkOV3MjK+loImFhQ==",
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/@sindresorhus/is": { "node_modules/@sindresorhus/is": {
"version": "4.6.0", "version": "4.6.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
@ -332,12 +402,9 @@
} }
}, },
"node_modules/discord-api-types": { "node_modules/discord-api-types": {
"version": "0.26.1", "version": "0.32.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.32.1.tgz",
"integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==", "integrity": "sha512-/ewl0CPYT5xjOC+SJ7wADJKjtpZfiiUaYXOP/Ns54lnBcv4Xqa4iKSqRF/w1fjiUvWTYN9W8UuOiyCHtmu5fJw=="
"engines": {
"node": ">=12"
}
}, },
"node_modules/discord.js": { "node_modules/discord.js": {
"version": "13.6.0", "version": "13.6.0",
@ -359,6 +426,30 @@
"npm": ">=7.0.0" "npm": ">=7.0.0"
} }
}, },
"node_modules/discord.js/node_modules/@discordjs/builders": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==",
"dependencies": {
"@sindresorhus/is": "^4.2.0",
"discord-api-types": "^0.26.0",
"ts-mixer": "^6.0.0",
"tslib": "^2.3.1",
"zod": "^3.11.6"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/discord.js/node_modules/discord-api-types": {
"version": "0.26.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz",
"integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==",
"engines": {
"node": ">=12"
}
},
"node_modules/discord.js/node_modules/form-data": { "node_modules/discord.js/node_modules/form-data": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
@ -1118,15 +1209,23 @@
}, },
"dependencies": { "dependencies": {
"@discordjs/builders": { "@discordjs/builders": {
"version": "0.11.0", "version": "0.13.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", "integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==",
"requires": { "requires": {
"@sindresorhus/is": "^4.2.0", "@sapphire/shapeshift": "^2.0.0",
"discord-api-types": "^0.26.0", "@sindresorhus/is": "^4.6.0",
"ts-mixer": "^6.0.0", "discord-api-types": "^0.31.1",
"tslib": "^2.3.1", "fast-deep-equal": "^3.1.3",
"zod": "^3.11.6" "ts-mixer": "^6.0.1",
"tslib": "^2.3.1"
},
"dependencies": {
"discord-api-types": {
"version": "0.31.2",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.31.2.tgz",
"integrity": "sha512-gpzXTvFVg7AjKVVJFH0oJGC0q0tO34iJGSHZNz9u3aqLxlD6LfxEs9wWVVikJqn9gra940oUTaPFizCkRDcEiA=="
}
} }
}, },
"@discordjs/collection": { "@discordjs/collection": {
@ -1134,11 +1233,58 @@
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz", "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz",
"integrity": "sha512-zmjq+l/rV35kE6zRrwe8BHqV78JvIh2ybJeZavBi5NySjWXqN3hmmAKg7kYMMXSeiWtSsMoZ/+MQi0DiQWy2lw==" "integrity": "sha512-zmjq+l/rV35kE6zRrwe8BHqV78JvIh2ybJeZavBi5NySjWXqN3hmmAKg7kYMMXSeiWtSsMoZ/+MQi0DiQWy2lw=="
}, },
"@discordjs/rest": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-0.4.1.tgz",
"integrity": "sha512-rtWy+AIfNlfjGkAgA2TJLASdqli07aTNQceVGT6RQQiQaEqV0nsfBO4WtDlDzk7PmO3w+InP3dpwEolJI5jz0A==",
"requires": {
"@discordjs/collection": "^0.7.0-dev",
"@sapphire/async-queue": "^1.3.1",
"@sapphire/snowflake": "^3.2.1",
"@types/node-fetch": "^2.6.1",
"discord-api-types": "^0.29.0",
"form-data": "^4.0.0",
"node-fetch": "^2.6.7",
"tslib": "^2.3.1"
},
"dependencies": {
"@discordjs/collection": {
"version": "0.7.0-dev.1652350334-4515a1e",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0-dev.1652350334-4515a1e.tgz",
"integrity": "sha512-fBlyAUGP2Rhc083eLVniSMJSDV76c9YdgEK4gdfw5F+7T1PlixEomo5su+XhuwhMa5VIhPT1FfC3vsQAFg4ZQA=="
},
"discord-api-types": {
"version": "0.29.0",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.29.0.tgz",
"integrity": "sha512-Ekq1ICNpOTVajXKZguNFrsDeTmam+ZeA38txsNLZnANdXUjU6QBPIZLUQTC6MzigFGb0Tt8vk4xLnXmzv0shNg=="
},
"form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
}
}
},
"@sapphire/async-queue": { "@sapphire/async-queue": {
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.1.tgz", "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.1.tgz",
"integrity": "sha512-FFTlPOWZX1kDj9xCAsRzH5xEJfawg1lNoYAA+ecOWJMHOfiZYb1uXOI3ne9U4UILSEPwfE68p3T9wUHwIQfR0g==" "integrity": "sha512-FFTlPOWZX1kDj9xCAsRzH5xEJfawg1lNoYAA+ecOWJMHOfiZYb1uXOI3ne9U4UILSEPwfE68p3T9wUHwIQfR0g=="
}, },
"@sapphire/shapeshift": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-2.2.0.tgz",
"integrity": "sha512-UEnKgMlQyI0yY/q+lCMX0VJft9y86IsesgbIQj6e62FBYSaMVr+IaMNpi4z45Q14VnuMACbK0yrbHISNqgUYcQ=="
},
"@sapphire/snowflake": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.2.2.tgz",
"integrity": "sha512-ula2O0kpSZtX9rKXNeQMrHwNd7E4jPDJYUXmEGTFdMRfyfMw+FPyh04oKMjAiDuOi64bYgVkOV3MjK+loImFhQ=="
},
"@sindresorhus/is": { "@sindresorhus/is": {
"version": "4.6.0", "version": "4.6.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
@ -1365,9 +1511,9 @@
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
}, },
"discord-api-types": { "discord-api-types": {
"version": "0.26.1", "version": "0.32.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.32.1.tgz",
"integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==" "integrity": "sha512-/ewl0CPYT5xjOC+SJ7wADJKjtpZfiiUaYXOP/Ns54lnBcv4Xqa4iKSqRF/w1fjiUvWTYN9W8UuOiyCHtmu5fJw=="
}, },
"discord.js": { "discord.js": {
"version": "13.6.0", "version": "13.6.0",
@ -1385,6 +1531,23 @@
"ws": "^8.4.0" "ws": "^8.4.0"
}, },
"dependencies": { "dependencies": {
"@discordjs/builders": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz",
"integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==",
"requires": {
"@sindresorhus/is": "^4.2.0",
"discord-api-types": "^0.26.0",
"ts-mixer": "^6.0.0",
"tslib": "^2.3.1",
"zod": "^3.11.6"
}
},
"discord-api-types": {
"version": "0.26.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz",
"integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ=="
},
"form-data": { "form-data": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",

View File

@ -1,5 +1,8 @@
{ {
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.13.0",
"@discordjs/rest": "^0.4.1",
"discord-api-types": "^0.32.1",
"discord.js": "^13.6.0", "discord.js": "^13.6.0",
"noblox.js": "^4.13.1" "noblox.js": "^4.13.1"
} }