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

@modcord/message-parser

v1.0.1

Published

A not so fast and not so efficient parser using regular expressions for discord messages, supports custom emojis and spoilers.

Downloads

9

Readme

Discord Message Parser

  • Has zero dependencies.
  • A message parser for discord using regular expressions and string manipulation.
  • If you need help feel free to join our discord server to talk and help you with your code.
  • If you encounter any of those fell free to open an issue in our github repository.

Download & Update

You can download it from npm:

npm i discord-message-parser

You can update to a newer version to receive updates using npm.

npm update discord-message-parser

Changelog

3rd of April (v1.0.0) - Original publication to node package manager.

Setting Up

First things first, we include the module into the project.

const MessageParser = require("discord-message-parser");
const { SpoilerParser, EmojiParser } = MessageParser;

Examples

Examples assume that you have setted up the module as presented in 'Setting Up' section. Following examples assume that your Discord.Client is called client.

Following examples assume that your client.on("message", message is called message.

Following example contains isolated code which you need to integrate in your own command handler.

  • Counting emojis in a message:
client.on("message", (message) => {
  const emojiCount = EmojiParser.countEmojis(message.content);
  console.log(emojiCount);
  /*  Sample output: 
     {
       custom: 1,
       animated: 0,
       unicode: 2,
       total: 3
     }
  */
});
  • Parsing emojis in a message:
client.on("message", (message) => {
  const messageEmojis = EmojiParser.parseEmojis(message.content);
  console.log(messageEmojis);
  /* Sample output:
  {
      custom: [{ name: "doggo", id: "393852367751086090", raw: "<:doggo:393852367751086090>", animated: false, unicode: false }],
      customAnimated: [{ name: "dogdance", id: "663013890376073257", raw: "<:dogdance:663013890376073257>", animated: true, unicode: false }],
      customEmojis: [{ name: "doggo", id: "393852367751086090", raw: "<:doggo:393852367751086090>", animated: false, unicode: false }, { name: "dogdance", id: "663013890376073257", raw: "<:dogdance:663013890376073257>", animated: true, unicode: false }],
      unicode: [{ name: null, id: null, raw: "⏱️", animated: null, unicode: true }, { name: null, id: null, raw: "☕", animated: null, unicode: true }],
      allEmojis: [{ name: "doggo", id: "393852367751086090", raw: "<:doggo:393852367751086090>", animated: false, unicode: false }, { name: "dogdance", id: "663013890376073257", raw: "<:dogdance:663013890376073257>", animated: true, unicode: false }, { name: null, id: null, raw: "⏱️", animated: null, unicode: true }, { name: null, id: null, raw: "☕", animated: null, unicode: true }]
  }
  */
});
  • Parsing spoilers in a message:
client.on("message", (message) => {
  const messageSpoilers = SpoilerParser.parseSpoilers(message.content);
  console.log(messageSpoilers);
  /* Sample Output
  [
    { content: 'is killed', raw: '||is killed||' },
    { content: 'married tom', raw: '||married tom||' }
  ]
  */
});

Is time for you to get creative..

Methods

1. Emoji Parsing API

_parseCustomEmojis - Used internally by the library

Parses the non-animated custom emojis from a string.

EmojiParser._parseCustomEmojis(<Content - String>);
  • Output:
Array<Emoji>

_parseAnimatedCustomEmojis - Used internally by the library

Parses the animated custom emojis from a string.

EmojiParser._parseAnimatedCustomEmojis(<Content - String>);
  • Output:
Array<Emoji>

_parseUnicodeEmojis - Used internally by the library

Parses the unicode emojis from a string.

EmojiParser._parseUnicodeEmojis(<Content - String>);
  • Output:
Array<Emoji>

countEmojis

Counts the amount of emojis found in a string and returns the numbers.

EmojiParser.countEmojis(<Content - String>);
  • Output:
Object

_parseEmoji - Used internally by the library

Parse the custom emoji, both animated and not, and returns an array of 1 (custom emoji, non animated, it's the emoji's id) or 2 elements (first - an a string, specific for animated emojis & then the second it's the emoji's id).

EmojiParser._parseEmoji(<Content - String>);
  • Output:
Array<String>

parseEmojis

Parses the string's emojis and returns them in an object, with emojis grouped into 5 properties (custom, customAnimated, customEmojis, unicode, allEmojis), each of them is an array of emojis.

EmojiParser.parseEmojis(<Content - String>);
  • Output:
Object

2. Spoiler Parsing API

_parseSpoilerContent - Used internally by the library

Parse a spoiler from end to finnish and returns its contents.

SpoilerParser._parseSpoilerContent(<Content - String>);
  • Output:
String

parseSpoilers

Parses all of the spoilers in a string and returns them as an array with objects having content and raw properties.

SpoilerMarser.parseEmojis(<Content - String>);
  • Output:
Array<Object>