npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@d-lab/discord-puppet

v0.6.8

Published

NodeJs client to interact with Discord app as a puppet.

Downloads

52

Readme

Discord Puppet NodeJSTypeScript npm version

Node client that simulates a Discord user in a headless browser. Use Discord functionalities including BOT interaction on the server-side. Include a Midjourney client which you can use to generate images using the /imagine command of Midjourney.

available on NPM

Installation

npm i @d-lab/discord-puppet 

Discord Puppet is using Puppeteer to simulate a Discord user in a headless browser. If you want to run it on a headless browser, you may have to install addition depencies based on your OS.

For Debian UI-less: check tavinus GIST

sudo apt install libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2 libpangocairo-1.0-0 libxss1 libgtk-3-0

Discord Puppet base SDK

You will find different basic actions for Discord under the Puppet class. You can use it to create your own puppet, such as the Midjourney Puppet described below.

Example

import {Puppet, options} from "@d-lab/discord-puppet"

const config: Option = options(
    process.env.DISCORD_USERNAME,
    process.env.DISCORD_PASSWORD
)
/** Setup Puppet config and pluggins */
const puppet = new Puppet(config)

/** Start Puppet opens a browser and a new Tab, handle Login then redirect to specified server or default one*/
await puppet.start()

await puppet.clickServer("My Server")
await puppet.clickChannel("my-channel")
await puppet.sendMessage("Hello world!")

/** close headless browser */
await puppet.shutdown()

I18N support

Discord use different label in the code based on your language settings. You can specify the language you want to use in the config constructor. For now only English and French are set up, but no worries there are only 3 labels to translate.

import {Puppet, buildOptions, Language, LanguagePack} from "@d-lab/discord-puppet"

const frLanguage: LanguagePack = new LanguagePack("fr", {
  "servers": "Serveurs",
  "channels": "Salons",
  "close": "Fermer"
})

const config: Option = buildOptions({
  username: process.env.DISCORD_USERNAME,
  password: process.env.DISCORD_PASSWORD,
  language: frLanguage
  //language: Language.EN
})
/** Setup Puppet config and pluggins */
const puppet = new Puppet(config)

MidJourney Puppet

This library has been initially built to create a puppet for the MidJourney AI Art generation. This service is only available on Discord as a bot for now. Using this puppet you can easily generate AI art using the puppet.imagine() method on the server side.

Prerequisite

This Puppet is using the MidJourney Bot, you will need to add it to your server. You can find the bot on the MidJourney Website.

  • Join MidJourney Discord
  • If your discord user never used MidJourney before
    • run any command on MidJourney bot (such as imagine)
    • accept their Terms of Service
    • your user is set up!
  • Create a new Personal Server on Discord: for example 'My Art' steps
  • Add the bot to your personal server from MidJourney server steps
  • Add a new channel: for example 'all-art'
  • You're good to go!

Example

import {MidjourneyPuppet, options} from "@d-lab/discord-puppet"

const config: Option = options(
    process.env.DISCORD_USERNAME,
    process.env.DISCORD_PASSWORD
)
const puppet = new MidjourneyPuppet(config)
await puppet.start()
await puppet.clickServer("My Art")
await puppet.clickChannel("all-art")

/** Get your MidJourney account status */
const msg1 = await puppet.info()
console.log("MJY account: ", msg1)

/** Ask MidJourney to generate an image */
// you can specify an optional callback that will receive the url of the image being generated on the fly
// you will receive multiple URLs every time MidJourney is updating the not-finished-image
// it can be usefull if you want to show the loading image to the user
function loading(url: string) {
    console.log("Loading ~ ", url)
}

const msg2 = await puppet.imagine(`Your Imagine prompt (check MidJourney prompt guides)`, loading)
console.log("MJY image: ", msg2)

Test Locally

You can use the example script located in ./bin to try out this library.

First clone this repository on your local machine.

clone https://github.com/Draym/discord-puppet.git
cd discord-puppet

Then install the dependencies

npm i

Then create a .env file with your Discord credentials. You can check the file .env.example to see the mandatory fields.

Then run the example script

ts-node ./bin/midjourney-cmds.ts