fix(tts): correct Discord snowflake regex and getSource typo
- Mention/emoji regexes used [(0-9)]{18}; '(' and ')' inside a character
class are literal so this matched the bracket chars themselves and
hard-fixed the ID length to 18. Discord snowflakes are 17-20 digits
(older 2015-2017 accounts are 17, 2024+ trend toward 19-20). Switch
to \\d{17,20} and capture the ID for member lookup.
- Tighten emoji regex name segment from .* (greedy, eats across emojis)
to [^:]+ so adjacent emojis no longer collapse into one match.
- Rename getSorce -> getSource.
This commit is contained in:
@@ -62,7 +62,7 @@ export class TTSClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
text = this.textEditor(channel.guild, text);
|
text = this.textEditor(channel.guild, text);
|
||||||
const buf = await this.getSorce(text);
|
const buf = await this.getSource(text);
|
||||||
if (!buf) return;
|
if (!buf) return;
|
||||||
|
|
||||||
const session = this.getSession(channel.guild, voiceChannel);
|
const session = this.getSession(channel.guild, voiceChannel);
|
||||||
@@ -91,7 +91,7 @@ export class TTSClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async getSorce(text: string): Promise<Buffer | null> {
|
private async getSource(text: string): Promise<Buffer | null> {
|
||||||
const parts = text.split(signature.regex);
|
const parts = text.split(signature.regex);
|
||||||
const bufferList: Buffer[] = [];
|
const bufferList: Buffer[] = [];
|
||||||
|
|
||||||
@@ -119,11 +119,11 @@ export class TTSClient {
|
|||||||
if (text.length === 0) return "파일";
|
if (text.length === 0) return "파일";
|
||||||
return text
|
return text
|
||||||
.replace(URL_RE, (u) => labelForUrl(u) ?? u)
|
.replace(URL_RE, (u) => labelForUrl(u) ?? u)
|
||||||
.replace(/\<\@\!?[(0-9)]{18}\>/g, (t) => {
|
.replace(/<@!?(\d{17,20})>/g, (_t, id: string) => {
|
||||||
const member = guild.members.cache.get(t.replace(/[^0-9]/g,""));
|
const member = guild.members.cache.get(id);
|
||||||
return member?.nickname ?? member?.user.username ?? "유저";
|
return member?.nickname ?? member?.user.username ?? "유저";
|
||||||
})
|
})
|
||||||
.replace(/\<a?\:.*\:[(0-9)]{18}\>/g, () => {
|
.replace(/<a?:[^:]+:\d{17,20}>/g, () => {
|
||||||
return "이모티콘";
|
return "이모티콘";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user