62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
import { EmbedBuilder } from 'discord.js';
|
|
import { getMetaData } from '../feature/utility.js'; // 메타데이터 추출 함수
|
|
|
|
export default async function messageCreateEvent(message) {
|
|
const badWords = ['권태웅', '태웅', '웅태'];
|
|
|
|
if (badWords.some(word => message.content.includes(word))) {
|
|
await message.channel.send('어허 나쁜말 쓰지 마세요');
|
|
}
|
|
|
|
|
|
// URL 감지 및 메타데이터 처리
|
|
const mobileUrlPattern = /https?:\/\/m\.dcinside\.com\/board\/[^\s]+/g;
|
|
const normalUrlPattern = /https?:\/\/gall\.dcinside\.com\/mgallery\/board\/view\/\?id=[^&]+&no=\d+/g;
|
|
|
|
const mobileUrls = message.content.match(mobileUrlPattern);
|
|
const normalUrls = message.content.match(normalUrlPattern);
|
|
|
|
// 모바일 URL 처리
|
|
if (mobileUrls && mobileUrls.length > 0) {
|
|
try {
|
|
const metaData = await getMetaData(mobileUrls[0]); // 첫 번째 모바일 URL 메타데이터 추출
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x0099FF)
|
|
.setTitle(metaData.title || '제목 없음')
|
|
.setURL(mobileUrls[0])
|
|
.setDescription(metaData.description || '설명 없음');
|
|
|
|
if (metaData.image) {
|
|
embed.setImage(metaData.image);
|
|
}
|
|
|
|
await message.channel.send({ embeds: [embed] });
|
|
} catch (error) {
|
|
console.error('모바일 URL 메타데이터 처리 중 오류:', error.message);
|
|
await message.channel.send('모바일 URL에서 메타데이터를 가져오는 중 오류가 발생했습니다.');
|
|
}
|
|
}
|
|
|
|
// 갤러리 URL 처리
|
|
if (normalUrls && normalUrls.length > 0) {
|
|
try {
|
|
const metaData = await getMetaData(normalUrls[0]); // 첫 번째 갤러리 URL 메타데이터 추출
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x0099FF)
|
|
.setTitle(metaData.title || '제목 없음')
|
|
.setURL(normalUrls[0])
|
|
.setDescription(metaData.description || '설명 없음');
|
|
|
|
if (metaData.image) {
|
|
embed.setImage(metaData.image);
|
|
}
|
|
|
|
await message.channel.send({ embeds: [embed] });
|
|
} catch (error) {
|
|
console.error('갤러리 URL 메타데이터 처리 중 오류:', error.message);
|
|
await message.channel.send('갤러리 URL에서 메타데이터를 가져오는 중 오류가 발생했습니다.');
|
|
}
|
|
}
|
|
} |