sleeplessone1917 / lemmy-bot Goto Github PK
View Code? Open in Web Editor NEWA bot library for Lemmy, the fediverse link aggregator.
Home Page: https://www.npmjs.com/package/lemmy-bot
License: GNU Affero General Public License v3.0
A bot library for Lemmy, the fediverse link aggregator.
Home Page: https://www.npmjs.com/package/lemmy-bot
License: GNU Affero General Public License v3.0
Is there a way to check if a person is a mod? In the "creator" variable there is just "admin" and this is not mod.
I don't really like having my logs spammed by the library's activity, I'd prefer handling my own logging in my app, only for the operations where I deem it necessary.
I propose creating an additional, optional flag in the new LemmyBot()
constructor to disable the output of logs from the library.
If @SleeplessOne1917 likes the idea I could also implement such a feature myself and submit a PR for it.
Sometimes I'll start a script and it'll give me this error and exits. It'd be nice if it could gracefully handle this error.
I'm connecting to lemmy.world as my instance, which has weird connectivity issues. I'm wondering if the ws is timing out and actorId
isn't getting set properly. If so, it would be nice if it could attempt to reconnect.
Log:
> ts-node src/main.ts
Connected to Lemmy Instance
Initializing DB
Logging in
Marking account as bot account
Subscribing to communities
/node_modules/lemmy-bot/dist/helpers.js:55
const extractInstanceFromActorId = (actorId) => actorId.match(/https?:\/\/(.*)\/(?:c|u)\/.*/)[1];
^
TypeError: Cannot read properties of null (reading '1')
at extractInstanceFromActorId (/node_modules/lemmy-bot/dist/helpers.js:55:94)
at LemmyBot.<anonymous> (/node_modules/lemmy-bot/dist/bot.js:804:90)
at Generator.next (<anonymous>)
at /node_modules/lemmy-bot/dist/bot.js:8:71
at new Promise (<anonymous>)
at __awaiter (/node_modules/lemmy-bot/dist/bot.js:4:12)
at WebSocketConnection.<anonymous> (/node_modules/lemmy-bot/dist/bot.js:449:51)
at WebSocketConnection.emit (node:events:513:28)
at WebSocketConnection.emit (node:domain:489:12)
at WebSocketConnection.processFrame (/node_modules/websocket/lib/WebSocketConnection.js:554:26)
at /node_modules/websocket/lib/WebSocketConnection.js:323:40
at processTicksAndRejections (node:internal/process/task_queues:77:11)
This is a feature request, it should already be possible since the code already has this:
Lines 492 to 496 in 9dfaa18
I've got a bot for lemmy.world and it has stopped working since they've upgraded to 0.18.1-rc.4
It fails at logging in:
Starting bot
Initializing DB
app listening at http://localhost:1234
logging in
D:\projects\lemmybot\node_modules\node-fetch\lib\index.js:273
return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
^
FetchError: invalid json response body at https://lemmy.world/api/v3/user/login reason: Unexpected token J in JSON at position 0
at D:\projects\lemmybot\node_modules\node-fetch\lib\index.js:273:32
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
type: 'invalid-json'
}
I've double checked, the account credentials I'm passing in are valid.
Hi,
Can a feature be added to get the source text of a communities' (and instances') sidebar? I would like to be able to limit where my bot is run and allowing instance and community owners to set specific markdown in the sidebar seems like the easiest way to do this.
Thanks!
It happens when the ratelimit is achieved, it happens every time on lemmy.world and i have my poll rate at 15 ( i tested at 120 ). But it will straight up 502 Gateway Error ( Sometimes /comment sometimes /posts ) and after few seconds the login will fail too because it gets tot the ratelimit too.
I would guess the requests between comments and posts are too fast and need a buffer between them ( just use the poll rate as buffer between calls )
Tried Lemmy Instance:
lemmy.world
The allowList property of the federation option does not seem to be followed, and the bot will reply to all comments/posts on any federated community.
example:
federation: {
allowList: [
{
instance: 'lemmy.world',
communities: ['vexillology']
},
{
instance: 'lemmy.antemeridiem.xyz',
communities: ['vexillologyjerk']
}
]
},
I am using lemmy-bot 0.3.9 from npm
Works fine in memory, on disk tends to take one or two start attempts for it to finish initialisation.
Initializing DB
/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:43
const getRow = (db, id, table) => new Promise((resolve, reject) => {
^
Error: SQLITE_ERROR: no such table: posts
--> in Database#get('SELECT id, reprocessTime FROM posts WHERE id=?;', 54, [Function (anonymous)])
at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:44:8
at new Promise (<anonymous>)
at getRow (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:43:35)
at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:74:88
at Generator.next (<anonymous>)
at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:8:71
at new Promise (<anonymous>)
at __awaiter (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:4:12)
at get (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:74:26)
at get (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:102:26)
at LemmyBot.<anonymous> (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:988:35)
at Generator.next (<anonymous>)
at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:8:71
at new Promise (<anonymous>)
at __awaiter (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:4:12)
at LemmyBot._LemmyBot_handleEntry (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:987:12)
at LemmyBot.<anonymous> (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:505:129)
at Generator.next (<anonymous>)
at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:8:71
at new Promise (<anonymous>)
at __awaiter (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:4:12)
at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:503:64
at Array.map (<anonymous>)
at LemmyBot.<anonymous> (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:503:46)
at Generator.next (<anonymous>)
at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:8:71
at new Promise (<anonymous>) {
errno: 1,
code: 'SQLITE_ERROR',
__augmented: true
}
Due to how getUserId and getCommunityId try to find the id (using the search), if the actual user or community doesnt show up in that then it cant be found by the query
For example if you try to look for the id of the community [email protected]. Doing a call to getCommunityId("git") then does an api call to https://programming.dev/api/v3/search?q=git&type_=Communities which does not have git as one of the options (instead its populated by other things that have git in the name)
Hey! I haven't gotten my bot to work after updating the instance to Lemmy 0.18.0. Is this because they no longer are using websockets? If so, will this library update?
Some weird database issues..
Error: SQLITE_BUSY: database is locked
--> in Statement#run({ '$id': 42368, '$reprocessTime': null }, [Function (anonymous)])
at Database.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/sqlite3/lib/sqlite3.js:76:19)
at Database.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/sqlite3/lib/sqlite3.js:20:19)
at <anonymous> (/app/node_modules/.pnpm/github.com+SleeplessOne1917+lemmy-bot@6ed4abbf3e6c343e60ecffa94059b51eae8afbb5_i365mkdgu5davuyz74udnrlrka/node_modules/lemmy-bot/dist/db.js:57:8)
at new Promise (<anonymous>)
at upsert (/app/node_modules/.pnpm/github.com+SleeplessOne1917+lemmy-bot@6ed4abbf3e6c343e60ecffa94059b51eae8afbb5_i365mkdgu5davuyz74udnrlrka/node_modules/lemmy-bot/dist/db.js:56:58)
at <anonymous> (/app/node_modules/.pnpm/github.com+SleeplessOne1917+lemmy-bot@6ed4abbf3e6c343e60ecffa94059b51eae8afbb5_i365mkdgu5davuyz74udnrlrka/node_modules/lemmy-bot/dist/db.js:75:114)
at Generator.next (<anonymous>)
at <anonymous> (/app/node_modules/.pnpm/github.com+SleeplessOne1917+lemmy-bot@6ed4abbf3e6c343e60ecffa94059b51eae8afbb5_i365mkdgu5davuyz74udnrlrka/node_modules/lemmy-bot/dist/db.js:8:71) {
errno: 5,
code: 'SQLITE_BUSY',
__augmented: true
}
Hi,
I see the lib can get and edit posts and comments by ID, but what about listing IDs by user ?
Thanks
function onPrivateMessage(res){
console.log(res)
res.botActions.sendPrivateMessage(res.messageView.private_message.creator_id, "holaa")
}
this prints Sending private message to user ID undefined
and does not send anything
I'm looking into making a bot that lets commenters vote on what genres apply to the story and then locks it and logs it into a database that will (probably) be web-accessible.
I, admittedly, have not worked on it at all yet, but I'm imagining the comment will be updated to reflect what genres have been accepted and (maybe) a link to find more like it.
If there's no way to edit a comment via this (or any other) library, then this project will be a non-starter and probably dropped before it's even started.
This would allow us to find federated communities/posts/comments/people.
I currently need this to be able to find/fetch not-yet federated communities on my instance.
I've been doing some development on a bot, and I don't want to post my in-progress threads to a live, production lemmy instance. I'd prefer to be able to set the bot to be in "dry run" mode, and only log to the console the actions it would have taken on the production instance
The new option would be used as follows
const bot = new LemmyBot.LemmyBot({
enableLogs: true,
dryRun: true
});
Every login attempt results in a user_already_exists
error. This probably happens in saveUserSettings() and looks like it's related to this issue, apparently one needs to include all user data in saveUserSettings()
.
to remove a comment I'm using
botActions.removeComment({
reason: "Requested by user " + userName,
removed: true,
comment_id: parentId
});
with parentId
defined, but it prints Removing comment ID undefined
and does not remove the comment.
I created a bot and it didnt got any posts from my community. And after i debugged it. It fetches 1 time correctly but then it doesnt fetch it anymore.
lemmyService.bot = new LemmyBot({
instance: process.env.LEMMY_INSTANCE!,
credentials: {
username: process.env.LEMMY_USERNAME!,
password: process.env.LEMMY_PW!,
},
connection: {
minutesUntilReprocess: 1,
secondsBetweenPolls: 30,
},
schedule: [],
federation: "all",
dbFile: "./lemmy.db",
handlers: {
post: async ({
botActions,
postView,
preventReprocess,
reprocess,
}) => {
console.log("NEW POST")
});
It logs like in the initial start the first 30 posts and then i can wait like for 15 minutes nothing happens
i created simple bot with posts
and privateMessage
handlers. After running for some time it closes with the following error:
node main.js
Starting bot
Initializing DB
(node:89951) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Logging in
Logged in
/home/dell/dbx-home/image_compare/node_modules/node-fetch/lib/index.js:1501
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://lemmy.world/api/v3/post/list?type_=Subscribed&auth=*censored*&sort=New failed, reason:
at ClientRequest.<anonymous> (/home/dell/dbx-home/image_compare/node_modules/node-fetch/lib/index.js:1501:11)
at ClientRequest.emit (node:events:519:28)
at TLSSocket.socketErrorListener (node:_http_client:495:9)
at TLSSocket.emit (node:events:519:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:540:9)
at process.processTimers (node:internal/timers:514:7) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
}
Node.js v21.5.0
It works for 20-30 mins before closing. One time it closed right after starting.
I made that the bot automatically sends a message to a new post in a community. Everything works and the library replies with
"Replying to post ID 651474"
My Code:
botActions.createComment({
content: Config.autoComment.text,
postId: postView.post.id,
});
But nothing happens
I was wondering if Lemmy has any native ability to detect if a post was changed, and what was changed without having to store that information in an external database? If so, does lemmy-bot also have that functionality?
Can't seem to get any further, it logs in, marks user as bot, and then just sits at user_already_exists
Not sure where the logs are dumped
Hi, wondering if you could help with where I'm going wrong.
I'm using the like me bot example, and getting the error "Expected 1 arguments, but got 2. (ts2554) on the Vote.Upvote lines and the same error on the SendPrivateMessage lines where the text is flagging the same error.
I'm really new to this so most likely an error with my setup but google has been no help in figuring this out.
Thanks
edit: on Lemmy 0.18 and using bot version 0.4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.