1.0.0 • Published 1 year ago

discord-mainscript v1.0.0

Weekly downloads
-
License
mainscript
Repository
-
Last release
1 year ago

discord-html-transcripts

Discord HTML mainscript is a node.js module to generate nice looking HTML transcripts. Processes discord markdown like bold, italics, strikethroughs, and much more! Nicely formats attachments and embeds.

This module can format the following things like:

  • Discord flavored markdown
    • Allows for complex markdown syntax to be parsed properly
  • Embeds
  • System messages
    • Join messages
    • Message Pins
    • Boost messages
  • Slash commands
    • Will show the name of the command in the same style as Discord
  • Buttons
  • Reactions
  • Attachments
    • Images, videos, audio, and generic files
  • Replies
  • Mentions
  • Threads

📝 Usage

Example usage using the built in message fetcher.

const discordTranscripts = require('discord-html-mainscript');
// or (if using typescript) import * as discordTranscripts from 'discord-html-mainscript';

const channel = message.channel; // or however you get your TextChannel

// Must be awaited
const attachment = await discordTranscripts.createTranscript(channel);

channel.send({
  files: [attachment],
});

Or if you prefer, you can pass in your own messages.

const discordTranscripts = require('discord-html-mainscript');
// or (if using typescript) import * as discordTranscripts from 'discord-html-mainscript';

const messages = someWayToGetMessages(); // Must be Collection<string, Message> or Message[]
const channel = someWayToGetChannel(); // Used for ticket name, guild icon, and guild name

// Must be awaited
const attachment = await discordTranscripts.generateFromMessages(messages, channel);

channel.send({
  files: [attachment],
});
//if you prefer, you can also send the html file to your own dashboard page! to do this you need to us fs so:
const fs = require('fs').promises;
let channel = interaction.channel
        let test = await mainscript.createTranscript(channel, {
            limit: -1,
            returnType: 'string',
            returnBuffer: false,
            fileName: `${channel.name}`,
            minify: true,
            saveImages: true,
            useCDN: true,
        })

await fs.writeFile(process.cdv() + `some place you want to create your file to...`, test).catch(err => console.log(err));
//if you need any help how you can do this all. You can always add me on discord: tonymelony#5793 :)

⚙️ Configuration

Both methods of generating a transcript allow for an option object as the last parameter.
All configuration options are optional!

Built in Message Fetcher

const attachment = await discordTranscripts.createTranscript(channel, {
    limit: -1, // Max amount of messages to fetch. `-1` recursively fetches.
    returnType: 'attachment', // Valid options: 'buffer' | 'string' | 'attachment' Default: 'attachment' OR use the enum ExportReturnType!
    filename: 'transcript.html', // Only valid with returnType is 'attachment'. Name of attachment.
    saveImages: false, // Download all images and include the image data in the HTML (allows viewing the image even after it has been deleted) (! NOTE IT WILL INCREASE FILE SIZE !)
    callbacks: {
      // register custom callbacks for the following:
      resolveChannel: (channelId: string) => Awaitable<Channel | null>,
      resolveUser: (userId: string) => Awaitable<User | null>,
      resolveRole: (roleId: string) => Awaitable<Role | null>
    },
    poweredBy: true // Whether to include the "Powered by discord-html-mainscript" footer
});

Providing your own messages

const attachment = await discordTranscripts.generateFromMessages(messages, channel, {
  // Same as createTranscript, but no limit
});

🤝 Hope you will enjoy the package? Love By Tonymelony