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

web-discord-transcripts

v4.0.0

Published

Build web discord transcripts easily

Downloads

22

Readme

web-discord-transcripts

web-discord-transcripts is an npm package that provides a convenient solution for creating web transcripts of chat conversations, particularly for Discord bots, with a focus on ticket systems. This package streamlines the process of generating chat logs and enables easy integration with web applications or user interfaces. It creates static html webpage which can be used to display the transcripts.

Table of Contents

Installation

You can install web-discord-transcripts using npm or yarn:

npm install web-discord-transcripts
# or
yarn add web-discord-transcripts

Usage

To use web-discord-transcripts in your Discord bot or web application, follow the steps below:

Generate the static webpage:

import { Webpage, Message } from "web-discord-transcripts"
import { channels } from "../constants/channel.js"
import { guilds } from "../constants/guild.js"
import data from "../transcripts/example.js"

const nodes = data.map((data) => {
  const node = Message({
    user: data.user,
    payload: { content: data.content, embeds: data.embeds },
    time: new Date()
  })

  return node
})

const page = Webpage({
  title: "ticket-transcript",
  content: nodes,
  data: {
    guild: guilds.nightfangCommunity,
    chatChannel: channels.ticketTranscripts
  }
})

For example, you can use express to show the generated webpage on the browser. Feel free to customize the above steps according to your application's specific needs. This package aims to simplify the process of managing and displaying chat transcripts for discord conversations, especially useful for ticket system.

Examples

index.js:

import express from "express"
import transcriptRouter from "./routes/transcript.js"

const app = express()
const port = 3000

app.get("/", (_req, res) => {
  res.send("api (/) endpoint")
})

app.use("/transcripts", transcriptRouter)

app.listen(port, () => {
  console.log(`server started at port: ${port}`)
})

constants/channel.js:

import { Channel } from "web-discord-transcripts"

export const channels = {
  ticketTranscripts: new Channel({ name: "ticket-transcripts" }),
  modApplication: new Channel({ name: "📄 mod-application" })
}

constants/guild.js:

import { Guild } from "web-discord-transcripts"

export const guilds = {
  nightfangCommunity: new Guild({
    name: "Nightfang Community",
    iconURL: "https://cdn.discordapp.com/icons/960453487743881237/aaa40a37a4fa84580aa317e7de696d24.webp"
  })
}

constants/role.js:

import { Role } from "web-discord-transcripts"

export const roles = {
  staff: new Role({ name: "Staff", color: "#5865f2" }),
  bot: new Role({ name: "Bot", color: "#f87248" }),
  support: new Role({ name: "Support", color: "#ffff00" }),
  member: new Role({ name: "Member", color: "#ffffff" }),
}

constants/user.js:

import { User } from "web-discord-transcripts"
import { roles } from "./role.js"

export const users = {
  nightfang: new User({
    username: "Nightfang",
    avatarURL: "https://cdn.discordapp.com/avatars/984245658905104384/a90a3ad0359ff2f67e65b40a13e2cb0d.png?size=1024",
    bot: true,
    highestRole: roles.bot
  }),
  shadow: new User({
    username: "Shadow",
    avatarURL: "https://cdn.discordapp.com/avatars/893705256368750592/957bb7cf2f720432d818c9257a610b8c.png?size=1024",
    highestRole: roles.staff
  }),
  john: new User({
    username: "John",
    highestRole: roles.support
  }),
  joe: new User({
    username: "Joe",
    highestRole: roles.member
  })
}

transcripts/example.js:

import { Embed } from "web-discord-transcripts"

import { channels } from "../constants/channel.js"
import { users } from "../constants/user.js"
import { roles } from "../constants/role.js"

const welcomeEmbed = new Embed({
  color: "#12c4ff",
  title: "Welcome Joe",
  description: `Please wait patiently for the ${roles.staff.mention()} to respond, until then do tell the purpose of creating the ticket`
})

const closeEmbed = new Embed({
  color: "#f87248",
  description: `Ticket closed by ${users.john.mention()}`
})

const data = [
  {
    user: users.nightfang,
    embeds: [welcomeEmbed]
  },
  {
    user: users.joe,
    content: [
      "Hello",
      `${roles.staff.mention()} I want to apply for ${roles.support.mention()} role`
    ]
  },
  {
    user: users.shadow,
    content: [
      `${users.john.mention()} will handle this ticket, I'm busy right now`
    ]
  },
  {
    user: users.john,
    content: [
      "Hi!",
      `${users.joe.mention()} please apply for the support role at ${channels.modApplication.mention()}`,
      `You can ping me if you want to ask anything`
    ]
  },
  {
    user: users.joe,
    content: [
      "Okay, thanks for the support!",
      "You may close the ticket"
    ]
  },
  {
    user: users.nightfang,
    embeds: [closeEmbed]
  },
  {
    user: users.nightfang,
    content: [
      "This ticket will be deleted in a few seconds"
    ]
  }
]

export default data

routes/transcript.js:

import { Webpage, Message } from "web-discord-transcripts"
import { channels } from "../constants/channel.js"
import { guilds } from "../constants/guild.js"
import data from "../transcripts/example.js"
import { Router } from "express"

const router = Router()

router.get("/example", (_req, res) => {
  const nodes = data.map((data) => {
    const node = Message({
      user: data.user,
      payload: { content: data.content, embeds: data.embeds },
      time: new Date()
    })

    return node
  })

  const page = Webpage({
    title: "ticket-transcript",
    content: nodes,
    data: {
      guild: guilds.nightfangCommunity,
      chatChannel: channels.ticketTranscripts
    }
  })

  res.status(200).send(page)
})

export default router

Contributing

Contributions are welcome! If you find any issues or want to suggest enhancements, please open an issue or submit a pull request on the GitHub repository. Always ensure to check if an issue or pull request already exists before creating your own! There’s no need to hurry in making contributions, take your time to do it right.

Help

For support and assistance, join our Discord server and connect with the community to resolve any issues or queries related to the package.

License

web-discord-transcripts is licensed under the MIT License. See the LICENSE file for more information.