this post was submitted on 30 Jan 2024
24 points (90.0% liked)

Lemmy Integrations

274 readers
1 users here now

A community about all integrations with the lemmy API. Bots, Scripts, New Apps, etc.

founded 10 months ago
MODERATORS
24
submitted 10 months ago* (last edited 10 months ago) by Demigodrick to c/[email protected]
 

As inspired by the bots on Reddit that respond to certain words, I've thrown together this code which allows anyone to set up their own response bot.

There is a bit more detail on Github, but in summary you can set your own trigger word and responses, and you have two modes of operation, "Exclude" which is the default and covers every community you're federated with (and allows moderators of a community to PM the bot to exclude it) and "Include", where you can pick a single community for the bot to be active in.

This is really early days and rough, but should work at the most basic level. Anyone who can provide some ideas/feedback/improvements - I'm totally open to them.

And to prove it works, I'm running Legolas Bot. Any comment you make below with the word "legolas" in will get a response (probably).

Small updates to reduce spaminess - will only reply to top level comments now.

Edit: Little updates include customisable polling rates and the ability to tag the comment creators name in a response.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 5 points 10 months ago (11 children)

Looking at the code, it seems to download the 25 newest comments every 5 seconds from the instance it is configured to go through. I understand that this is probably the easiest way to go, but that sounds also like a lot of useless traffic by downloading the same messages over and over. Isn't there a way to make it more efficient and get only the unread messages? Lemmy does not support that? I guess one would need to fiddle in the code of an instance to do that efficiently.

[–] Demigodrick 4 points 10 months ago* (last edited 10 months ago) (8 children)

It's in json format so in reality it's very little data. There's no way (that I know of) to grab only "new" comments - I don't think the lemmy api has anything like that.

Even if you put seen comments in a db you've still got to pull them to check if they've been seen or not which defeats the object.

25 every 5 seconds might be a touch overkill too but it does stop the bot missing any comments. I can certainly move them to variables that can be set in the env file/docker.

Edit to add: if it is locked down to one community then yes its way overkill, so will add them as variables and update docs to reflect.

[–] [email protected] 2 points 10 months ago (1 children)

I see, thanks. I guess at one point if it becomes problematic, instances can add hooks or light-weight calls.

[–] Demigodrick 2 points 10 months ago

I've pushed the change so operators can change those values in the env file or via docker. Btw let me know if you do start work on the megathread thing, it does pose an interesting challenge in terms of structuring posts and handling that data.

load more comments (6 replies)
load more comments (8 replies)