55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import { GuildMember, SlashCommandBuilder, Interaction } from 'discord.js';
|
|
import { getTextResponsePrettyPlease, randomWord, sendSegments, startGame } from '../lib/game';
|
|
import { shuffle } from 'd3-array';
|
|
import { knownServers } from '../lib/knownServers';
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('twosentencehorror')
|
|
.setDescription('Communally create the worst horror stories known to man'),
|
|
|
|
serverWhitelist: [...knownServers.fbi],
|
|
|
|
execute: async (interaction: Interaction, member: GuildMember) => {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
startGame(interaction, member.user, 'Markov game', async (players, channel) => {
|
|
const firstPlayers = shuffle(players);
|
|
const secondPlayers = [...firstPlayers.slice(1), firstPlayers[0]]; // shift by 1
|
|
|
|
const firstHalves = await Promise.all(firstPlayers.map(async (firstPlayer) => {
|
|
let firstHalf = await getTextResponsePrettyPlease(
|
|
firstPlayer,
|
|
`Start a horror story... (1 sentence max!) (try working with: “${randomWord()}”)\n\n**Send a message to continue**`,
|
|
(msg) => !(msg.includes('. ') || msg.includes('! ') || msg.includes('? '))
|
|
);
|
|
|
|
if (!(firstHalf.endsWith('.') || firstHalf.endsWith('!') || firstHalf.endsWith('?'))) firstHalf = firstHalf + '.';
|
|
|
|
return firstHalf;
|
|
}));
|
|
|
|
const secondHalves = await Promise.all(secondPlayers.map(async (secondPlayer, i) => {
|
|
const firstHalf = firstHalves[i];
|
|
|
|
let secondHalf = await getTextResponsePrettyPlease(
|
|
secondPlayer,
|
|
`> _${firstHalf}_\nContinue this sentence with a twist!`,
|
|
(msg) => !(msg.includes('. ') || msg.includes('! ') || msg.includes('? '))
|
|
);
|
|
|
|
if (!(secondHalf.endsWith('.') || secondHalf.endsWith('!') || secondHalf.endsWith('?'))) secondHalf = secondHalf + '.';
|
|
|
|
return secondHalf;
|
|
}));
|
|
|
|
const segments = [
|
|
'Here\'s the bone-chilling stories you\'ve all created:\n\n',
|
|
...firstHalves.map((firstHalf, i) => firstHalf + ' ' + secondHalves[i]),
|
|
'\n\nThank you for participating :)'
|
|
];
|
|
|
|
await sendSegments(segments, channel);
|
|
});
|
|
}
|
|
}; |