added submissions
This commit is contained in:
parent
62b6f2628f
commit
6e50de5310
@ -18,3 +18,5 @@ node bot.js
|
|||||||
```
|
```
|
||||||
|
|
||||||
also, the bot requires the bot and applications.commands scope, which can be found in developer portal -> bot -> oauth2 -> url generator -> scopes, simply generate link with the bot and applications.commands scopes checked then add bot to server (can be done if bot already in server). no other permissions are needed.
|
also, the bot requires the bot and applications.commands scope, which can be found in developer portal -> bot -> oauth2 -> url generator -> scopes, simply generate link with the bot and applications.commands scopes checked then add bot to server (can be done if bot already in server). no other permissions are needed.
|
||||||
|
|
||||||
|
finally, the bhop/surf/deathrun cookies in the config.json require the full ``_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_`` text, so include it
|
6
bot.js
6
bot.js
@ -2,7 +2,7 @@ const fs = require('node:fs');
|
|||||||
const { Client, Collection, Intents } = require("discord.js");
|
const { Client, Collection, Intents } = require("discord.js");
|
||||||
const {token} = require("./config.json");
|
const {token} = require("./config.json");
|
||||||
|
|
||||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS]});
|
const client = new Client({intents: [Intents.FLAGS.GUILDS]});
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
||||||
@ -35,6 +35,10 @@ client.on("error", async error => {
|
|||||||
|
|
||||||
client.once("ready", () => {
|
client.once("ready", () => {
|
||||||
console.log("Ready");
|
console.log("Ready");
|
||||||
|
client.user.setActivity({
|
||||||
|
name: "use /take and /submit",
|
||||||
|
type: 0
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
39
commands/submissions.js
Normal file
39
commands/submissions.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const { MessageAttachment } = require("discord.js");
|
||||||
|
const fs = require('node:fs');
|
||||||
|
|
||||||
|
async function execute(interaction) {
|
||||||
|
const game = interaction.options.getString("game");
|
||||||
|
|
||||||
|
let fname;
|
||||||
|
if (game === "bhop") fname = "files/bhop_submissions.csv";
|
||||||
|
else if (game === "surf") fname = "files/surf_submissions.csv";
|
||||||
|
else if (game === "deathrun") fname = "files/deathrun_submissions.csv";
|
||||||
|
else {
|
||||||
|
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(fname)) {
|
||||||
|
await interaction.reply(`No submissions exist yet for ${game}.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const csv = fs.readFileSync(fname);
|
||||||
|
const file = new MessageAttachment(csv, fname);
|
||||||
|
await interaction.reply({files: [file]});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('submissions')
|
||||||
|
.setDescription('View the submissions in .csv format')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option.setName("game")
|
||||||
|
.setDescription("Select the maptest game")
|
||||||
|
.setRequired(true)
|
||||||
|
.addChoices({name: "bhop", value: "bhop"}, {name: "surf", value: "surf"}, {name: "deathrun", value: "deathrun"}))
|
||||||
|
,
|
||||||
|
execute
|
||||||
|
};
|
73
commands/submit.js
Normal file
73
commands/submit.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const { parse } = require("csv-parse/sync");
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const noblox = require("noblox.js");
|
||||||
|
|
||||||
|
async function execute(interaction) {
|
||||||
|
const game = interaction.options.getString("game");
|
||||||
|
|
||||||
|
let fname;
|
||||||
|
if (game === "bhop") fname = "files/bhop_submissions.csv";
|
||||||
|
else if (game === "surf") fname = "files/surf_submissions.csv";
|
||||||
|
else if (game === "deathrun") fname = "files/deathrun_submissions.csv";
|
||||||
|
else {
|
||||||
|
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(fname)) {
|
||||||
|
fs.writeFileSync(fname, "id,timestamp\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = interaction.options.getInteger("asset_id");
|
||||||
|
try {
|
||||||
|
const info = await noblox.getProductInfo(id);
|
||||||
|
if (info.AssetTypeId != 10) {
|
||||||
|
await interaction.reply({content: `(id: ${id}) is not a valid model ID.`, ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
await interaction.reply({content: `There is a problem with this asset ID (id: ${id}).`, ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const csv = fs.readFileSync(fname);
|
||||||
|
const records = parse(csv, {delimiter: ',', fromLine: 2});
|
||||||
|
|
||||||
|
let s = "id,timestamp\n";
|
||||||
|
for (let record of records) {
|
||||||
|
const rid = record[0];
|
||||||
|
const rtimestamp = record[1];
|
||||||
|
if (id == rid) {
|
||||||
|
await interaction.reply({content: `Tried to submit map (id: ${id}) that already exists!`, ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s += `${rid},${rtimestamp}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unix = Math.round(+new Date()/1000);
|
||||||
|
s += `${id},${unix}\n`;
|
||||||
|
|
||||||
|
fs.writeFileSync(fname, s);
|
||||||
|
|
||||||
|
await interaction.reply(`Map (id: ${id}) successfully submitted.`);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('submit')
|
||||||
|
.setDescription('Submit your map')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option.setName("game")
|
||||||
|
.setDescription("Select the maptest game")
|
||||||
|
.setRequired(true)
|
||||||
|
.addChoices({name: "bhop", value: "bhop"}, {name: "surf", value: "surf"}, {name: "deathrun", value: "deathrun"}))
|
||||||
|
.addIntegerOption(option =>
|
||||||
|
option.setName("asset_id")
|
||||||
|
.setDescription("The asset ID of the model")
|
||||||
|
.setRequired(true))
|
||||||
|
,
|
||||||
|
execute
|
||||||
|
};
|
@ -2,6 +2,55 @@ const { SlashCommandBuilder } = require('@discordjs/builders');
|
|||||||
const noblox = require("noblox.js");
|
const noblox = require("noblox.js");
|
||||||
const { bhopCookie, surfCookie, deathrunCookie } = require("../config.json");
|
const { bhopCookie, surfCookie, deathrunCookie } = require("../config.json");
|
||||||
|
|
||||||
|
async function execute(interaction) {
|
||||||
|
const game = interaction.options.getString("game");
|
||||||
|
let cookie;
|
||||||
|
if (game === "bhop") cookie = bhopCookie;
|
||||||
|
else if (game === "surf") cookie = surfCookie;
|
||||||
|
else if (game === "deathrun") cookie = deathrunCookie;
|
||||||
|
else {
|
||||||
|
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const id = interaction.options.getInteger("asset_id");
|
||||||
|
await noblox.setCookie(cookie).then(async () => {
|
||||||
|
|
||||||
|
// validate that this is a model
|
||||||
|
try {
|
||||||
|
const info = await noblox.getProductInfo(id);
|
||||||
|
if (info.AssetTypeId != 10) {
|
||||||
|
await interaction.reply({content: `(id: ${id}) is not a valid model ID.`, ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
await interaction.reply({content: `There is a problem with this asset ID (id: ${id}).`, ephemeral: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
noblox.buy(id, 0).then(async () => {
|
||||||
|
await interaction.reply(
|
||||||
|
`
|
||||||
|
Now that your map (id: ${id}) has been taken by the ${game} maptest bot you can load it into the ${game} maptest place. To load your map, join the game and say
|
||||||
|
\`\`\`
|
||||||
|
!map ${id}
|
||||||
|
\`\`\`Read what it says. If your map successfully loaded type !rtv and then choose your map.
|
||||||
|
If it did not load successfully, you can expand the chat to view the full error message by clicking and dragging on the edge of the chat.
|
||||||
|
`
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(async (error) => {
|
||||||
|
if (error.message == "You already own this item.") {
|
||||||
|
await interaction.reply({content: "The bot has already taken this model!", ephemeral: true});
|
||||||
|
} else {
|
||||||
|
await interaction.reply({content: `An error occured trying to take the model (id: ${id}). Make sure it is uncopylocked!`, ephemeral: true});
|
||||||
|
console.log(`Could not take asset ID ${id}: `);
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('take')
|
.setName('take')
|
||||||
@ -16,38 +65,5 @@ module.exports = {
|
|||||||
.setDescription("The asset ID of the model")
|
.setDescription("The asset ID of the model")
|
||||||
.setRequired(true))
|
.setRequired(true))
|
||||||
,
|
,
|
||||||
async execute(interaction) {
|
execute
|
||||||
const game = interaction.options.getString("game");
|
|
||||||
let cookie;
|
|
||||||
if (game == "bhop") cookie = bhopCookie;
|
|
||||||
else if (game == "surf") cookie = surfCookie;
|
|
||||||
else if (game == "deathrun") cookie = deathrunCookie;
|
|
||||||
else {
|
|
||||||
await interaction.reply("Invalid game specified!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const id = interaction.options.getInteger("asset_id");
|
|
||||||
await noblox.setCookie(cookie).then(async () => {
|
|
||||||
noblox.buy(id, 0).then(async () => {
|
|
||||||
await interaction.reply(
|
|
||||||
`
|
|
||||||
Now that your map (id: ${id}) has been taken by the ${game} maptest bot you can load it into the ${game} maptest place. To load your map, join the game and say
|
|
||||||
\`\`\`
|
|
||||||
!map ${id}
|
|
||||||
\`\`\`Read what it says. If your map successfully loaded type !rtv and then choose your map.
|
|
||||||
If it did not load successfully, you can expand the chat to view the full error message by clicking and dragging on the edge of the chat.
|
|
||||||
`
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch(async (error) => {
|
|
||||||
if (error.message == "You already own this item.") {
|
|
||||||
await interaction.reply("The bot has already taken this model!");
|
|
||||||
} else {
|
|
||||||
await interaction.reply(`An error occured trying to take the model (id: ${id}). Make sure it is uncopylocked!`);
|
|
||||||
console.log(`Could not take asset ID ${id}: `);
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
2
files/.gitignore
vendored
Normal file
2
files/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
@ -2,8 +2,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/builders": "^0.13.0",
|
"@discordjs/builders": "^0.13.0",
|
||||||
"@discordjs/rest": "^0.4.1",
|
"@discordjs/rest": "^0.4.1",
|
||||||
|
"csv-parse": "^5.0.4",
|
||||||
"discord-api-types": "^0.32.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-csv": "^0.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user