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/
|
db/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
database/
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -135,4 +135,5 @@ config.json
|
||||||
# database
|
# database
|
||||||
db/
|
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 (existsSync(absPnpApiPath)) {
|
||||||
if (!process.versions.pnp) {
|
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();
|
require(absPnpApiPath).setup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defer to the real prettier/index.js your application uses
|
// Defer to the real prettier your application uses
|
||||||
module.exports = absRequire(`prettier/index.js`);
|
module.exports = absRequire(`prettier`);
|
||||||
|
|
2
.yarn/sdks/prettier/package.json
vendored
2
.yarn/sdks/prettier/package.json
vendored
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "prettier",
|
"name": "prettier",
|
||||||
"version": "2.8.8-sdk",
|
"version": "3.0.3-sdk",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"type": "commonjs"
|
"type": "commonjs"
|
||||||
}
|
}
|
||||||
|
|
2
.yarn/sdks/typescript/package.json
vendored
2
.yarn/sdks/typescript/package.json
vendored
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "typescript",
|
"name": "typescript",
|
||||||
"version": "5.1.3-sdk",
|
"version": "5.2.2-sdk",
|
||||||
"main": "./lib/typescript.js",
|
"main": "./lib/typescript.js",
|
||||||
"type": "commonjs"
|
"type": "commonjs"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1 @@
|
||||||
plugins:
|
yarnPath: .yarn/releases/yarn-3.6.3.cjs
|
||||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
|
||||||
spec: "@yarnpkg/plugin-interactive-tools"
|
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-3.6.0.cjs
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:16.19.0
|
FROM node:18.17.1
|
||||||
RUN mkdir app
|
RUN mkdir app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
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",
|
"name": "muffin-ai-arujak",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"main": "dist/index.js",
|
||||||
"license": "MIT",
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.11.0",
|
"discord.js": "^14.13.0",
|
||||||
"dotenv": "^16.1.4",
|
"dotenv": "^16.3.1",
|
||||||
"mysql2": "^3.3.5"
|
"mysql2": "^3.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@migan/prettier-config": "^1.0.0",
|
"@migan/prettier-config": "^1.0.0",
|
||||||
"@types/jest": "^29.5.2",
|
"@types/node": "^20.6.3",
|
||||||
"@types/node": "^20.3.1",
|
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"jest": "^29.5.0",
|
"prettier": "^3.0.3",
|
||||||
"prettier": "^2.8.8",
|
|
||||||
"ts-jest": "^29.1.0",
|
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"tsup": "^6.7.0",
|
"tsup": "^7.2.0",
|
||||||
"typescript": "^5.1.3"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup",
|
"build": "tsup",
|
||||||
"dev": "cross-env NODE_ENV=development ts-node src",
|
"dev": "cross-env NODE_ENV=development ts-node src",
|
||||||
"start": "cross-env NODE_ENV=production node dist",
|
"start": "cross-env NODE_ENV=production node dist"
|
||||||
"test": "jest"
|
|
||||||
},
|
},
|
||||||
"prettier": "@migan/prettier-config",
|
"packageManager": "yarn@3.6.3",
|
||||||
"packageManager": "yarn@3.6.0"
|
"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', () => {
|
this.once('ready', () => {
|
||||||
console.log(
|
console.log(
|
||||||
`Build Number: ${execSync('git rev-parse --short HEAD').toString()}`
|
`Build Number: ${execSync('git rev-parse --short HEAD').toString()}`,
|
||||||
)
|
)
|
||||||
this.user!.setActivity({
|
this.user!.setActivity({
|
||||||
type: ActivityType.Playing,
|
type: ActivityType.Playing,
|
||||||
|
@ -78,11 +78,6 @@ export default class MuffinAI extends Client {
|
||||||
})
|
})
|
||||||
return super.login(config.bot.token)
|
return super.login(config.bot.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override destroy() {
|
|
||||||
this.chatBot.destroy()
|
|
||||||
super.destroy()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'discord.js' {
|
declare module 'discord.js' {
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default class ChatBot {
|
||||||
let response: string
|
let response: string
|
||||||
if ((msg.channel as TextChannel).nsfw) {
|
if ((msg.channel as TextChannel).nsfw) {
|
||||||
const [rows1] = await db.execute<ResponseData[]>(
|
const [rows1] = await db.execute<ResponseData[]>(
|
||||||
'SELECT * FROM nsfw_content;'
|
'SELECT * FROM nsfw_content;',
|
||||||
)
|
)
|
||||||
const rows2 = [...rows, ...rows1]
|
const rows2 = [...rows, ...rows1]
|
||||||
response = rows2[Math.floor(Math.random() * rows2.length)].text
|
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) {
|
if (msg.author.id === config.train.user_ID) {
|
||||||
const response = await this.getResponse(msg)
|
const response = await this.getResponse(msg)
|
||||||
const [rows] = await db.execute<ResponseData[]>(
|
const [rows] = await db.execute<ResponseData[]>(
|
||||||
'SELECT * FROM statement;'
|
'SELECT * FROM statement;',
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
await db.beginTransaction()
|
await db.beginTransaction()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
'INSERT INTO statement (id, text, persona, in_response_to) VALUES (?, ?, ?, ?);',
|
'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()
|
await db.commit()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -52,13 +52,13 @@ export default class ChatBot {
|
||||||
const user = `user:${msg.author.username.slice(0, 50).toLowerCase()}`
|
const user = `user:${msg.author.username.slice(0, 50).toLowerCase()}`
|
||||||
const text = msg.content.replace('머핀아 ', '')
|
const text = msg.content.replace('머핀아 ', '')
|
||||||
const [rows] = await db.execute<ResponseData[]>(
|
const [rows] = await db.execute<ResponseData[]>(
|
||||||
'SELECT * FROM nsfw_content;'
|
'SELECT * FROM nsfw_content;',
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
await db.beginTransaction()
|
await db.beginTransaction()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
`INSERT INTO nsfw_content (id, text, persona) VALUES (?, ?, ?);`,
|
`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()
|
await db.commit()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -70,8 +70,4 @@ export default class ChatBot {
|
||||||
db.release()
|
db.release()
|
||||||
return this
|
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,
|
clean: true,
|
||||||
format: ['cjs'],
|
format: ['cjs'],
|
||||||
entry: ['src/index.ts', 'src/Commands/*.ts'],
|
entry: ['src/index.ts', 'src/Commands/*.ts'],
|
||||||
minify: true,
|
// minify: true,
|
||||||
splitting: true,
|
// splitting: true,
|
||||||
})
|
})
|
||||||
|
|
11
update.sh
11
update.sh
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/sh
|
#!/usr/bin/sh
|
||||||
sudo docker stop maa
|
sudo docker compose stop
|
||||||
sudo docker rm maa
|
sudo docker compose rm -s -f
|
||||||
sudo docker rmi maa
|
sudo docker compose build
|
||||||
sudo docker build -t maa .
|
sudo docker compose up -d
|
||||||
sudo docker run -d --name maa maa
|
sudo docker compose logs -f
|
||||||
sudo docker logs -f maa
|
|
||||||
|
|
Loading…
Reference in a new issue