add more safer korean replace

This commit is contained in:
kimpure 2026-05-21 13:09:54 +00:00
parent 8d3d55601d
commit ae3339e49f
No known key found for this signature in database
4 changed files with 48 additions and 20 deletions

View file

@ -1,4 +1,4 @@
import { Channel, ChatInputCommandInteraction, MessageFlags, SlashCommandSubcommandBuilder } from "discord.js";
import { Channel, ChannelType, ChatInputCommandInteraction, MessageFlags, SlashCommandSubcommandBuilder } from "discord.js";
import { defineCommand, DiscordCommand } from "../command";
import { insertGuildReadChannel } from "../db";
@ -9,6 +9,7 @@ export default defineCommand(
.addChannelOption(option =>
option
.setName("channel")
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildVoice)
.setDescription("예주가 읽을 채널이에요")
.setRequired(true)
),

View file

@ -1,4 +1,4 @@
import { Channel, ChatInputCommandInteraction, MessageFlags, SlashCommandSubcommandBuilder } from "discord.js";
import { Channel, ChannelType, ChatInputCommandInteraction, MessageFlags, SlashCommandSubcommandBuilder } from "discord.js";
import { defineCommand, DiscordCommand } from "../command";
import { insertGuildReadChannel, removeGuildReadChannel } from "../db";
@ -9,6 +9,7 @@ export default defineCommand(
.addChannelOption(option =>
option
.setName("channel")
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildVoice)
.setDescription("예주가 더이상 읽지 않을 채널이에요")
.setRequired(true)
),
@ -29,7 +30,7 @@ export default defineCommand(
return await interaction.editReply("읽지 않는것을 실패했어요 ?ㄴ");
}
await interaction.editReply("예주가 이제 이 채널을 읽지않아요!");
await interaction.editReply(`예주가 <#${channel.id}> 채널을 읽지않아요!`);
},
true
)

View file

@ -55,21 +55,19 @@ export default defineEvent("messageCreate", async (message) => {
return;
if (message.content === "") {
return await playVoice(
guild,
profile,
voice,
content =
message.attachments.size > 0
? `${message.attachments.size} 개의 첨부파일`
: "알수없는 메시지"
);
} else {
for (const text of content.split("\n")) {
await playVoice(guild, profile, voice, text, options);
content = message.attachments.size > 0
? `${message.attachments.size} 개의 첨부파일`
: "알수없는 메시지"
if (message.attachments.size == 1 && Math.random() < 0.05) {
content = "어이, 유저. 일개의 첨부파일이 뭘 할 수 있지?"
}
}
for (const text of content.split("\n")) {
await playVoice(guild, profile, voice, text, options);
}
} catch(err) {
message.reply("말이 꼬이네요 ㅜ.ㅜ");
console.log("playVoice failed. ", err);

View file

@ -103,10 +103,33 @@ export const LangPrefixMaxLength = (()=>{
return max;
})();
export const SIPrefix = {
"k": "킬로",
"ki": "키비",
"m": "메가",
"mi": "메비",
"g": "기가",
"gi": "기비",
"t": "테라",
"ti": "테비",
"p": "페타",
"pi": "페비",
"e": "엑사",
"ei": "엑시",
"z": "제타",
"zi": "제비",
"y": "요타",
"yi": "요비",
}
export function processDots(input: string): string {
return input.replace(/[\.,]+$/, "")
.replace(/[\.,]{2,}/g, "")
.replace(/[\.,]\s/g, " ");
}
export function saferKorean(input: string): string {
return input.replace(/\.+$/, "")
.replace(/\.\.+/g, "")
.replace(/\.[ \t]/g, " ")
return processDots(input)
.replace(/^[\?\!\'\"]+$/, (total)=>(
[...total].map(element => IsolatedSymbolMap[
element as keyof typeof IsolatedSymbolMap
@ -123,7 +146,7 @@ export function saferKorean(input: string): string {
}
return lang + "코드블럭";
})
.replace(/ㅋ{2,}/g, "크")
.replace(/ㅋ{2,}/g, (content) => "크".repeat(content.length))
.replace(/[아ㅏ]{3,}/g, "아아아")
.replace(/https\S+/g, "링크")
.replace(/ㅌ{2,}/g, "틔틔")
@ -133,7 +156,12 @@ export function saferKorean(input: string): string {
}
return content;
})
.replace(/(\d+)[ \t\n]*([개살])/g, (_, num: string, postfix: string)=>{
.replace(/(\d+)([kKMmgGtTpP][iI]?)[bB]/g, (_, num: string, mod: string) => {
num = IntegerKorean.convertFromString(num);
mod = SIPrefix[mod.toLowerCase() as keyof typeof SIPrefix];
return `${num} ${mod}바이트 `;
})
.replace(/(\d+)[ \t\n]*([개살시])/g, (_, num: string, postfix: string)=>{
const intNum = parseInt(num)
if (CallingNumberKorean.canConvert(intNum)) {
return CallingNumberKorean.convert(intNum) + postfix;