Implement madlibs
This commit is contained in:
@@ -21,12 +21,27 @@ module.exports = {
|
|||||||
.setLabel('No')
|
.setLabel('No')
|
||||||
.setStyle(ButtonStyle.Danger),
|
.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 => {
|
client.on(Events.InteractionCreate, interaction => {
|
||||||
if (!interaction.isButton()) return;
|
if (!interaction.isButton()) return;
|
||||||
if (interaction.customId == 'yes') {
|
if (interaction.customId == 'yes') {
|
||||||
console.log("User selected yes");
|
console.log("User selected yes");
|
||||||
if (interaction.channel.id != undefined) {
|
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);
|
initGame(interaction.channel.id, client, interaction);
|
||||||
}
|
}
|
||||||
} else if (interaction.customId == 'no') {
|
} else if (interaction.customId == 'no') {
|
||||||
@@ -47,43 +62,26 @@ function initGame(channelId, client, interaction) {
|
|||||||
console.log("Starting game in channel " + channelId);
|
console.log("Starting game in channel " + channelId);
|
||||||
madlibState.gameChannel = channelId;
|
madlibState.gameChannel = channelId;
|
||||||
//let selectedStory =
|
//let selectedStory =
|
||||||
selectStory(interaction);
|
|
||||||
//global.madlibNextPrompt(client, 0, selectedStory);
|
//global.madlibNextPrompt(client, 0, selectedStory);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const channel = client.channels.cache.get(interaction.channel.id);
|
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.");
|
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() {
|
function buildOptionJSON() {
|
||||||
const madlib = require("../madlibs/stories.json");
|
const madlib = require("../madlibs/stories.json");
|
||||||
let returnObj = [];
|
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 = {};
|
let entryObj = {};
|
||||||
entryObj["label"] = Object.keys(madlib.stories)[i];
|
entryObj["label"] = Object.keys(madlib.stories)[i];
|
||||||
entryObj["description"] = "Story " + (i+1);
|
entryObj["description"] = "Story " + (i+1);
|
||||||
entryObj["value"] = i;
|
entryObj["value"] = (i+1).toString();
|
||||||
returnObj.push(entryObj);
|
returnObj.push(entryObj);
|
||||||
}
|
}
|
||||||
return returnObj;
|
return returnObj;
|
||||||
}
|
}
|
||||||
console.log(buildOptionJSON());
|
//console.log(buildOptionJSON());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
|
6
main.cjs
6
main.cjs
@@ -5,9 +5,11 @@ const Discord = require('discord.js');
|
|||||||
const { clientId, guildId, token } = require('./key.json');
|
const { clientId, guildId, token } = require('./key.json');
|
||||||
let fs = require('node:fs');
|
let fs = require('node:fs');
|
||||||
let path = require('node:path');
|
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};
|
//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
|
// Create a new client instance
|
||||||
const client = new Discord.Client({
|
const client = new Discord.Client({
|
||||||
|
Reference in New Issue
Block a user