Skip to content

Commit

Permalink
BUG: Hide emoji professions for disabled 'person'
Browse files Browse the repository at this point in the history
Fixes #13

This still doesn't take into account a few exceptions like:

	older person
	prince
	princess
	merperson
	mermaid
	mx claus
	...
  • Loading branch information
kernc committed Feb 6, 2025
1 parent 2bc2bbb commit 35975ff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
16 changes: 14 additions & 2 deletions efck/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def clean_desc(text):
text = re.sub(r'\W{2,}', ' ', text)
return text

emojis = []
known_man_names = set()

official_emoji = set()
with open(EMOJI_ORDERING_FILE, encoding='utf-8') as fd:
for line in fd:
Expand All @@ -88,6 +91,8 @@ def clean_desc(text):
emoji_normed = ''.join(ch for ch in emoji if ch not in MODIFIER_CHARS)
shortcode = shortcodes.pop(emoji_normed, '')

if name.startswith('man'):
known_man_names.add(name.split(':')[0])
if should_skip_emoji(name):
continue

Expand All @@ -96,11 +101,18 @@ def clean_desc(text):
shortcode = clean_desc(shortcode)
custom_str = ' '.join(filter(None, (custom_strings.get(ch, '') for ch in emoji)))

yield emoji, name, alt_name, shortcode, custom_str
emojis.append((emoji, name, alt_name, shortcode, custom_str))

# All shortcodes were consumed
assert not shortcodes, shortcodes

# Trail with custom emoji sequences from the file
for custom_emoji in custom_strings.keys() - official_emoji:
yield custom_emoji, '', '', '', custom_strings[custom_emoji]
emojis.append((custom_emoji, '', '', '', custom_strings[custom_emoji]))

# Skip person in case of emojis for which either man or woman
# versions also exist ("health worker", "astronout" ...)
is_person_disabled = not config_state[EmojiTab.__name__]['Gender']['person']
if is_person_disabled:
emojis[:] = [i for i in emojis if f'man {i[1]}' not in known_man_names]
return emojis
2 changes: 1 addition & 1 deletion efck/tabs/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, *args, **kwargs):

def init(self):
logger.info('Reloading emoji ...')
self.emoji_data = list(enum_emojis())
self.emoji_data = enum_emojis()

def rowCount(self, index):
return len(self.emoji_data)
Expand Down
13 changes: 12 additions & 1 deletion efck/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,21 @@ class TestEmoji(TestCase):
def test_enum_emoji(self):
from .emoji import enum_emojis

emojis = list(enum_emojis())
emojis = enum_emojis()
self.assertGreater(len(emojis), 1000)
self.assertGreater(len(emojis[0]), 3)

def test_no_judge(self):
from .emoji import enum_emojis
from .config import _gender

# Test disabled neuter professions are not present
_gender.update({'person': 0, 'man': 0, 'woman': 1})
emojis = enum_emojis()
judge = [i[1] for i in emojis if 'judge' in i[1]]
self.assertEqual(len(judge), 1)
self.assertIn('woman', judge[0])


class TestOutput(TestCase):
def test_copy_to_clipboard(self):
Expand Down

0 comments on commit 35975ff

Please sign in to comment.