|
|
|
@ -31,18 +31,24 @@ module.exports = {
|
|
|
|
|
.addComponents(
|
|
|
|
|
new StringSelectMenuBuilder()
|
|
|
|
|
.setCustomId('selectstory')
|
|
|
|
|
.setPlaceholder('Automatically pick a random story')
|
|
|
|
|
.setPlaceholder('Select an option')
|
|
|
|
|
.setMaxValues(global.madlibState.numberOfStories)
|
|
|
|
|
.addOptions(
|
|
|
|
|
buildOptionJSON().toString()
|
|
|
|
|
buildOptionJSON()//.toString()
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
interaction.reply({ content: 'Select a story', components: [row] });
|
|
|
|
|
var selectedStory;
|
|
|
|
|
const channel = client.channels.cache.get(interaction.channel.id);
|
|
|
|
|
channel.send({ content: 'Select a story', components: [row], fetchMessage: true });
|
|
|
|
|
client.on(Events.InteractionCreate, interaction => {
|
|
|
|
|
if (!interaction.isStringSelectMenu()) return;
|
|
|
|
|
selectedStory = interaction.values[0];
|
|
|
|
|
console.log("User selected: " +selectedStory);
|
|
|
|
|
initGame(interaction.channel.id, client, interaction, selectedStory);
|
|
|
|
|
//storySelectMessage.delete();
|
|
|
|
|
console.log(interaction);
|
|
|
|
|
});
|
|
|
|
|
initGame(interaction.channel.id, client, interaction);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else if (interaction.customId == 'no') {
|
|
|
|
|
console.log("User selected no");
|
|
|
|
@ -57,12 +63,11 @@ module.exports = {
|
|
|
|
|
console.log("User " + interaction.user.tag + " ran /startmadlib");
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
function initGame(channelId, client, interaction) {
|
|
|
|
|
function initGame(channelId, client, interaction, selectedStory) {
|
|
|
|
|
if(global.madlibState.gameChannel == undefined) {
|
|
|
|
|
console.log("Starting game in channel " + channelId);
|
|
|
|
|
madlibState.gameChannel = channelId;
|
|
|
|
|
//let selectedStory =
|
|
|
|
|
//global.madlibNextPrompt(client, 0, selectedStory);
|
|
|
|
|
madlibState.gameChannel = channelId;
|
|
|
|
|
global.madlibNextPrompt(client, 0, selectedStory);
|
|
|
|
|
} else {
|
|
|
|
|
const channel = client.channels.cache.get(interaction.channel.id);
|
|
|
|
|
channel.send("There is currently an active game! Wait for it to be finished before starting a new one.");
|
|
|
|
@ -71,8 +76,14 @@ function initGame(channelId, client, interaction) {
|
|
|
|
|
function buildOptionJSON() {
|
|
|
|
|
const madlib = require("../madlibs/stories.json");
|
|
|
|
|
let returnObj = [];
|
|
|
|
|
//Object.keys(madlib.stories).length
|
|
|
|
|
for (let i = 0; i < 1; ++i) {
|
|
|
|
|
{
|
|
|
|
|
let entryObj = {};
|
|
|
|
|
entryObj["label"] = "Automatically select random story";
|
|
|
|
|
entryObj["description"] = "Math.random()"
|
|
|
|
|
entryObj["value"] = "0"
|
|
|
|
|
returnObj.push(entryObj);
|
|
|
|
|
}
|
|
|
|
|
for (let i = 0; i < Object.keys(madlib.stories).length; ++i) {
|
|
|
|
|
let entryObj = {};
|
|
|
|
|
entryObj["label"] = Object.keys(madlib.stories)[i];
|
|
|
|
|
entryObj["description"] = "Story " + (i+1);
|
|
|
|
|