cross-posted from: https://fuckreddit.tryp.digital/post/72

As the title says, I’m trying to create my own discord bot that takes channel comments and posts them on lemmy but I’m woefully underprepared. I definitely just need some more baseline info because as always I’m already in much deeper than I should be. Thanks for any help!

I’ve already setup a bot (on the same server as lemmy, exactly how it’s described in the linked doc) and can successfully ping it from my server. I used this to set it up which uses Lua and I’m unsure if that will be an issue. I can setup node.js if need be.

I also installed the lemmy-js-client. I guess I have a few questions but really I’ll take any help I can get :)

  • Does the js client need to be installed in a certain location?
  • Where does the block of text on the api docs go? Just in my bot.lua file?
  • websocket or http? Does it matter?
  • I need to make a POST request to lemmy to uyt the content there after I grab the comment from discord?
  • Can someone recommend me a resource so I can learn more about using the API here? More than willing to do the legwork on my own but I’d like to know I’m going in the right track first.

Additionally I was trying to use pipedream for assistance. I can optionally run code right on the site as shown in the picture below but also I can use any API account or make a POST request which are 2nd and 3rd photos below respectively. I’m taking a stab at the http POST workflow in between typing this.

  • Tryp@fuckreddit.tryp.digitalOP
    link
    fedilink
    arrow-up
    1
    ·
    3 years ago

    True I guess the at that stage Lua is no longer relevant.

    Also I linked that document in my post. Are you able to answer the questions I asked at all it would be a big help! :)

    • thann@heapoverflow.mlM
      link
      fedilink
      arrow-up
      3
      ·
      3 years ago

      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

      • Tryp@fuckreddit.tryp.digitalOP
        link
        fedilink
        arrow-up
        3
        ·
        3 years ago

        Oh my god my hero! :)

        Okay I’m starting to understand this more and will probably be taking a deeper stab at this soon. The where/how is this bot running is what was getting me but after reading up on node.js a little more it’s all making more sense.

        When it comes to passing the info from discord, this is when I’ll need to use parameters to define what data to take form the previous steps? This will also have to be in one file? So one file per action or string of actions?

        • thann@heapoverflow.mlM
          link
          fedilink
          arrow-up
          2
          ·
          3 years ago

          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”.

          • Tryp@fuckreddit.tryp.digitalOP
            link
            fedilink
            arrow-up
            2
            ·
            3 years ago

            Excellent! Alright feeling the confidence. If I find some time after the easter weekend I’m going for another run! :) Thanks a million.