diff --git a/.pnp.cjs b/.pnp.cjs index a89c12c..b6802a3 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -52,6 +52,7 @@ const RAW_RUNTIME_STATE = ["ts-node", "virtual:df417fa6ed58592061b3cdd25305c567cb83e355f566a3f712cecb8d4e6c4814c3ed842a030a9c3a51e2de30e93ecf82143ea19accc29756c7a7ac08166c7416#npm:10.9.2"],\ ["tsup", "virtual:df417fa6ed58592061b3cdd25305c567cb83e355f566a3f712cecb8d4e6c4814c3ed842a030a9c3a51e2de30e93ecf82143ea19accc29756c7a7ac08166c7416#npm:8.1.0"],\ ["typescript", "patch:typescript@npm%3A5.5.2#optional!builtin::version=5.5.2&hash=379a07"],\ + ["undici", "npm:6.19.2"],\ ["ws", "virtual:df417fa6ed58592061b3cdd25305c567cb83e355f566a3f712cecb8d4e6c4814c3ed842a030a9c3a51e2de30e93ecf82143ea19accc29756c7a7ac08166c7416#npm:8.17.1"]\ ],\ "linkType": "SOFT"\ @@ -2948,6 +2949,7 @@ const RAW_RUNTIME_STATE = ["ts-node", "virtual:df417fa6ed58592061b3cdd25305c567cb83e355f566a3f712cecb8d4e6c4814c3ed842a030a9c3a51e2de30e93ecf82143ea19accc29756c7a7ac08166c7416#npm:10.9.2"],\ ["tsup", "virtual:df417fa6ed58592061b3cdd25305c567cb83e355f566a3f712cecb8d4e6c4814c3ed842a030a9c3a51e2de30e93ecf82143ea19accc29756c7a7ac08166c7416#npm:8.1.0"],\ ["typescript", "patch:typescript@npm%3A5.5.2#optional!builtin::version=5.5.2&hash=379a07"],\ + ["undici", "npm:6.19.2"],\ ["ws", "virtual:df417fa6ed58592061b3cdd25305c567cb83e355f566a3f712cecb8d4e6c4814c3ed842a030a9c3a51e2de30e93ecf82143ea19accc29756c7a7ac08166c7416#npm:8.17.1"]\ ],\ "linkType": "SOFT"\ @@ -3890,6 +3892,13 @@ const RAW_RUNTIME_STATE = ["undici", "npm:6.13.0"]\ ],\ "linkType": "HARD"\ + }],\ + ["npm:6.19.2", {\ + "packageLocation": "./.yarn/cache/undici-npm-6.19.2-a9aa1269bb-f4895c0c1e.zip/node_modules/undici/",\ + "packageDependencies": [\ + ["undici", "npm:6.19.2"]\ + ],\ + "linkType": "HARD"\ }]\ ]],\ ["undici-types", [\ diff --git a/.yarn/cache/undici-npm-6.19.2-a9aa1269bb-f4895c0c1e.zip b/.yarn/cache/undici-npm-6.19.2-a9aa1269bb-f4895c0c1e.zip new file mode 100644 index 0000000..235c2c6 Binary files /dev/null and b/.yarn/cache/undici-npm-6.19.2-a9aa1269bb-f4895c0c1e.zip differ diff --git a/config.example.json b/config.example.json index 1e1a924..374f33b 100644 --- a/config.example.json +++ b/config.example.json @@ -13,5 +13,8 @@ "password": "", "database": "", "port": 3306 + }, + "api": { + "opendict": "" } } diff --git a/package.json b/package.json index d2fe388..fa7926b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "3.0.0-cake.d240626b", + "version": "3.0.0-cake.d240713a", "main": "dist/index.js", "private": true, "dependencies": { @@ -13,6 +13,7 @@ "discord.js": "^14.15.3", "dokdo": "^0.6.2", "mysql2": "^3.10.1", + "undici": "^6.19.2", "ws": "^8.17.1" }, "devDependencies": { diff --git a/src/Client.ts b/src/Client.ts index a5e1eb2..16a8726 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,5 +1,5 @@ import { SapphireClient, container, LogLevel } from '@sapphire/framework' -import { GatewayIntentBits, type Snowflake } from 'discord.js' +import { GatewayIntentBits, Partials, type Snowflake } from 'discord.js' import { ChatBot, NODE_ENV, MaaDatabase } from './modules' import { version } from '../package.json' import config from '../config.json' @@ -26,9 +26,9 @@ export default class MuffinBot extends SapphireClient { }, allowedMentions: { roles: [], - users: [], repliedUser: true, }, + partials: [Partials.Message, Partials.ThreadMember], }) } @@ -60,6 +60,9 @@ declare module '@sapphire/pieces' { database: string port: number } + api: { + opendict: string + } } } } diff --git a/src/Commands/wordRelay.ts b/src/Commands/wordRelay.ts new file mode 100644 index 0000000..997d1b5 --- /dev/null +++ b/src/Commands/wordRelay.ts @@ -0,0 +1,25 @@ +import { type Message, PermissionFlagsBits } from 'discord.js' +import { ApplyOptions } from '@sapphire/decorators' +import { Command } from '@sapphire/framework' +import { WordRelay } from '../modules' + +@ApplyOptions({ + name: '끝말잇기', + aliases: ['끄투', '끄투리오'], + description: '머핀봇이랑 끝말잇기를 해보ㅅ세요.', + detailedDescription: { + usage: '머핀아 끝말잇기' + } +}) +export default class extends Command { + public async messageRun(msg: Message) { + if ( + !msg.guild.members.me?.permissions.has( + PermissionFlagsBits.CreatePublicThreads, + ) + ) + return msg.reply('제게 공개 스레드 만들기 권한ㅇ이 없어요.') + + new WordRelay().startGame(msg) + } +} diff --git a/src/modules/index.ts b/src/modules/index.ts index 4b4de0a..21e3f02 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -1,13 +1,16 @@ -import ChatBot from './ChatBot' import { ResponseData, NSFWData, LearnData, MaaDatabase } from './database' -import noPerm from './noPerm' +import { WordRelay } from './wordRelay' import { NODE_ENV } from './env' +import ChatBot from './ChatBot' +import noPerm from './noPerm' + export { - ChatBot, - noPerm, ResponseData, - NODE_ENV, - NSFWData, - LearnData, MaaDatabase, + LearnData, + WordRelay, + NODE_ENV, + ChatBot, + NSFWData, + noPerm, } diff --git a/src/modules/wordRelay.ts b/src/modules/wordRelay.ts index bea4b91..1133b99 100644 --- a/src/modules/wordRelay.ts +++ b/src/modules/wordRelay.ts @@ -1,12 +1,72 @@ -import { type Message, PermissionFlagsBits } from 'discord.js' +import { container } from '@sapphire/framework' +import { type Message } from 'discord.js' +import { request } from 'undici' export class WordRelay { - public async startGame(msg: Message) { - if ( - msg.guild.members.me?.permissions.has( - PermissionFlagsBits.CreatePublicThreads, - ) - ) - return msg.reply('제게 공개 스레드 만들기 권한ㅇ이 없어요.') + private _url = 'https://opendict.korean.go.kr/api/search' + private _usedWords: string[] = [] + + public async validWord(word: string): Promise { + const res: any = await request(`${this._url}`, { + query: { + key: container.config.api.opendict, + req_type: 'json', + advanced: 'y', + type1: 'all', + type3: 'general', + q: word, + }, + }).then(res => res.body.json()) + + if (res.channel.total === 0) return true + else return false } + + public startGame(msg: Message) { + /** + * @description MAAWRCollected: Muffin Ai Arujak(MAA) Collected + */ + const MAAWR_COLLECTED = 'MAAWRCollected' + const userID = msg.author.id + + try { + msg + .startThread({ + name: `${container.client.user?.username}-끝말잇기`, + }) + .then(thread => { + thread.send( + `<@${userID}>님, 여기 들어와서 시작단어를ㄹ 60초안에 입력해주세요!`, + ) + + const collector = thread.createMessageCollector({ + filter: message => message.author.id === userID, + time: 60_000, + }) + + collector + .on('collect', async message => { + if (await this.validWord(message.content)) { + collector.stop(MAAWR_COLLECTED) + } else { + await message.reply( + '해당 단어는 일치하지 않아요. 다시 한ㅂ번 입력해주세요.', + ) + } + }) + .on('end', (collected, reason) => { + if (reason === 'time') { + thread.send( + `<@${userID}>님, 60초동안 시작단어를 입력하지 않아 자동ㅇ으로 게임이 종료되었어요.`, + ) + } else if (reason === MAAWR_COLLECTED) { + } + }) + }) + } catch (err) { + console.log(err) + } + } + + public getWord() {} } diff --git a/yarn.lock b/yarn.lock index d488d6d..714a094 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2420,6 +2420,7 @@ __metadata: ts-node: "npm:^10.9.2" tsup: "npm:^8.1.0" typescript: "npm:^5.5.2" + undici: "npm:^6.19.2" ws: "npm:^8.17.1" languageName: unknown linkType: soft @@ -3270,6 +3271,13 @@ __metadata: languageName: node linkType: hard +"undici@npm:^6.19.2": + version: 6.19.2 + resolution: "undici@npm:6.19.2" + checksum: 10/f4895c0c1e2fcde18076ac98965c231875811b8e14ceab1a7b19e940ed1a2fce69e0864e1186bfdc9347dffe0f39a00daf6dd5e7c0169b2b33de59a859dc2f1d + languageName: node + linkType: hard + "unique-filename@npm:^3.0.0": version: 3.0.0 resolution: "unique-filename@npm:3.0.0"