Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequency/Auto Settings #39

Open
LunaWasHere opened this issue Jun 22, 2022 · 2 comments
Open

Frequency/Auto Settings #39

LunaWasHere opened this issue Jun 22, 2022 · 2 comments

Comments

@LunaWasHere
Copy link

Is there any chance there can be some sort of Auto setting? A previous markov bot I was aware of allowed you to set a % chance for every message that was typed by a user in a listened channel to trigger a message from the bot. It created a lot of very fun chaos because the bot would chime in at random times and you never knew when or what was gonna happen. Additionally, if we can get % chance setting for how often it embeds an image instead of it randomly choosing to embed an image alongside its post that would also be wonderful!

@solenum
Copy link

solenum commented Jan 18, 2024

Did anyone happen to fork this and implement this feature? Feels kind of useless to have a markov chain bot that can't auto-trigger.

@solenum
Copy link

solenum commented Jan 18, 2024

Did it myself, here's the git diff if you want to give it a try (could do with not being an int, 1% may be too high of a min chance for most use cases)

diff --git a/src/config/classes.ts b/src/config/classes.ts
index bb1002f..11dc9c2 100644
--- a/src/config/classes.ts
+++ b/src/config/classes.ts
@@ -163,4 +163,13 @@ export class AppConfig {
   @IsOptional()
   @IsString()
   devGuildId = process.env.DEV_GUILD_ID;
+
+  /**
+   * Specifies the chance in 100 to randomly respond to a message
+   * @example 95
+   * @env RANDOM_CHANCE
+   */
+  @IsOptional()
+  @IsInt()
+  randomChance = process.env.RANDOM_CHANCE ? parseInt(process.env.RANDOM_CHANCE, 10) : 100;
 }
diff --git a/src/index.ts b/src/index.ts
index 40953bd..02972bf 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -771,6 +771,15 @@ client.on('messageCreate', async (message) => {
   }
   if (command === null) {
     if (isHumanAuthoredMessage(message)) {
+      // handle random response
+      if ((await isValidChannel(message.channel))) {
+        var chance = Math.random() * 100;
+        if (chance >= (100 - config.randomChance)) {
+          const generatedResponse = await generateResponse(message);
+          await handleResponseMessage(generatedResponse, message);
+        }
+      }
+
       if (client.user && message.mentions.has(client.user)) {
         L.debug('Responding to mention');
         // <@!278354154563567636> how are you doing?

You can then build the docker image and import it like this (probably a more efficient way to tag on save but I couldn't be bothered to read the docker docs)

Locally
> docker build .
> docker image ls
> docker save -o discordmarkov.tar <id>
> scp discordmarkov.tar yourserver:

Server
> docker load -i discordmarkov.tar
> docker tag <id> discordmarkov:tag
and reference discordmarkov:tag with docker/in your docker-compose.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants