Giter Club home page Giter Club logo

md-embed's Introduction

What is EmbedMD?

EmbedMD, or dekita-md-embed is a simple module written by DekitaRPG that allows you to load a markdown file, or directory of, and then convert the file(s) into discord.js embed objects! You can then send those embeds in discord.js like you normally would!!

Please note: discord.js is REQUIRED for this module to function.

License TLDR

Copyright (c) 2021 Dekita ([email protected]) [view license]

Documentation

https://dekita.github.io/md-embed/

System Requirements

node.js | discord.js

Author Information

email | website | twitter | github

How To Use This Module In Your Own Projects:

Assuming you already have a node.js project that uses discord.js, getting setup with this module is incredibly straighforward! Just follow the examples below to get you started.

Install EmbedMD

npm i dekita-md-embed

Require EmbedMD

const EmbedMD = require('dekita-md-embed');

Create Markdown Files

Once you have installed EmbedMD, create a file and save it as filename.md. Use the format detailed below for the file contents, and then it can be used as a template for creating discord.js embeds.

# URL #
{creator.url}

# TITLE #
title text... 

# COLOR #
RANDOM

# AUTHOR #
{user.name} :: {user.avatar} :: {creator.url}

# THUMBNAIL #
{bot.avatar}

# DESCRIPTION #
description text...

# FOOTER #
{user.name} :: {user.avatar}

# FIELD #
label :: string :: true

# FIELDS #
label :: string :: true

# TIMESTAMP #
false

NOTE1: If using a hex color code within the COLOR field, remove the # or you will get errors! NOTE2: FIELD, FIELDS, AUTHOR, and FOOTER elements exprect multiple properties. These should be delimited using a double : character (::)! If you dont want to delimit with :: then you can set a custom delimiter by setting the EmbedMD.delimiter. For example, to use -;

EmbedMD.delimiter = '-';

Load A File Then Create Embed

const embed_md = EmbedMD.prepareMD('/directory/path.md'); // cache embed files from path
const embed = EmbedMD.getEmbed(embed_md); // get embed using embed_md

Load All Files From Directory Then Create Embed

const embed_mds = EmbedMD.parseDir('/directory/path'); // cache embed files from path
const embed_ids = Object.keys(embed_mds); // array of filenames without.md and route
const embed = EmbedMD.getEmbed(embed_mds.embed_id); // get embed using embed_id

Send Embed With discord.js

// in some discord js command interaction:
await interaction.reply({embeds: [embed]});

Formatting Embed Templates

Its entirely possible to have the embed parse information based on additional properties. For example, you might want to display user information or some data from a variable within your embed. Simply pass an object as the second argument to getEmbed with the properties that you want to replace within your .md file. For example, lets assume the following files:

file.md:

# FOOTER #
{user.name} :: {user.avatar}

file.js:

const embed_md = EmbedMD.prepareMD('./file.md');
const embed = EmbedMD.getEmbed(embed_md, {
    '{user.avatar}': interaction.user.displayAvatarURL(),
    '{user.name}': interaction.user.username,
    '{creator.url}': "https://dekitarpg.com",
}); 

With these files in place, an embed with only footer information will be created, and will use the interaction user information for the footer content when being initialized.

Global Replacers

You can define replacer key:value's globally by using the setGlobalReplacer function. All future embedds created will use then these replacers. NOTE: If you define a global replacer, and then supply a duplicate replacer for any embed template, the global replacer will be ignored. Use unsetGlobalReplacer if you need to later remove global replacer key:values.

EmbedMD.setGlobalReplacer('{bot.name}', client.user.username);
EmbedMD.setGlobalReplacer('{bot.color}', CONFIG.embed_color.replace('#',''));
EmbedMD.setGlobalReplacer('{bot.avatar}', client.user.displayAvatarURL());

Additional

You can also utilize the included helper functions for anything you might find useful. They are pretty handy!

EmbedMD.format("Hi name!", {name: 'DekiaRPG'});
// => "Hi DekitaRPG!"

EmbedMD.parseArray(['1', '5', 'false', 'some description']);
// => [1, 5, false, 'some description']

Actual Real Life Reviews

Tbh this is the most useful/creative/good-idea lib i've seen around here in a long time - Tim

md-embed's People

Contributors

dekita avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.