feature: initial commit word relay

This commit is contained in:
Siwoo Jeon 2024-07-13 21:17:24 +09:00
parent 69613e4d39
commit 84e1b93496
Signed by: migan
GPG key ID: C4151385FFD2082A
9 changed files with 130 additions and 18 deletions

9
.pnp.cjs generated
View file

@ -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<compat/typescript>::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<compat/typescript>::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", [\

Binary file not shown.

View file

@ -13,5 +13,8 @@
"password": "",
"database": "",
"port": 3306
},
"api": {
"opendict": ""
}
}

View file

@ -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": {

View file

@ -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
}
}
}
}

25
src/Commands/wordRelay.ts Normal file
View file

@ -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<Command.Options>({
name: '끝말잇기',
aliases: ['끄투', '끄투리오'],
description: '머핀봇이랑 끝말잇기를 해보ㅅ세요.',
detailedDescription: {
usage: '머핀아 끝말잇기'
}
})
export default class extends Command {
public async messageRun(msg: Message<true>) {
if (
!msg.guild.members.me?.permissions.has(
PermissionFlagsBits.CreatePublicThreads,
)
)
return msg.reply('제게 공개 스레드 만들기 권한ㅇ이 없어요.')
new WordRelay().startGame(msg)
}
}

View file

@ -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,
}

View file

@ -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<true>) {
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<boolean> {
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<true>) {
/**
* @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() {}
}

View file

@ -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"