Implement madlibs

master
Chloe Fontenot 🏳️‍⚧️ 2023-04-06 16:28:29 +07:00
parent 91784d7d7d
commit 48fcfc375c
2 changed files with 24 additions and 24 deletions

@ -21,12 +21,27 @@ module.exports = {
.setLabel('No')
.setStyle(ButtonStyle.Danger),
);
const message = await interaction.reply({ content: "You have requested to start a madlib game in the current channel. I will intercept any message sent in this channel as game input until the game is over. Please refrain from using this in a busy channel, as it can be annoying for others. Would you like to continue?", fetchReply: true, components: [row], allowedMentions: { repliedUser: false, } });
const message = await interaction.reply({ content: "You have requested to start a madlib game in the current channel. I will intercept any message sent in this channel as game input until the game is over. Please refrain from using this in a busy channel, as it can be annoying for others. Would you like to continue?", fetchReply: true, components: [row]});
client.on(Events.InteractionCreate, interaction => {
if (!interaction.isButton()) return;
if (interaction.customId == 'yes') {
console.log("User selected yes");
if (interaction.channel.id != undefined) {
const row = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('selectstory')
.setPlaceholder('Automatically pick a random story')
.setMaxValues(global.madlibState.numberOfStories)
.addOptions(
buildOptionJSON().toString()
),
);
interaction.reply({ content: 'Select a story', components: [row] });
client.on(Events.InteractionCreate, interaction => {
if (!interaction.isStringSelectMenu()) return;
console.log(interaction);
});
initGame(interaction.channel.id, client, interaction);
}
} else if (interaction.customId == 'no') {
@ -47,43 +62,26 @@ function initGame(channelId, client, interaction) {
console.log("Starting game in channel " + channelId);
madlibState.gameChannel = channelId;
//let selectedStory =
selectStory(interaction);
//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.");
}
}
async function selectStory(interaction) {
const row = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('selectStory')
.setPlaceholder('Automatically pIck a random story')
.addOptions(
buildOptionJSON()
),
);
await interaction.reply({ content: 'Select a story', components: [row] });
client.on(Events.InteractionCreate, interaction => {
if (!interaction.isStringSelectMenu()) return;
console.log(interaction);
});
}
function buildOptionJSON() {
const madlib = require("../madlibs/stories.json");
let returnObj = [];
for (let i = 0; i < Object.keys(madlib.stories).length; ++i) {
//Object.keys(madlib.stories).length
for (let i = 0; i < 1; ++i) {
let entryObj = {};
entryObj["label"] = Object.keys(madlib.stories)[i];
entryObj["description"] = "Story " + (i+1);
entryObj["value"] = i;
entryObj["value"] = (i+1).toString();
returnObj.push(entryObj);
}
return returnObj;
}
console.log(buildOptionJSON());
//console.log(buildOptionJSON());
/*
{

@ -5,9 +5,11 @@ const Discord = require('discord.js');
const { clientId, guildId, token } = require('./key.json');
let fs = require('node:fs');
let path = require('node:path');
global.madlibState = { gameChannel: undefined, storyTitle:undefined, currentStory: undefined, storyIterate: 0, storyReplaceContent: [], storyLength: undefined};
global.madlibState = { gameChannel: undefined, storyTitle:undefined, currentStory: undefined, storyIterate: 0, storyReplaceContent: [], storyLength: undefined, numberOfStories: undefined};
//export {madlibState};
//Get number of stories
const madlib = require("./madlibs/stories.json");
global.madlibState.numberOfStories = Object.keys(madlib.stories).length;
// Create a new client instance
const client = new Discord.Client({