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

discord-emoji-utils

v1.0.0-beta.2

Published

A utility library for managing custom emoji cache.

Downloads

3

Readme

Discord Emoji Utils

Discord Emoji Utils is a utility library for managing custom emoji cache in Discord applications. It provides functions to add emojis, remove duplicate emojis based on their ID and name or by their image hash, and perform additional operations such as emoji download and upload.

Installation

Install the package using npm:

npm install discord-emoji-utils

Usage

const { EmojiUtils } = require('discord-emoji-utils');

// Create an instance of EmojiUtils
const emojiUtils = new EmojiUtils();

// Add emojis to the utility
emojiUtils.addEmoji({ id: '1', name: 'emoji1', imageUrl: 'https://example.com/emoji1.png' });
emojiUtils.addEmoji({ id: '2', name: 'emoji2', imageUrl: 'https://example.com/emoji2.png' });
emojiUtils.addEmoji({ id: '3', name: 'emoji3', imageUrl: 'https://example.com/emoji3.png' });

// Remove duplicate emojis by ID and name
emojiUtils.removeDuplicateEmojis();

// Remove duplicate emojis by image hash
emojiUtils.removeDuplicateEmojisByImageHash();

// Get the updated emoji list
const updatedEmojis = emojiUtils.getEmojis();
console.log(updatedEmojis);

// Perform other operations such as emoji download and upload

API

addEmoji(emoji)

Adds an emoji to the utility.

  • emoji (object): An object representing the emoji with properties id, name, and imageUrl.

removeDuplicateEmojis()

Removes duplicate emojis from the cache based on their ID and name.

removeDuplicateEmojisByImageHash()

Removes duplicate emojis from the cache based on their image hash.

getEmojis()

Returns the updated list of emojis after removing duplicates.

downloadImage(imageUrl)

Downloads the image from the specified URL and returns a promise that resolves with the image data as a buffer.

  • imageUrl (string): The URL of the image to download.

computeImageHash(imageUrl)

Computes the image hash for the specified image URL using image processing techniques. Returns a promise that resolves with the computed image hash.

  • imageUrl (string): The URL of the image for which to compute the hash.

Examples

Downloading Emojis

const { EmojiUtils } = require('discord-emoji-utils');

const emojiUtils = new EmojiUtils();

// Add emojis to the utility
emojiUtils.addEmoji({ id: '1', name: 'emoji1', imageUrl: 'https://example.com/emoji1.png' });
emojiUtils.addEmoji({ id: '2', name: 'emoji2', imageUrl: 'https://example.com/emoji2.png' });
emojiUtils.addEmoji({ id: '3', name: 'emoji3', imageUrl: 'https://example.com/emoji3.png' });

// Download emojis to a folder
const destinationFolder = './emojis';
emojiUtils.downloadEmojis(destinationFolder)
  .then(downloads => {
    console.log('Emojis downloaded:', downloads);
  })
  .catch(error => {
    console.error('Failed to download emojis:', error);
  });

Uploading Emojis

const { EmojiUtils } = require('discord-emoji-utils');
const Discord = require('discord.js');

const emojiUtils = new EmojiUtils();
const client = new Discord.Client();
const guildId = '1234567890'; // Replace with the desired guild ID

// Add emojis to the utility
emojiUtils.addEmoji({ id: '1', name: 'emoji1', imageUrl: 'https://example.com/emoji1.png' });
emojiUtils.addEmoji({ id: '2', name: 'emoji2', imageUrl: 'https://example.com/emoji2.png' });
emojiUtils.addEmoji({ id: '3', name: 'emoji3', imageUrl: 'https://example.com/emoji3.png' });

// Upload emojis to a Discord guild
const uploadEmojis = async () => {
try {
await client.login('YOUR_DISCORD_TOKEN');
const guild = await client.guilds.fetch(guildId);
// Get the updated list of emojis
const updatedEmojis = emojiUtils.getEmojis();

// Upload emojis to the guild
for (const emoji of updatedEmojis) {
  const { id, name, imageUrl } = emoji;
  const imageBuffer = await emojiUtils.downloadImage(imageUrl);
  const uploadedEmoji = await guild.emojis.create(imageBuffer, name);
  console.log('Uploaded emoji:', uploadedEmoji);
}

// Logout the client
await client.logout();
} catch (error) {
console.error('Failed to upload emojis:', error);
}
};

uploadEmojis();

License

This project is licensed under the MIT License.