Skip to content

Commit c83749d

Browse files
committed
reorder word chain checks to hit less ratelimits
Signed-off-by: cobalt <61329810+cobaltt7@users.noreply.github.com>
1 parent 19c9bd1 commit c83749d

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

modules/word-chain/handle.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,30 @@ export default async function handleWordChain(message: Message): Promise<void> {
9393
return;
9494
}
9595

96+
const latest = await Word.findOne({ channel: message.channel.id })
97+
.sort({ createdAt: -1 })
98+
.exec();
99+
100+
if (latest?.author === message.author.id) {
101+
await reject(
102+
`${
103+
constants.emojis.statuses.no
104+
} ${message.author.toString()} **You can’t send two words in a row!**`,
105+
);
106+
return;
107+
}
108+
109+
const letter = latest && latest.word.at(-1)?.toLowerCase();
96110
const current = normalize(word);
97-
if (!(await isWord(current, language))) {
111+
if (letter && letter !== current[0]) {
98112
await reject(
99113
`${
100114
constants.emojis.statuses.no
101-
} ${message.author.toString()} **Unknown word!** ${inlineCode(
115+
} ${message.author.toString()} **Wrong letter!** ${inlineCode(
102116
current,
103-
)} is not a word. (language: ${language.name})`,
117+
)} does not start with ${inlineCode(letter.toUpperCase())}, which ${inlineCode(
118+
latest.word,
119+
)} ends with.`,
104120
);
105121
return;
106122
}
@@ -122,29 +138,13 @@ export default async function handleWordChain(message: Message): Promise<void> {
122138
return;
123139
}
124140

125-
const latest = await Word.findOne({ channel: message.channel.id })
126-
.sort({ createdAt: -1 })
127-
.exec();
128-
129-
if (latest?.author === message.author.id) {
130-
await reject(
131-
`${
132-
constants.emojis.statuses.no
133-
} ${message.author.toString()} **You can’t send two words in a row!**`,
134-
);
135-
return;
136-
}
137-
138-
const letter = latest && latest.word.at(-1)?.toLowerCase();
139-
if (letter && letter !== current[0]) {
141+
if (!(await isWord(current, language))) {
140142
await reject(
141143
`${
142144
constants.emojis.statuses.no
143-
} ${message.author.toString()} **Wrong letter!** ${inlineCode(
145+
} ${message.author.toString()} **Unknown word!** ${inlineCode(
144146
current,
145-
)} does not start with ${inlineCode(letter.toUpperCase())}, which ${inlineCode(
146-
latest.word,
147-
)} ends with.`,
147+
)} is not a word. (language: ${language.name})`,
148148
);
149149
return;
150150
}

0 commit comments

Comments
 (0)