feat: rewrite finish learnData
This commit is contained in:
parent
3c2bc0f238
commit
177527fcc0
6 changed files with 83 additions and 62 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "muffinbot",
|
"name": "muffinbot",
|
||||||
"version": "3.0.0-cake.d240624a",
|
"version": "3.0.0-cake.d240624b",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -19,27 +19,22 @@ import { type LearnData } from '../modules'
|
||||||
})
|
})
|
||||||
export default class extends Command {
|
export default class extends Command {
|
||||||
public async messageRun(msg: Message, args: Args) {
|
public async messageRun(msg: Message, args: Args) {
|
||||||
const db = this.container.database
|
|
||||||
const command = await args.rest('string').catch(() => null)
|
const command = await args.rest('string').catch(() => null)
|
||||||
|
const options: SelectMenuComponentOptionData[] = []
|
||||||
if (!command) {
|
const db = this.container.database
|
||||||
return await msg.channel.send('사용법: \n```머핀아 삭제 (지울 단어)```')
|
|
||||||
}
|
|
||||||
|
|
||||||
const [datas] = await db.database.execute<LearnData[]>(
|
const [datas] = await db.database.execute<LearnData[]>(
|
||||||
'SELECT * FROM learn WHERE command = ? AND user_id = ?;',
|
'SELECT * FROM learn WHERE command = ? AND user_id = ?;',
|
||||||
[command, msg.author.id],
|
[command, msg.author.id],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
return await msg.channel.send('사용법: \n```머핀아 삭제 (지울 단어)```')
|
||||||
|
}
|
||||||
|
|
||||||
if (!datas) {
|
if (!datas) {
|
||||||
return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
|
return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(datas.length)
|
|
||||||
|
|
||||||
if (datas.length > 1) {
|
|
||||||
const options: SelectMenuComponentOptionData[] = []
|
|
||||||
|
|
||||||
datas.forEach(data => {
|
datas.forEach(data => {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
options.push({
|
options.push({
|
||||||
|
@ -74,19 +69,5 @@ export default class extends Command {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
// await db.learn.delete(command)
|
|
||||||
// await msg.reply('어라 이제 그ㄱ게 기억이 안나요. 그게 뭐ㅇ였죠?')
|
|
||||||
console.log('b')
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (data[0].user_id !== msg.author.id) {
|
|
||||||
// return await msg.channel.send(
|
|
||||||
// '어라 당ㅅ신은 언제 가르쳐 주셨죠?',
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// await db.learn.delete(command)
|
|
||||||
// await msg.reply('어라 이제 그ㄱ게 기억이 안나요.')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
36
src/interaction-handlers/deleteLearn.ts
Normal file
36
src/interaction-handlers/deleteLearn.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import {
|
||||||
|
InteractionHandler,
|
||||||
|
InteractionHandlerTypes,
|
||||||
|
} from '@sapphire/framework'
|
||||||
|
import { type StringSelectMenuInteraction } from 'discord.js'
|
||||||
|
import { ApplyOptions } from '@sapphire/decorators'
|
||||||
|
|
||||||
|
@ApplyOptions<InteractionHandler.Options>({
|
||||||
|
interactionHandlerType: InteractionHandlerTypes.SelectMenu,
|
||||||
|
})
|
||||||
|
export default class extends InteractionHandler {
|
||||||
|
public async parse(interaction: StringSelectMenuInteraction) {
|
||||||
|
if (interaction.customId !== 'maa$deleteLearn') return this.none()
|
||||||
|
return this.some()
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(interaction: StringSelectMenuInteraction) {
|
||||||
|
await interaction.deferUpdate()
|
||||||
|
|
||||||
|
const id = interaction.values[0].slice('maa$deleteLearn-'.length)
|
||||||
|
const db = this.container.database
|
||||||
|
|
||||||
|
await db.learn.delete(id)
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: '삭제',
|
||||||
|
description: `${id}번을 정상적으로 삭제하ㅇ였어요.`,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
components: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,9 @@
|
||||||
import { LearnTable, NSFWContentTable, StatementTable } from './model'
|
import { LearnTable, NSFWContentTable, StatementTable } from './model'
|
||||||
import { createPool, type QueryResult } from 'mysql2/promise'
|
import { createPool, type QueryResult } from 'mysql2/promise'
|
||||||
import { container } from '@sapphire/framework'
|
import { container } from '@sapphire/framework'
|
||||||
import run from './run'
|
|
||||||
|
|
||||||
export class MaaDatabase {
|
export class MaaDatabase {
|
||||||
public database = createPool({
|
public readonly database = createPool({
|
||||||
...container.config.mysql,
|
...container.config.mysql,
|
||||||
keepAliveInitialDelay: 10000,
|
keepAliveInitialDelay: 10000,
|
||||||
enableKeepAlive: true,
|
enableKeepAlive: true,
|
||||||
|
|
|
@ -55,7 +55,7 @@ export class LearnTable implements BaseTable<LearnData, string> {
|
||||||
const db = await this._database.getConnection()
|
const db = await this._database.getConnection()
|
||||||
|
|
||||||
await run(db, async () => {
|
await run(db, async () => {
|
||||||
await db.execute('DELETE FROM learn WHERE command = ?;', [key])
|
await db.execute('DELETE FROM learn WHERE id = ?;', [key])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,12 @@ const sourcemap = process.env.NODE_ENV === 'development' ? true : false
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
clean: true,
|
clean: true,
|
||||||
format: ['cjs'],
|
format: ['cjs'],
|
||||||
entry: ['src/index.ts', 'src/commands/*.ts', 'src/listeners/*.ts'],
|
entry: [
|
||||||
|
'src/index.ts',
|
||||||
|
'src/Commands/*.ts',
|
||||||
|
'src/listeners/*.ts',
|
||||||
|
'src/interaction-handlers/*.ts',
|
||||||
|
],
|
||||||
minify: true,
|
minify: true,
|
||||||
sourcemap,
|
sourcemap,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue