63 lines
No EOL
1.7 KiB
TypeScript
63 lines
No EOL
1.7 KiB
TypeScript
import { getOrCreateVoiceConnection } from "../util";
|
|
import { getUserProfile, hasGuildReadChannel } from "../db";
|
|
import { defineEvent } from "../event";
|
|
import { playVoice } from "../tts";
|
|
|
|
export default defineEvent("messageCreate", async (message) => {
|
|
if (message.author.bot)
|
|
return;
|
|
|
|
const guild = message.guild;
|
|
if (guild == null)
|
|
return;
|
|
|
|
const hasChannel = await hasGuildReadChannel(guild.id, message.channelId);
|
|
if (!hasChannel)
|
|
return;
|
|
|
|
const profile = await getUserProfile(message.author.id);
|
|
|
|
let content = message.cleanContent;
|
|
let voice: string | null = null
|
|
if (content.startsWith("$t ")) {
|
|
voice = "TypeCast"
|
|
} else if (content.startsWith("$p ")) {
|
|
voice = "Papago"
|
|
}
|
|
|
|
if (voice) {
|
|
content = content.replace(/^\$[^ ]+ +/, "")
|
|
} else {
|
|
voice = profile.voice;
|
|
}
|
|
|
|
try {
|
|
if (!await getOrCreateVoiceConnection(guild))
|
|
return;
|
|
|
|
if (!guild.members.me?.voice.channel)
|
|
return;
|
|
|
|
if (message.content === "") {
|
|
return await playVoice(
|
|
guild,
|
|
profile,
|
|
content =
|
|
message.attachments.size > 0
|
|
? `${message.attachments.size} 개의 첨부파일`
|
|
: "알수없는 메시지"
|
|
);
|
|
} else {
|
|
await content.split("\n").forEach(async text => {
|
|
await playVoice(
|
|
guild,
|
|
profile,
|
|
text
|
|
);
|
|
});
|
|
}
|
|
|
|
} catch(err) {
|
|
message.reply("말이 꼬이네요 ㅜ.ㅜ");
|
|
}
|
|
}) |