Provides utilities for parsing and accessing Discord emojis.
Project description
Discord Emoji Parser
A Python library providing utilities for parsing and accessing Discord emojis with advanced functionality such as emoji enumeration and dynamic handling.
Features
- Parse individual or multiple Discord emojis from a string.
- Generate CDN-hosted URLs for emojis (animated or static).
- Validate emoji format.
- Convert parsed emojis into JSON mappings for integration with other tools.
- Dynamically create Enum classes for Discord emojis, enabling easy programmatic access.
Installation
This project uses Poetry for dependency management. The easiest way to instal is with pip
pip install discordemojiparser
Usage
Importing the Library
from discordemojiparser.emoji_parser import EmojiParser
Parsing Emojis
Parse a Single Emoji
emoji_str = "<a:wave:123456789>"
emoji = EmojiParser.parse_single(emoji_str)
print(emoji.name) # wave
print(emoji.url) # https://cdn.discordapp.com/emojis/123456789.gif
Parse All Emojis in a String
text = "<a:wave:123456789> <:smile:987654321>"
emojis = EmojiParser.parse_all(text)
for emoji in emojis:
print(emoji.name, emoji.url)
Validate Emoji Strings
print(EmojiParser.is_emoji("<a:wave:123456789>")) # True
print(EmojiParser.has_emoji("Hello <a:wave:123456789>!")) # True
print(EmojiParser.is_emoji("wave:123456789>")) # False
Generating JSON from Emojis
text = "<a:wave:123456789> <:smile:987654321>"
emoji_json = EmojiParser.get_emojis_json(text)
print(emoji_json)
# Output: {'wave': 'https://cdn.discordapp.com/emojis/123456789.gif',
# 'smile': 'https://cdn.discordapp.com/emojis/987654321.png'}
Creating Emoji Enums
Dynamically Generate an Enum for Emojis
text = "<a:wave:123456789> <:smile:987654321>"
EmojiEnum = EmojiParser.get_emojis_enum(text)
# Access emoji attributes via Enum
print(EmojiEnum.wave.url) # https://cdn.discordapp.com/emojis/123456789.gif
print(EmojiEnum.smile.name) # smile
# Iterate through Enum members
for emoji_name, emoji in EmojiEnum.__members__.items():
print(emoji_name, emoji.url)
Example Application
from discordemojiparser.emoji_parser import EmojiParser
# Input text containing Discord emojis
text = """
<:gamesir:1176772767132168232>
<a:wave:123456789>
<smile:987654321>
"""
# Parse all emojis and create an enum
EmojiEnum = EmojiParser.get_emojis_enum(text)
# Use the enum
print(EmojiEnum.gamesir.url) # https://cdn.discordapp.com/emojis/1176772767132168232.png
print(EmojiEnum.wave.url) # https://cdn.discordapp.com/emojis/123456789.gif
Project Structure
discordemojiparser/
├── discordemojiparser/
│ ├── __init__.py
│ ├── emoji_parser.py
│ └── emoji_enum.py
├── pyproject.toml
└── README.md
└── LICENSE
- discordemojiparser/emoji_parser.py: Core logic for parsing and handling emojis.
- discordemojiparser/emoji_enum.py: Custom Enum implementation for managing emojis programmatically.
- pyproject.toml: Poetry configuration.
Author
Dylan Magar ("DJ Stomp")
- GitHub: @DJStompZone
License
MIT License (see LICENSE file)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file discordemojiparser-1.0.1.tar.gz.
File metadata
- Download URL: discordemojiparser-1.0.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7624e8fae1194dc1da6c5b3c28f90aa4167581d5cce3b63d6cf3e072a582ceff
|
|
| MD5 |
67f91ba08e89407403933ffba97ab5ed
|
|
| BLAKE2b-256 |
34e95af23e21a22a342628604e749ed15fded036c570d0c4fd63eaba9d495eb6
|
File details
Details for the file discordemojiparser-1.0.1-py3-none-any.whl.
File metadata
- Download URL: discordemojiparser-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3320aa1234fb0d2ce6901ace58d0cd0a3946a8c1f86da0b0ebb3fa70599c5f2
|
|
| MD5 |
af009a2211b9f6f2a368abfa21ad24b1
|
|
| BLAKE2b-256 |
629b969c9d5311cab98850aabff00b1341d76c8a04a646bd581636d3a91f6160
|