feat: docker compose
This commit is contained in:
parent
30986abb3c
commit
3da05a22f8
19 changed files with 640 additions and 3752 deletions
|
@ -1,2 +1,3 @@
|
|||
db/
|
||||
node_modules/
|
||||
node_modules/
|
||||
database/
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -135,4 +135,5 @@ config.json
|
|||
# database
|
||||
db/
|
||||
|
||||
.idea
|
||||
.idea/
|
||||
database/
|
541
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
541
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
6
.yarn/sdks/prettier/index.js
vendored
6
.yarn/sdks/prettier/index.js
vendored
|
@ -11,10 +11,10 @@ const absRequire = createRequire(absPnpApiPath);
|
|||
|
||||
if (existsSync(absPnpApiPath)) {
|
||||
if (!process.versions.pnp) {
|
||||
// Setup the environment to be able to require prettier/index.js
|
||||
// Setup the environment to be able to require prettier
|
||||
require(absPnpApiPath).setup();
|
||||
}
|
||||
}
|
||||
|
||||
// Defer to the real prettier/index.js your application uses
|
||||
module.exports = absRequire(`prettier/index.js`);
|
||||
// Defer to the real prettier your application uses
|
||||
module.exports = absRequire(`prettier`);
|
||||
|
|
2
.yarn/sdks/prettier/package.json
vendored
2
.yarn/sdks/prettier/package.json
vendored
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "prettier",
|
||||
"version": "2.8.8-sdk",
|
||||
"version": "3.0.3-sdk",
|
||||
"main": "./index.js",
|
||||
"type": "commonjs"
|
||||
}
|
||||
|
|
2
.yarn/sdks/typescript/package.json
vendored
2
.yarn/sdks/typescript/package.json
vendored
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "typescript",
|
||||
"version": "5.1.3-sdk",
|
||||
"version": "5.2.2-sdk",
|
||||
"main": "./lib/typescript.js",
|
||||
"type": "commonjs"
|
||||
}
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.6.0.cjs
|
||||
yarnPath: .yarn/releases/yarn-3.6.3.cjs
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM node:16.19.0
|
||||
FROM node:18.17.1
|
||||
RUN mkdir app
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
|
25
docker-compose.yml
Normal file
25
docker-compose.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
database:
|
||||
container_name: "muffin_database"
|
||||
image: mariadb:10.9.4
|
||||
volumes:
|
||||
- "./database/:/var/lib/mysql"
|
||||
- "/etc/localtime:/etc/localtime"
|
||||
- "./scripts/:/docker-entrypoint-initdb.d/"
|
||||
ports:
|
||||
- "1502:3306"
|
||||
env_file:
|
||||
- "./.env"
|
||||
networks:
|
||||
- muffin_ai
|
||||
discord_bot:
|
||||
container_name: "maa"
|
||||
build: "."
|
||||
networks:
|
||||
- muffin_ai
|
||||
|
||||
networks:
|
||||
muffin_ai:
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
28
package.json
28
package.json
|
@ -1,31 +1,27 @@
|
|||
{
|
||||
"name": "muffin-ai-arujak",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"discord.js": "^14.11.0",
|
||||
"dotenv": "^16.1.4",
|
||||
"mysql2": "^3.3.5"
|
||||
"discord.js": "^14.13.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"mysql2": "^3.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@migan/prettier-config": "^1.0.0",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/node": "^20.6.3",
|
||||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-jest": "^29.1.0",
|
||||
"prettier": "^3.0.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsup": "^6.7.0",
|
||||
"typescript": "^5.1.3"
|
||||
"tsup": "^7.2.0",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "cross-env NODE_ENV=development ts-node src",
|
||||
"start": "cross-env NODE_ENV=production node dist",
|
||||
"test": "jest"
|
||||
"start": "cross-env NODE_ENV=production node dist"
|
||||
},
|
||||
"prettier": "@migan/prettier-config",
|
||||
"packageManager": "yarn@3.6.0"
|
||||
"packageManager": "yarn@3.6.3",
|
||||
"prettier": "@migan/prettier-config"
|
||||
}
|
||||
|
|
21
scripts/create_table.sql
Executable file
21
scripts/create_table.sql
Executable file
|
@ -0,0 +1,21 @@
|
|||
CREATE TABLE
|
||||
`statement` (
|
||||
`id` int(11) NOT NULL,
|
||||
`text` varchar(255) DEFAULT NULL,
|
||||
`search_text` varchar(255) NOT NULL DEFAULT '',
|
||||
`conversation` varchar(32) NOT NULL DEFAULT '',
|
||||
`created_at` datetime DEFAULT current_timestamp(),
|
||||
`in_response_to` varchar(255) DEFAULT NULL,
|
||||
`search_in_response_to` varchar(255) NOT NULL DEFAULT '',
|
||||
`persona` varchar(50) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
`nsfw_content` (
|
||||
`id` int(11) NOT NULL,
|
||||
`text` varchar(255) NOT NULL DEFAULT '',
|
||||
`created_at` datetime DEFAULT current_timestamp(),
|
||||
`persona` varchar(50) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
|
@ -42,7 +42,7 @@ export default class MuffinAI extends Client {
|
|||
|
||||
this.once('ready', () => {
|
||||
console.log(
|
||||
`Build Number: ${execSync('git rev-parse --short HEAD').toString()}`
|
||||
`Build Number: ${execSync('git rev-parse --short HEAD').toString()}`,
|
||||
)
|
||||
this.user!.setActivity({
|
||||
type: ActivityType.Playing,
|
||||
|
@ -78,11 +78,6 @@ export default class MuffinAI extends Client {
|
|||
})
|
||||
return super.login(config.bot.token)
|
||||
}
|
||||
|
||||
public override destroy() {
|
||||
this.chatBot.destroy()
|
||||
super.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'discord.js' {
|
||||
|
|
|
@ -14,7 +14,7 @@ export default class ChatBot {
|
|||
let response: string
|
||||
if ((msg.channel as TextChannel).nsfw) {
|
||||
const [rows1] = await db.execute<ResponseData[]>(
|
||||
'SELECT * FROM nsfw_content;'
|
||||
'SELECT * FROM nsfw_content;',
|
||||
)
|
||||
const rows2 = [...rows, ...rows1]
|
||||
response = rows2[Math.floor(Math.random() * rows2.length)].text
|
||||
|
@ -33,13 +33,13 @@ export default class ChatBot {
|
|||
if (msg.author.id === config.train.user_ID) {
|
||||
const response = await this.getResponse(msg)
|
||||
const [rows] = await db.execute<ResponseData[]>(
|
||||
'SELECT * FROM statement;'
|
||||
'SELECT * FROM statement;',
|
||||
)
|
||||
try {
|
||||
await db.beginTransaction()
|
||||
await db.execute(
|
||||
'INSERT INTO statement (id, text, persona, in_response_to) VALUES (?, ?, ?, ?);',
|
||||
[++rows[rows.length - 1].id, msg.content, 'muffin', response]
|
||||
[++rows[rows.length - 1].id, msg.content, 'muffin', response],
|
||||
)
|
||||
await db.commit()
|
||||
} catch (err) {
|
||||
|
@ -52,13 +52,13 @@ export default class ChatBot {
|
|||
const user = `user:${msg.author.username.slice(0, 50).toLowerCase()}`
|
||||
const text = msg.content.replace('머핀아 ', '')
|
||||
const [rows] = await db.execute<ResponseData[]>(
|
||||
'SELECT * FROM nsfw_content;'
|
||||
'SELECT * FROM nsfw_content;',
|
||||
)
|
||||
try {
|
||||
await db.beginTransaction()
|
||||
await db.execute(
|
||||
`INSERT INTO nsfw_content (id, text, persona) VALUES (?, ?, ?);`,
|
||||
[++rows[rows.length - 1].id, text, user]
|
||||
[++rows[rows.length - 1].id, text, user],
|
||||
)
|
||||
await db.commit()
|
||||
} catch (err) {
|
||||
|
@ -70,8 +70,4 @@ export default class ChatBot {
|
|||
db.release()
|
||||
return this
|
||||
}
|
||||
|
||||
public async destroy() {
|
||||
this.db.end()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
import { database, config } from '../src/modules'
|
||||
import { createConnection } from 'mysql2/promise'
|
||||
|
||||
describe('test database system', () => {
|
||||
test('Validate rows', async () => {
|
||||
return database.then(async conn1 => {
|
||||
const [rows1] = await conn1.execute('SELECT * FROM statement;')
|
||||
const conn2 = await createConnection(config)
|
||||
const [rows2] = await conn2.execute(`SELECT * FROM statement;`)
|
||||
expect(rows1).toEqual(rows2)
|
||||
})
|
||||
})
|
||||
})
|
|
@ -4,6 +4,6 @@ export default defineConfig({
|
|||
clean: true,
|
||||
format: ['cjs'],
|
||||
entry: ['src/index.ts', 'src/Commands/*.ts'],
|
||||
minify: true,
|
||||
splitting: true,
|
||||
// minify: true,
|
||||
// splitting: true,
|
||||
})
|
||||
|
|
11
update.sh
11
update.sh
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/sh
|
||||
sudo docker stop maa
|
||||
sudo docker rm maa
|
||||
sudo docker rmi maa
|
||||
sudo docker build -t maa .
|
||||
sudo docker run -d --name maa maa
|
||||
sudo docker logs -f maa
|
||||
sudo docker compose stop
|
||||
sudo docker compose rm -s -f
|
||||
sudo docker compose build
|
||||
sudo docker compose up -d
|
||||
sudo docker compose logs -f
|
||||
|
|
Loading…
Reference in a new issue