add more safer korean replace
This commit is contained in:
parent
8d3d55601d
commit
ae3339e49f
4 changed files with 48 additions and 20 deletions
|
|
@ -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 { defineCommand, DiscordCommand } from "../command";
|
||||||
import { insertGuildReadChannel } from "../db";
|
import { insertGuildReadChannel } from "../db";
|
||||||
|
|
||||||
|
|
@ -9,6 +9,7 @@ export default defineCommand(
|
||||||
.addChannelOption(option =>
|
.addChannelOption(option =>
|
||||||
option
|
option
|
||||||
.setName("channel")
|
.setName("channel")
|
||||||
|
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildVoice)
|
||||||
.setDescription("예주가 읽을 채널이에요")
|
.setDescription("예주가 읽을 채널이에요")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -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 { defineCommand, DiscordCommand } from "../command";
|
||||||
import { insertGuildReadChannel, removeGuildReadChannel } from "../db";
|
import { insertGuildReadChannel, removeGuildReadChannel } from "../db";
|
||||||
|
|
||||||
|
|
@ -9,6 +9,7 @@ export default defineCommand(
|
||||||
.addChannelOption(option =>
|
.addChannelOption(option =>
|
||||||
option
|
option
|
||||||
.setName("channel")
|
.setName("channel")
|
||||||
|
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildVoice)
|
||||||
.setDescription("예주가 더이상 읽지 않을 채널이에요")
|
.setDescription("예주가 더이상 읽지 않을 채널이에요")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
),
|
),
|
||||||
|
|
@ -29,7 +30,7 @@ export default defineCommand(
|
||||||
return await interaction.editReply("읽지 않는것을 실패했어요 ?ㄴ");
|
return await interaction.editReply("읽지 않는것을 실패했어요 ?ㄴ");
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.editReply("예주가 이제 이 채널을 읽지않아요!");
|
await interaction.editReply(`예주가 <#${channel.id}> 채널을 읽지않아요!`);
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
@ -55,20 +55,18 @@ export default defineEvent("messageCreate", async (message) => {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (message.content === "") {
|
if (message.content === "") {
|
||||||
return await playVoice(
|
content = message.attachments.size > 0
|
||||||
guild,
|
|
||||||
profile,
|
|
||||||
voice,
|
|
||||||
content =
|
|
||||||
message.attachments.size > 0
|
|
||||||
? `${message.attachments.size} 개의 첨부파일`
|
? `${message.attachments.size} 개의 첨부파일`
|
||||||
: "알수없는 메시지"
|
: "알수없는 메시지"
|
||||||
);
|
|
||||||
} else {
|
if (message.attachments.size == 1 && Math.random() < 0.05) {
|
||||||
|
content = "어이, 유저. 일개의 첨부파일이 뭘 할 수 있지?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const text of content.split("\n")) {
|
for (const text of content.split("\n")) {
|
||||||
await playVoice(guild, profile, voice, text, options);
|
await playVoice(guild, profile, voice, text, options);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
message.reply("말이 꼬이네요 ㅜ.ㅜ");
|
message.reply("말이 꼬이네요 ㅜ.ㅜ");
|
||||||
|
|
|
||||||
|
|
@ -103,10 +103,33 @@ export const LangPrefixMaxLength = (()=>{
|
||||||
return max;
|
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 {
|
export function saferKorean(input: string): string {
|
||||||
return input.replace(/\.+$/, "")
|
return processDots(input)
|
||||||
.replace(/\.\.+/g, "")
|
|
||||||
.replace(/\.[ \t]/g, " ")
|
|
||||||
.replace(/^[\?\!\'\"]+$/, (total)=>(
|
.replace(/^[\?\!\'\"]+$/, (total)=>(
|
||||||
[...total].map(element => IsolatedSymbolMap[
|
[...total].map(element => IsolatedSymbolMap[
|
||||||
element as keyof typeof IsolatedSymbolMap
|
element as keyof typeof IsolatedSymbolMap
|
||||||
|
|
@ -123,7 +146,7 @@ export function saferKorean(input: string): string {
|
||||||
}
|
}
|
||||||
return lang + "코드블럭";
|
return lang + "코드블럭";
|
||||||
})
|
})
|
||||||
.replace(/ㅋ{2,}/g, "크")
|
.replace(/ㅋ{2,}/g, (content) => "크".repeat(content.length))
|
||||||
.replace(/[아ㅏ]{3,}/g, "아아아")
|
.replace(/[아ㅏ]{3,}/g, "아아아")
|
||||||
.replace(/https\S+/g, "링크")
|
.replace(/https\S+/g, "링크")
|
||||||
.replace(/ㅌ{2,}/g, "틔틔")
|
.replace(/ㅌ{2,}/g, "틔틔")
|
||||||
|
|
@ -133,7 +156,12 @@ export function saferKorean(input: string): string {
|
||||||
}
|
}
|
||||||
return content;
|
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)
|
const intNum = parseInt(num)
|
||||||
if (CallingNumberKorean.canConvert(intNum)) {
|
if (CallingNumberKorean.canConvert(intNum)) {
|
||||||
return CallingNumberKorean.convert(intNum) + postfix;
|
return CallingNumberKorean.convert(intNum) + postfix;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue