Skip to content

Instantly share code, notes, and snippets.

@DCubix
Last active May 16, 2019 13:39
Show Gist options
  • Save DCubix/f06a1567e88c7fcd030603c9132cb6c1 to your computer and use it in GitHub Desktop.
Save DCubix/f06a1567e88c7fcd030603c9132cb6c1 to your computer and use it in GitHub Desktop.
Convert text into emoji for Discord
#!/bin/python3
import sys, random
## HOW TO USE:
## python emojitext.py "your text here" zws
## zws: This option is used to enable a zero-width space character to prevent discord from
## converting your characters into flags.
DIGIT = [':zero:', ':one:', ':two:', ':three:', ':four:', ':five:', ':six:', ':seven:', ':eight:', ':nine:']
ALTS = ['ben', 'crap', 'jx9', 'tuts', 'thinking', 'smirk', 'tada', 'snus', 'punk', 'face_palm', 'facepalm', 'clap', 'ok_hand', 'smile', '1234']
ZWS = '\u200b' if len(sys.argv) > 2 and sys.argv[2] == 'zws' else ''
def to_emoji(word):
if word in ALTS:
print(':%s:' % word, end=ZWS)
else:
for c in word:
if random.randint(0, 100) >= 50 and c == 'b':
print(':b:', end=ZWS)
else:
if c.isdigit():
print(DIGIT[int(c)], end=ZWS)
else:
print(':regional_indicator_%s:' % c, end=ZWS)
if len(sys.argv) > 1:
spl = sys.argv[1].lower().split(' ')
for word in spl:
to_emoji(word.strip())
print('', end=' ')
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment