• 0 Posts
Joined 4M ago
Cake day: Jan 21, 2022


I see.

res += "4 " + name The problem here is you’re doing <List> += <str>

Changing it to: res.append('4 ' + name) fixes it

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()

I think if you trimmed the problem down to a couple of lines you’d get a better response =/

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:

  1. make a JS script to make a post
  2. run the script from lua with io.popen
now I will answer your questions:

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:

also: this should probably have been posted to !javascript@heapoverflow.ml =/

Once lemmy has “flair” and we can filter by it, they should be comparable. But lemmy has the huge feature of federation.

Using readlink -f instead of cd && pwd, and /../ instead of multiple dirnames will make it a lot more readable:
export DOT="$(readlink -f "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")"/../../)"

I figured that already existed, and didn’t want to fragment the community =/

You’re doing a lot of confusing and unnecessary stuff here so it’s hard to understand what you want, but I think this is what you’re trying to do:

source "$(dirname ${BASH_SOURCE[0]})"/../config/zsh/.zshenv

return just exits from the function it is directly inside of. I think you just want to put if command -v pacstall; then in the last function.

Also, you should be able to tell it doesn’t work by running it =/

I think this is as close as you’re going to get
xargs apt-get install --ignore-missing < my_package_list.txt

sorry, I misread and thought he was asking trying to run “visual studio” or something lol

It’s not advised to run apps with sudo.

I created a script for vim that will let me save with sudo, so I just need the password when saving. I would recommend looking for a similar solution.

tee is useful for sending stdin to a file AND stdout, if you want to just write to a file you can do:

cat <<EOF > /tmp/file_to_write
stuff $VAR etc

EDIT: to append use this top line: cat <<EOF >> /tmp/file_to_write (double >)

FWIW, not having side-effects from being ran twice is called “idempotency

I see, I would ask it in a different sub =/

this: <<EOF is called a “here-doc”, and variable interpolation works in it =\

I hope that “flair” will solve this issue in the future.

You can if you want tho

Well, there will always be an element of opinion in questions and answers.
What are you thinking of asking?