feat: 유저가 한말 DB에 저장
This commit is contained in:
parent
f7b666c5b3
commit
889e4b7081
7 changed files with 31 additions and 23 deletions
|
@ -3,7 +3,9 @@
|
|||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"array-shuffle": "^3.0.0",
|
||||
"discord.js": "^14.7.1",
|
||||
"dotenv": "^16.0.3",
|
||||
"sqlite3": "^5.1.4"
|
||||
|
@ -18,7 +20,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "ts-node src",
|
||||
"dev": "ts-node-esm src",
|
||||
"start": "node dist"
|
||||
},
|
||||
"prettier": "@migan/prettier-config"
|
||||
|
|
|
@ -1,19 +1,7 @@
|
|||
import sqlite3 from 'sqlite3'
|
||||
import { ResponseData } from './types'
|
||||
import { ResponseData } from './types.js'
|
||||
import type { Client, Message } from 'discord.js'
|
||||
|
||||
function arrayShuffle<T>(array: T[]): T[] {
|
||||
array = [...array]
|
||||
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1))
|
||||
const temp = array[i]
|
||||
array[i] = array[j]
|
||||
array[j] = temp
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
||||
import arrayShuffle from 'array-shuffle'
|
||||
|
||||
export default class ChatBot {
|
||||
private db: sqlite3.Database
|
||||
|
@ -40,6 +28,7 @@ export default class ChatBot {
|
|||
|
||||
public train(client: Client): ChatBot {
|
||||
client.on('messageCreate', msg => {
|
||||
if (msg.author.bot) return
|
||||
if (msg.author.id === '1026185545837191238') {
|
||||
this.db.run(
|
||||
`INSERT INTO statement(text) VALUES('${msg.content}');`,
|
||||
|
@ -48,9 +37,17 @@ export default class ChatBot {
|
|||
this.getResponse(msg)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
if (!msg.content.startsWith('머핀아 ')) return
|
||||
const sql = `INSERT INTO statement(text) VALUES('${msg.content.replace(
|
||||
'머핀아 ',
|
||||
''
|
||||
)}')`
|
||||
this.db.run(sql, err => {
|
||||
if (err) throw err
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import { ActivityType, Client, GatewayIntentBits } from 'discord.js'
|
||||
import ChatBot from './ChatBot'
|
||||
import { join } from 'node:path'
|
||||
import ChatBot from './ChatBot.js'
|
||||
import { join, dirname } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import 'dotenv/config'
|
||||
|
||||
export default class MuffinAI extends Client {
|
||||
private chatBot = new ChatBot(join(__dirname, '..', 'db', 'db.sqlite3'))
|
||||
private chatBot = new ChatBot(
|
||||
join(dirname(fileURLToPath(import.meta.url)), '..', 'db', 'db.sqlite3')
|
||||
)
|
||||
public constructor() {
|
||||
super({
|
||||
intents: [
|
||||
|
|
|
@ -1 +1 @@
|
|||
import('./Client').then(a => new a.default().login())
|
||||
import('./Client.js').then(a => new a.default().login())
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs",
|
||||
"module": "Node16",
|
||||
/* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
"moduleResolution": "Node16", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
|
|
|
@ -2,7 +2,8 @@ import { defineConfig } from 'tsup'
|
|||
|
||||
export default defineConfig({
|
||||
clean: true,
|
||||
format: ['cjs'],
|
||||
format: ['esm'],
|
||||
entry: ['src/index.ts'],
|
||||
minify: true,
|
||||
splitting: true,
|
||||
})
|
||||
|
|
|
@ -278,6 +278,11 @@ arg@^4.1.0:
|
|||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
||||
|
||||
array-shuffle@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/array-shuffle/-/array-shuffle-3.0.0.tgz#9a927cc2ca4c8ef4d71cddef7c9ee7b3b733d54b"
|
||||
integrity sha512-rogEGxHOQPhslOhpg12LJkB+bbAl484/s2AJq0BxtzQDQfKl76fS2u9zWgg3p3b9ENcuvE7K8A7l5ddiPjCRnw==
|
||||
|
||||
array-union@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
|
||||
|
|
Loading…
Reference in a new issue