Add command for simulating extended dice roll and basic shell code

This commit is contained in:
Sebastian Fischlmayr 2022-10-12 19:10:23 +02:00
parent 8fee5df53e
commit f700c892ac
Signed by: Maverick
GPG key ID: 6379E413924A4E77
2 changed files with 128 additions and 8 deletions

View file

@ -27,6 +27,84 @@ const commands = [
{ name: 'Framework', value: 'framework' },
)
)
),
new SlashCommandBuilder()
.setName('simulate')
.setDescription('Simulate different type of dice rolls.')
.addSubcommand(subcommand =>
subcommand
.setName('simple')
.setDescription('Simulate a simple dice roll.')
)
.addSubcommand(subcommand =>
subcommand
.setName('extended')
.setDescription('Simulate an extended dice roll.')
.addNumberOption(option =>
option
.setName('dicepool')
.setDescription('The dicepool of the roll.')
.setRequired(true)
)
.addNumberOption(option =>
option
.setName('difficulty')
.setDescription('The difficulty of the roll.')
.setRequired(true)
)
.addNumberOption(option =>
option
.setName('interval')
.setDescription('The interval of the roll.')
.setRequired(false)
)
.addNumberOption(option =>
option
.setName('max-edge')
.setDescription('The maximum number of edge to use.')
.setRequired(false)
)
.addStringOption(option =>
option
.setName('edgetype')
.setDescription('What type of edgeing should be used ?')
.addChoices(
{ name: 'None', value: 'none' },
{ name: 'Turn Up', value: 'up' },
{ name: 'Reroll', value: 'reroll' },
{ name: 'Smart', value: 'smart' },
{ name: 'All', value: 'all' },
)
)
.addStringOption(option =>
option
.setName('edgerefresh')
.setDescription('How often should the edge refresh ?')
.addChoices(
{ name: 'Never', value: 'none' },
{ name: 'Every Roll', value: 'fill' },
{ name: '1 Edge per Roll', value: 'once' },
{ name: '2 Edge per Roll', value: 'twice' },
)
)
.addNumberOption(option =>
option
.setName('amount')
.setDescription('How many times should the roll be simulated ? WARNING this service is pricey !')
.setRequired(false)
)
.addBooleanOption(option =>
option
.setName('hidden')
.setDescription('Should the result be hidden ?')
.setRequired(false)
)
.addBooleanOption(option =>
option
.setName('true-random')
.setDescription('Should the dice be truly random ?')
.setRequired(false)
)
)
]
.map(command => command.toJSON());

View file

@ -1,5 +1,6 @@
require('dotenv').config();
const { crypto } = require('crypto');
const { Client, GatewayIntentBits } = require('discord.js');
const token = process.env.TOKEN;
@ -15,15 +16,56 @@ client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
console.log(interaction.commandName);
let commandName = interaction.commandName;
switch (interaction.commandName) {
case "generate":
switch (interaction.options.getSubcommand()) {
case "host":
let rating = interaction.options.getNumber("rating");
let type = interaction.options.getString("type") ?? "foundation";
await interaction.reply({files: ["./france-in-pictures-beautiful-places-to-photograph-eiffel-tower.jpg"]});
break;
default:
await interaction.reply({ content: 'Invalid subcommand!', ephemeral: true });
break;
}
break;
case "simulate":
await interaction.deferReply();
switch (interaction.options.getSubcommand()) {
case "simple":
await interaction.reply({ content: 'Simple dice roll!', ephemeral: true });
break;
if (commandName === "generate") {
if (interaction.options.getSubcommand() === "host") {
let rating = interaction.options.getNumber("rating");
let type = interaction.options.getString("type") ?? "foundation";
await interaction.reply({files: ["./france-in-pictures-beautiful-places-to-photograph-eiffel-tower.jpg"]});
}
case "extended":
let dicepool = interaction.options.getNumber("dicepool");
let difficulty = interaction.options.getNumber("difficulty");
let interval = interaction.options.getNumber("interval") ?? 1;
let simAmount = interaction.options.getNumber("amount") ?? 10000;
let hidden = interaction.options.getBoolean("hidden") ?? false;
let edgeType = interaction.options.getString("edge") ?? "none";
let edgeRefresh = interaction.options.getString("edgerefresh") ?? "none";
let maxEdge = interaction.options.getNumber("edge-max") ?? 6;
let useTrueRandom = interaction.options.getBoolean("true-random") ?? false;
let edge = maxEdge;
let warnings = [];
let calculatedResults = [];
let realResults = [];
await interaction.reply({ content: 'Extended dice roll!', ephemeral: hidden });
break;
}
break;
}
})
});
async function fillArrayWithRandomDice(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i] = await crypto.randomInt(1, 7);
}
}
client.login(token);