Skip to content

Commit 2f05a7d

Browse files
committed
pronouns: accept more styles of user input
1 parent 12f8640 commit 2f05a7d

File tree

1 file changed

+50
-32
lines changed

1 file changed

+50
-32
lines changed

sopel/modules/pronouns.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,19 @@
1414
# Copied from pronoun.is, leaving a *lot* out. If
1515
# https://github.com/witch-house/pronoun.is/pull/96 gets merged, using that
1616
# would be a lot easier.
17-
KNOWN_SETS = {
18-
'ze': 'ze/hir/hir/hirs/hirself',
19-
'ze/hir': 'ze/hir/hir/hirs/hirself',
20-
'ze/zir': 'ze/zir/zir/zirs/zirself',
21-
'they': 'they/them/their/theirs/themselves',
22-
'they/them': 'they/them/their/theirs/themselves',
23-
'they/.../themselves': 'they/them/their/theirs/themselves',
24-
'they/.../themself': 'they/them/their/theirs/themself',
25-
'she': 'she/her/her/hers/herself',
26-
'she/her': 'she/her/her/hers/herself',
27-
'he': 'he/him/his/his/himself',
28-
'he/him': 'he/him/his/his/himself',
29-
'xey': 'xey/xem/xyr/xyrs/xemself',
30-
'xey/xem': 'xey/xem/xyr/xyrs/xemself',
31-
'sie': 'sie/hir/hir/hirs/hirself',
32-
'sie/hir': 'sie/hir/hir/hirs/hirself',
33-
'it': 'it/it/its/its/itself',
34-
'it/it': 'it/it/its/its/itself',
35-
'ey': 'ey/em/eir/eirs/eirself',
36-
'ey/em': 'ey/em/eir/eirs/eirself',
37-
}
17+
# If ambiguous, the earlier one will be used.
18+
KNOWN_SETS = [
19+
"ze/hir/hir/hirs/hirself",
20+
"ze/zir/zir/zirs/zirself",
21+
"they/them/their/theirs/themselves",
22+
"they/them/their/theirs/themself",
23+
"she/her/her/hers/herself",
24+
"he/him/his/his/himself",
25+
"xey/xem/xyr/xyrs/xemself",
26+
"sie/hir/hir/hirs/hirself",
27+
"it/it/its/its/itself",
28+
"ey/em/eir/eirs/eirself",
29+
]
3830

3931

4032
@plugin.command('pronouns')
@@ -76,7 +68,9 @@ def say_pronouns(bot, nick, pronouns):
7668

7769

7870
@plugin.command('setpronouns')
79-
@plugin.example('.setpronouns they/them/their/theirs/themselves')
71+
@plugin.example('.setpronouns fae/faer/faer/faers/faerself')
72+
@plugin.example('.setpronouns they/them/theirs')
73+
@plugin.example('.setpronouns they/them')
8074
def set_pronouns(bot, trigger):
8175
"""Set your pronouns."""
8276
pronouns = trigger.group(2)
@@ -85,21 +79,45 @@ def set_pronouns(bot, trigger):
8579
return
8680

8781
disambig = ''
88-
if pronouns == 'they':
89-
disambig = ' You can also use they/.../themself, if you prefer.'
90-
pronouns = KNOWN_SETS.get(pronouns)
91-
elif pronouns == 'ze':
92-
disambig = ' I have ze/hir. If you meant ze/zir, you can use that instead.'
93-
pronouns = KNOWN_SETS.get(pronouns)
94-
elif len(pronouns.split('/')) != 5:
95-
pronouns = KNOWN_SETS.get(pronouns)
96-
if not pronouns:
82+
requested_pronoun_split = pronouns.split("/")
83+
if len(requested_pronoun_split) < 5:
84+
matching = []
85+
for known_pronoun_set in KNOWN_SETS:
86+
known_pronoun_split = known_pronoun_set.split("/")
87+
if known_pronoun_set.startswith(pronouns + "/") or (
88+
len(requested_pronoun_split) == 3
89+
and (
90+
(
91+
# "they/.../themself"
92+
requested_pronoun_split[1] == "..."
93+
and requested_pronoun_split[0] == known_pronoun_split[0]
94+
and requested_pronoun_split[2] == known_pronoun_split[4]
95+
)
96+
or (
97+
# "they/them/theirs"
98+
requested_pronoun_split[0:2] == known_pronoun_split[0:2]
99+
and requested_pronoun_split[2] == known_pronoun_split[3]
100+
)
101+
)
102+
):
103+
matching.append(known_pronoun_set)
104+
105+
if len(matching) == 0:
97106
bot.reply(
98107
"I'm sorry, I don't know those pronouns. "
99108
"You can give me a set I don't know by formatting it "
100109
"subject/object/possessive-determiner/possessive-pronoun/"
101110
"reflexive, as in: they/them/their/theirs/themselves"
102111
)
103112
return
113+
114+
pronouns = matching[0]
115+
if len(matching) > 1:
116+
disambig = " Or, if you meant one of these, please tell me: {}".format(
117+
", ".join(matching[1:])
118+
)
119+
104120
bot.db.set_nick_value(trigger.nick, 'pronouns', pronouns)
105-
bot.reply("Thanks for telling me!" + disambig)
121+
bot.reply(
122+
"Thanks for telling me! I'll remember you use {}.{}".format(pronouns, disambig)
123+
)

0 commit comments

Comments
 (0)