It’s hard to understand what you’re trying to do here…
I would recommend stripping the problem down to a couple lines and explaining what you want and why your code doesn’t work.
If you’re trying to extract information from a string regular expressions are the way to go. You should probably add more to the regexp to capture the name and the percentage, like so:
re.match(r'(.*) \(([0-9]*)%\)', s).groups()
You can do it a lot of ways. Use as many or as few files as you want. I figure for this one js file is sufficient.
Parameters would probably be the easiest to learn passing data; In lua, reading and writing to a “subprocess” isn’t trivial. see here, or here.
To simplify it, you could just write comment data to the js script and return errors to lua with “exit codes”.
Ahh, I see, sorry.
The simplest and dumbest way to make this work is to:
io.popen
Does the js client need to be installed in a certain location?
you need to make a “project directory”. Create a new directory the run npm install lemmy-js-client
to get started.
Where does the block of text on the api docs go? Just in my bot.lua file?
Make a file named lemmy-post.js and paste this from the api doc into it:
import { LemmyHttp } from 'lemmy-js-client';
let baseUrl = 'https://lemmy.ml';
let client: LemmyHttp = new LemmyHttp(baseUrl, headers?);
let jwt = await client.httpLogin(loginForm).jwt;
websocket or http? Does it matter?
websockets are good for persistent connections, but since your lua-bot will will be calling the script to do one-off tasks I would stick with the HTTP API
I need to make a POST request to lemmy to uyt the content there after I grab the comment from discord?
Presumably the lua-bot will have the content of the discord comment, so you just need to pass it to the JS script which will post it to lemmy.
Can someone recommend me a resource so I can learn more about using the API here?
I would recommend just playing around with the js-client in that script. run it like this: node lemmy-post.js
here are the js-clients docs:
https://join-lemmy.org/api/
also: this should probably have been posted to !javascript@heapoverflow.ml =/
FWIW, not having side-effects from being ran twice is called “idempotency”
I see.
res += "4 " + name
The problem here is you’re doing<List> += <str>
Changing it to:
res.append('4 ' + name)
fixes it