Building my own friend

Joined
Jun 14, 2018
Messages
110
Reaction score
1
hi so i'm building a friend but i'm trying to train it
so it can create and design flyers? here's what i have

JavaScript:
/** FLYER CREATION **/
    else if (
        message.includes("create a flyer") ||
        message.includes("build me a flyer") ||
        message.includes("random flyer")
    ) {
        return "Let’s make an awesome flyer! 🖼️ What details do you want to include? Title, colors, and content—just let me know!";
    } else if (message.startsWith("flyer:")) {
        return await handleFlyerRequest(message.slice(6).trim());
    }

    else if (message.startsWith("remember my zodiac")) {
        return handleZodiacMemory(message.slice(19).trim());
    } else if (message.includes("what's my zodiac")) {
        return memory['zodiacSign']
            ? `You’re a ${memory['zodiacSign']}! 🌟 Ready for your horoscope?`
            : "I don’t know your zodiac sign yet! Just tell me, and I’ll remember it. 🙌";
    } else if (message.includes("horoscope")) {
        return memory['zodiacSign']
            ? getHoroscope(memory['zodiacSign'])
            : "Please tell me your zodiac sign first. I can give you your horoscope once I know your sign! 🌙";
    } else if (message.includes("how are you")) {
        return "I’m doing great, thanks for asking! 😄 How about you? Feeling awesome today?";
    } else if (message.includes("thank you")) {
        return "You're very welcome! 😊 I'm always here to help! 🤗";
    } else if (message.includes("help with coding")) {
        return "You’ve come to the right place! 💻 Tell me what coding problem you're working on, and I’ll help you out.";
    } else {
        return "Oops! I’m not sure what that means. Can you rephrase? 🤔";
    }
}

async function handleImageRequest(details) {
    if (!details) {
        return "Please describe the image you'd like me to create, and I’ll get started!";
    }
    try {
        const imageUrl = await generateImageWithDalle(details);
        return `Tada! 🎉 Your image is ready! <a href="${imageUrl}" target="_blank">Click here to view it.</a>`;
    } catch (error) {
        console.error("Error generating image:", error);
        return "Oh no, something went wrong with the image generation. Let’s try again later! 😬";
    }
}

async function handleFlyerRequest(details) {
    const [title, color, content] = details.split(';').map(s => s.trim());
    if (!title || !color || !content) {
        return "Hmm, it looks like we’re missing something! Please use this format: 'Title; Color; Content'.";
    }
    try {
        const flyerUrl = await generateFlyer(title, color, content);
        return `Your flyer is ready! 🎉 <a href="${flyerUrl}" target="_blank">Click here to check it out.</a>`;
    } catch (error) {
        console.error("Error generating flyer:", error);
        return "Oops, there was a hiccup while creating your flyer. Try again later! 😅";
    }
}

but someone on reddit has said to me i'v split the flyer message twice,
once before calling the function and once in the function?

how do i fix this....
 
Joined
Jul 4, 2023
Messages
499
Reaction score
62
IMO, this is not a major mistake. Using message.slice(6).trim() in this part of the code is fine because message.startsWith indicates exactly what is happening in this section of the code.

JavaScript:
 else if (message.startsWith("flyer:")) {
     return await handleFlyerRequest(message.slice('flyer:'.length).trim());
 }

however, you can also use: message.replace('flyer:', '').trim();

BTW, using: message.slice('flyer:'.length).trim(); means you don’t need to manually calculate the length of the phrase.
 
Last edited:
Joined
Jul 4, 2023
Messages
499
Reaction score
62
BTW, you’re asking the user:
What details do you want to include?
but in your code, you need exactly these three properties at the same time: title, color and content.
const [title, color, content] = details.split(';').map(s => s.trim());
if (!title || !color || !content) {
return "Hmm, it looks like we’re missing something! Please use this format: 'Title; Color; Content'.";
}
IMO, the question should look like this:
Please provide the details as follows: title, color, content. Use this format: title; color; content
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,029
Messages
2,570,347
Members
46,984
Latest member
michelwilson

Latest Threads

Top