this post was submitted on 06 Aug 2024
1 points (100.0% liked)

Perchance - Create a Random Text Generator

448 readers
14 users here now

⚄︎ Perchance

This is a Lemmy Community for perchance.org, a platform for sharing and creating random text generators.

Feel free to ask for help, share your generators, and start friendly discussions at your leisure :)

This community is mainly for discussions between those who are building generators. For discussions about using generators, especially the popular AI ones, the community-led Casual Perchance forum is likely a more appropriate venue.

See this post for the Complete Guide to Posting Here on the Community!

Rules

1. Please follow the Lemmy.World instance rules.

2. Be kind and friendly.

  • Please be kind to others on this community (and also in general), and remember that for many people Perchance is their first experience with coding. We have members for whom English is not their first language, so please be take that into account too :)

3. Be thankful to those who try to help you.

  • If you ask a question and someone has made a effort to help you out, please remember to be thankful! Even if they don't manage to help you solve your problem - remember that they're spending time out of their day to try to help a stranger :)

4. Only post about stuff related to perchance.

  • Please only post about perchance related stuff like generators on it, bugs, and the site.

5. Refrain from requesting Prompts for the AI Tools.

  • We would like to ask to refrain from posting here needing help specifically with prompting/achieving certain results with the AI plugins (text-to-image-plugin and ai-text-plugin) e.g. "What is the good prompt for X?", "How to achieve X with Y generator?"
  • See Perchance AI FAQ for FAQ about the AI tools.
  • You can ask for help with prompting at the 'sister' community Casual Perchance, which is for more casual discussions.
  • We will still be helping/answering questions about the plugins as long as it is related to building generators with them.

6. Search through the Community Before Posting.

  • Please Search through the Community Posts here (and on Reddit) before posting to see if what you will post has similar post/already been posted.

founded 1 year ago
MODERATORS
 

I hope this is okay here, since it's primarily a coding question. I've been going around in circles with the coding assistant, trying to get something that will listen for keywords in chat and change the background (and avatar, but I gave up on that for now) automatically. None of the code she's given me has ever worked.

I did get this from her, which works:

`var backgroundUrls = {
  'keyword1': 'https://example.com/background1.png',
  'keyword2': 'https://example.com/background2.png',
  // Add more background keywords and URLs as needed
};

function changeBackground(keyword) {
  let link = backgroundUrls[keyword];
  if (link) {
    let prevMessage = oc.thread.messages.at(-2);
    prevMessage.scene = { 'background': {'url': link} };
    oc.thread.messages.pop(); // Remove the command message from the chat
  } else {
    oc.thread.messages.push({
      author: 'system',
      content: `<div class="error-message">Error: Invalid background keyword provided. Please use one of the following: ${Object.keys(backgroundUrls).join(', ')}.</div>`
    });
  }
}

oc.thread.on("MessageAdded", function({message}) {
  if (message.author == 'user' && /^\/change-bg/.test(message.content)) {
    let keyword = message.content.replace('/change-bg ', '');
    changeBackground(keyword);
  }
});`

This at least allows you preset keywords and urls so you can just type "/change-bg keyword" instead of "/change-bg url", so....it's something, I guess.

But I'd really like it to happen automatically, like if a keyword shows up in the course of chat, the background changes. But nothing I tried ever seemed to be able to change the avatar (but I guess it would only work on the active character? Does custom code execute on imported characters?)

(Edit: Thought I'd be cute and give the coding assistant the ability to look at urls, and pointed her at the custom code pages, but it doesn't retrieve enough of the page to be useful, I don't think.)

you are viewing a single comment's thread
view the rest of the comments
[–] VioneT 2 points 3 months ago* (last edited 3 months ago) (1 children)

It's because the message is split by the whitespaces, meaning 'living room' would be split to 'living' and 'room'. You could remove the .split(...).map(...) and just normalize the message with .toLowerCase()i.e. message.content.toLowerCase() then it should work for the 'living room'.

[–] [email protected] 1 points 3 months ago

Got it, thanks! :D