From 8d1550367c51b98e222ffa264b8414ebf59bce39 Mon Sep 17 00:00:00 2001 From: Kou-Ro Date: Mon, 12 Jun 2023 18:46:30 +0900 Subject: [PATCH 1/7] Copy db.js and environmentConfig.js from bot-main --- .gitignore | 5 +- environmentConfig.js | 8 + functions/db.js | 75 ++++++++++ package-lock.json | 340 ++++++++++++++++++++++++++++++++++++++++++- package.json | 6 +- 5 files changed, 431 insertions(+), 3 deletions(-) create mode 100644 environmentConfig.js create mode 100644 functions/db.js diff --git a/.gitignore b/.gitignore index 6f677ef..47b020b 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,7 @@ dist .pnp.* # JetBrains -.idea/ \ No newline at end of file +.idea/ + +config.json +config.dev.json \ No newline at end of file diff --git a/environmentConfig.js b/environmentConfig.js new file mode 100644 index 0000000..e6e9ea4 --- /dev/null +++ b/environmentConfig.js @@ -0,0 +1,8 @@ +const Path = require("path"); +const configPath = Path.resolve( + __dirname, + process.argv[2] === "run" ? "./config.json" : "./config.dev.json" +); +const config = require(configPath); +module.exports = config; +module.exports.configPath = configPath; diff --git a/functions/db.js b/functions/db.js new file mode 100644 index 0000000..b9068e2 --- /dev/null +++ b/functions/db.js @@ -0,0 +1,75 @@ +const { MongoClient, ServerApiVersion } = require("mongodb"); +const config = require('../environmentConfig') +const dbClient = new MongoClient(config.db, { serverApi: ServerApiVersion.v1 }); + +/*** + * データベースからデータを取得する + * @param dbName 取得先データベース名 + * @param collectionName 取得先コレクション名 + * @param filter フィルターを指定 + * @returns Array型 + */ +exports.find = async function (dbName, collectionName, filter) { + const collection = dbClient.db(dbName).collection(collectionName); + + return await collection.find(filter).toArray() +} + +/*** + * データベースを更新する + * @param dbName 更新先データベース名 + * @param collectionName 更新先コレクション名 + * @param filter 更新対象のフィルターを指定 + * @param update update operatorを用いた更新内容の記述 + */ +exports.update = async function run(dbName, collectionName, filter, update) { + try { + const database = dbClient.db(dbName); + const collection = database.collection(collectionName); + + const result = await collection.updateOne(filter,update) + await console.log(`${dbName}.${collectionName}を更新`,`DB更新実行`); + } catch(err) { + await console.error(`${dbName}.${collectionName}を更新できませんでした`,err,`DB更新失敗`); + } +} + + +/*** + * データベースにレコードを追加する + * @param dbName 追加先データベース名 + * @param collectionName 追加先コレクション名 + * @param object 追加するレコード(オブジェクト型) + */ +exports.insert = async function run(dbName, collectionName, object) { + + try { + const database = dbClient.db(dbName); + const collection = database.collection(collectionName); + + const result = await collection.insertOne(object); + await console.log(`${dbName}.${collectionName}にレコード追加`,`DB追加実行`); + } catch(err) { + await console.error(`${dbName}.${collectionName}にレコードを追加できませんでした`,err,`DB追加失敗`); + } +} +/*** + * データベースにレコードを削除する + * @param dbName 削除元データベース名 + * @param collectionName 削除元コレクション名 + * @param filter 削除対象のフィルターを指定 + */ +exports.delete = async function run(dbName,collectionName,filter) { + + try { + const database = dbClient.db(dbName); + const collection = database.collection(collectionName); + + const result = await collection.deleteOne(filter); + await console.log(`${dbName}.${collectionName}からレコード削除`,`DBレコード削除実行`); + } catch(err) { + await console.error(`${dbName}.${collectionName}からレコードを削除できませんでした`,err,`DB削除失敗`); + } +} + +//引数の詳細については、mongodbの公式ドキュメントを参照すること diff --git a/package-lock.json b/package-lock.json index c726b27..865f5ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,345 @@ "": { "name": "updatesystem", "version": "0.0.0", - "license": "ISC" + "license": "ISC", + "dependencies": { + "mongodb": "^5.6.0", + "path": "^0.12.7" + } + }, + "node_modules/@types/node": { + "version": "20.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.0.tgz", + "integrity": "sha512-cumHmIAf6On83X7yP+LrsEyUOf/YlociZelmpRYaGFydoaPdxdt80MAbu6vWerQT2COCp2nPvHdsbD7tHn/YlQ==" + }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==" + }, + "node_modules/@types/whatwg-url": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz", + "integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==", + "dependencies": { + "@types/node": "*", + "@types/webidl-conversions": "*" + } + }, + "node_modules/bson": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-5.3.0.tgz", + "integrity": "sha512-ukmCZMneMlaC5ebPHXIkP8YJzNl5DC41N5MAIvKDqLggdao342t4McltoJBQfQya/nHBWAcSsYRqlXPoQkTJag==", + "engines": { + "node": ">=14.20.1" + } + }, + "node_modules/inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" + }, + "node_modules/ip": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", + "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==" + }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "optional": true + }, + "node_modules/mongodb": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-5.6.0.tgz", + "integrity": "sha512-z8qVs9NfobHJm6uzK56XBZF8XwM9H294iRnB7wNjF0SnY93si5HPziIJn+qqvUR5QOff/4L0gCD6SShdR/GtVQ==", + "dependencies": { + "bson": "^5.3.0", + "mongodb-connection-string-url": "^2.6.0", + "socks": "^2.7.1" + }, + "engines": { + "node": ">=14.20.1" + }, + "optionalDependencies": { + "saslprep": "^1.0.3" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.201.0", + "mongodb-client-encryption": ">=2.3.0 <3", + "snappy": "^7.2.2" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz", + "integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==", + "dependencies": { + "@types/whatwg-url": "^8.2.1", + "whatwg-url": "^11.0.0" + } + }, + "node_modules/path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==", + "dependencies": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "engines": { + "node": ">= 0.6.0" + } + }, + "node_modules/punycode": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", + "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", + "engines": { + "node": ">=6" + } + }, + "node_modules/saslprep": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", + "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", + "optional": true, + "dependencies": { + "sparse-bitfield": "^3.0.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", + "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "dependencies": { + "ip": "^2.0.0", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.13.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "optional": true, + "dependencies": { + "memory-pager": "^1.0.2" + } + }, + "node_modules/tr46": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", + "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", + "dependencies": { + "punycode": "^2.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "dependencies": { + "inherits": "2.0.3" + } + }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", + "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", + "dependencies": { + "tr46": "^3.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + } + }, + "dependencies": { + "@types/node": { + "version": "20.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.0.tgz", + "integrity": "sha512-cumHmIAf6On83X7yP+LrsEyUOf/YlociZelmpRYaGFydoaPdxdt80MAbu6vWerQT2COCp2nPvHdsbD7tHn/YlQ==" + }, + "@types/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==" + }, + "@types/whatwg-url": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz", + "integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==", + "requires": { + "@types/node": "*", + "@types/webidl-conversions": "*" + } + }, + "bson": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-5.3.0.tgz", + "integrity": "sha512-ukmCZMneMlaC5ebPHXIkP8YJzNl5DC41N5MAIvKDqLggdao342t4McltoJBQfQya/nHBWAcSsYRqlXPoQkTJag==" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" + }, + "ip": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", + "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==" + }, + "memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "optional": true + }, + "mongodb": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-5.6.0.tgz", + "integrity": "sha512-z8qVs9NfobHJm6uzK56XBZF8XwM9H294iRnB7wNjF0SnY93si5HPziIJn+qqvUR5QOff/4L0gCD6SShdR/GtVQ==", + "requires": { + "bson": "^5.3.0", + "mongodb-connection-string-url": "^2.6.0", + "saslprep": "^1.0.3", + "socks": "^2.7.1" + } + }, + "mongodb-connection-string-url": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz", + "integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==", + "requires": { + "@types/whatwg-url": "^8.2.1", + "whatwg-url": "^11.0.0" + } + }, + "path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==", + "requires": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, + "process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==" + }, + "punycode": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", + "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==" + }, + "saslprep": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", + "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", + "optional": true, + "requires": { + "sparse-bitfield": "^3.0.3" + } + }, + "smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==" + }, + "socks": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", + "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "requires": { + "ip": "^2.0.0", + "smart-buffer": "^4.2.0" + } + }, + "sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "optional": true, + "requires": { + "memory-pager": "^1.0.2" + } + }, + "tr46": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", + "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", + "requires": { + "punycode": "^2.1.1" + } + }, + "util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "requires": { + "inherits": "2.0.3" + } + }, + "webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==" + }, + "whatwg-url": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", + "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", + "requires": { + "tr46": "^3.0.0", + "webidl-conversions": "^7.0.0" + } } } } diff --git a/package.json b/package.json index 0a2a987..a4b7da9 100644 --- a/package.json +++ b/package.json @@ -17,5 +17,9 @@ "bugs": { "url": "https://github.com/NITKC22s/UpdateSystem/issues" }, - "homepage": "https://github.com/NITKC22s/UpdateSystem#readme" + "homepage": "https://github.com/NITKC22s/UpdateSystem#readme", + "dependencies": { + "mongodb": "^5.6.0", + "path": "^0.12.7" + } } From 9f96bc0ea0bc5fe2ff7e5efe3c3b8f0574dcace9 Mon Sep 17 00:00:00 2001 From: Kou-Ro Date: Mon, 12 Jun 2023 22:26:51 +0900 Subject: [PATCH 2/7] CCConfig.json datas move to --- 0.0.0/Update.js | 33 +++++++++++++++++++++++++++++++++ UpdateSystem.js | 8 +++----- environmentConfig.js | 8 -------- environmentPath.js | 9 +++++++++ functions/db.js | 1 - 5 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 0.0.0/Update.js delete mode 100644 environmentConfig.js create mode 100644 environmentPath.js diff --git a/0.0.0/Update.js b/0.0.0/Update.js new file mode 100644 index 0000000..4771092 --- /dev/null +++ b/0.0.0/Update.js @@ -0,0 +1,33 @@ +const db=require("../functions/db.js"); +exports.update= function(){ + changeCCC(); +}; + +function changeCCC(){ + const ccconfig=require(targetPath+"/CCConfig.json"); + for(const guild of ccconfig.guilds){ + for(const category of guild.categories){ + if(category.ID!=="0000000000000000000"){ + db.insert ("main", "CC-categories", { + "ID": category.ID, + "name": category.name, + "guildID": guild.ID + }); + } + for(const channel of category.channels){ + if(channel.ID!=="0000000000000000000"&&channel.ID!=="") { + db.insert ("main", "CC-channels", { + "ID": channel.ID, + "name": channel.name, + "creatorID": channel.creatorID, + "createTime": channel.createTime, + "thereRole": channel.thereRole !== undefined ? channel.thereRole : false, + "roleID": channel.roleID !== undefined ? channel.roleID : "", + "categoryID": category.ID, + "guildID": guild.ID + }); + } + } + } + } +} \ No newline at end of file diff --git a/UpdateSystem.js b/UpdateSystem.js index 09cb50f..4c3a563 100644 --- a/UpdateSystem.js +++ b/UpdateSystem.js @@ -1,24 +1,22 @@ const pack=require('./package.json'); let ver; -let mainpack; +const envConfig=require("./environmentPath.js"); +envConfig.setConfig(); +let mainpack=require(targetPath+"/package.json"); switch (process.argv[2]){ case "test": - mainpack=require("../update-test/package.json"); ver="0.0.0" break; case "dev": - mainpack=require("../update-test/package.json"); ver=pack.version; break; case "run": - mainpack=require("../bot-main/package.json"); ver=pack.version; break; default: console.error("\u001b[33mPlease set command line argument to test, dev or run\u001b[0m"); console.error("Running type set to test"); - mainpack=require("../update-test/package.json"); ver="0.0.0"; break; } diff --git a/environmentConfig.js b/environmentConfig.js deleted file mode 100644 index e6e9ea4..0000000 --- a/environmentConfig.js +++ /dev/null @@ -1,8 +0,0 @@ -const Path = require("path"); -const configPath = Path.resolve( - __dirname, - process.argv[2] === "run" ? "./config.json" : "./config.dev.json" -); -const config = require(configPath); -module.exports = config; -module.exports.configPath = configPath; diff --git a/environmentPath.js b/environmentPath.js new file mode 100644 index 0000000..d9a7160 --- /dev/null +++ b/environmentPath.js @@ -0,0 +1,9 @@ +exports.setConfig=function() { + const Path = require ("path"); + global.configPath = Path.resolve ( + __dirname, + process.argv[2] === "run" ? "./config.json" : "./config.dev.json" + ); + global.config = require (configPath); + global.targetPath=Path.resolve (__dirname,"..",process.argv[2] === "run"?"bot-main":"update-test"); +}; \ No newline at end of file diff --git a/functions/db.js b/functions/db.js index b9068e2..456740b 100644 --- a/functions/db.js +++ b/functions/db.js @@ -1,5 +1,4 @@ const { MongoClient, ServerApiVersion } = require("mongodb"); -const config = require('../environmentConfig') const dbClient = new MongoClient(config.db, { serverApi: ServerApiVersion.v1 }); /*** From 72f783e22ae30732438a58471178f16b6652baef Mon Sep 17 00:00:00 2001 From: Kou-Ro Date: Wed, 14 Jun 2023 01:28:42 +0900 Subject: [PATCH 3/7] commit for @Kokastar --- 0.0.0/Outdate.js | 97 +++++++++++++++++++++++++++++++++++++++++ 0.0.0/Update.js | 31 ++++++++----- UpdateSystem.js | 109 +++++++++++++++++++++++++--------------------- VersionList.json | 2 +- functions/db.js | 5 +-- package-lock.json | 11 +++++ package.json | 1 + 7 files changed, 190 insertions(+), 66 deletions(-) create mode 100644 0.0.0/Outdate.js diff --git a/0.0.0/Outdate.js b/0.0.0/Outdate.js new file mode 100644 index 0000000..06c7125 --- /dev/null +++ b/0.0.0/Outdate.js @@ -0,0 +1,97 @@ +const fs = require ('fs'); +const db = require ('../functions/db.js'); + +/*** + * @returns {Promise} + */ +exports.outdate = async function () { + await changeDBCC (); +} + +async function changeDBCC () { + let ccconfig = { + "guilds": [ + { + "ID": "0000000000000000000", + "categories": [ + { + "ID": "0000000000000000000", + "name": "", + "allowRole": false, + "active": false, + "channels": [ + { + "ID": "0000000000000000000", + "name": "", + "creatorId": "0000000000000000000", + "createTime": 0, + "thereRole": false, + "roleID": "0000000000000000000", + "roleName": "" + } + ] + } + ] + } + ] + }; + + let ccchannels = await db.find ("main", "CC-channels", {}); + let cccategories = await db.find ("main", "CC-categories", {}); + while (cccategories.length > 0) { + const categoriesData = await cccategories.filter (category => category.guildID === cccategories[0].guildID); + let guildConfig = { + "ID": cccategories[0].guildID, + "categories": [ + { + "ID": "0000000000000000000", + "name": "キャンセル", + "allowRole": false, + "channels": [] + } + ] + }; + for (let i = 0; i < categoriesData.length; i++) { + let channelsData = ccchannels.filter (channel => channel.categoryID === categoriesData[i].ID); + let categoryConfig = { + "ID": categoriesData[i].ID, + "name": categoriesData[i].name, + "allowRole": categoriesData[i].allowRole, + "channels": [ + { + "ID": "", + "name": "", + "creatorId": "0000000000000000000", + "createTime": 0, + "thereRole": false, + "roleID": "0000000000000000000", + "roleName": "" + } + ] + }; + for (let j = 0; j < channelsData.length; j++) { + categoryConfig.channels.push ({ + "ID": channelsData[j].ID, + "name": channelsData[j].name, + "creatorID": channelsData[j].creatorID, + "createTime": channelsData[j].createTime, + "thereRole": channelsData[j].thereRole, + "roleID": channelsData[j].thereRole === true ? channelsData[j].roleID : undefined, + "roleName": channelsData[j].thereRole === true ? channelsData[j].roleName : undefined + }); + } + guildConfig.categories.push (categoryConfig); + } + ccconfig.guilds.push (guildConfig); + cccategories = cccategories.filter (category => category.guildID !== cccategories[0].guildID); + } + const ccconfigJ = JSON.stringify (ccconfig, null, 2); + try { + fs.writeFileSync (targetPath + "/CCConfig.json", ccconfigJ, "utf-8"); + } + catch (e) { + console.log (e); + } + + return; +} \ No newline at end of file diff --git a/0.0.0/Update.js b/0.0.0/Update.js index 4771092..aaaebe2 100644 --- a/0.0.0/Update.js +++ b/0.0.0/Update.js @@ -1,28 +1,34 @@ -const db=require("../functions/db.js"); -exports.update= function(){ - changeCCC(); +const db = require ("../functions/db.js"); + +/*** + * @returns {Promise} + */ +exports.update = async function () { + await changeCCC (); }; -function changeCCC(){ - const ccconfig=require(targetPath+"/CCConfig.json"); - for(const guild of ccconfig.guilds){ - for(const category of guild.categories){ - if(category.ID!=="0000000000000000000"){ - db.insert ("main", "CC-categories", { +async function changeCCC () { + const ccconfig = require (targetPath + "/CCConfig.json"); + for (const guild of ccconfig.guilds) { + for (const category of guild.categories) { + if (category.ID !== "0000000000000000000") { + await db.insert ("main", "CC-categories", { "ID": category.ID, "name": category.name, + "allowRole": category.allowRole, "guildID": guild.ID }); } - for(const channel of category.channels){ - if(channel.ID!=="0000000000000000000"&&channel.ID!=="") { - db.insert ("main", "CC-channels", { + for (const channel of category.channels) { + if (channel.ID !== "0000000000000000000" && channel.ID !== "") { + await db.insert ("main", "CC-channels", { "ID": channel.ID, "name": channel.name, "creatorID": channel.creatorID, "createTime": channel.createTime, "thereRole": channel.thereRole !== undefined ? channel.thereRole : false, "roleID": channel.roleID !== undefined ? channel.roleID : "", + "roleName": channel.roleName !== undefined ? channel.roleName : "", "categoryID": category.ID, "guildID": guild.ID }); @@ -30,4 +36,5 @@ function changeCCC(){ } } } + return; } \ No newline at end of file diff --git a/UpdateSystem.js b/UpdateSystem.js index 4c3a563..13e253b 100644 --- a/UpdateSystem.js +++ b/UpdateSystem.js @@ -1,57 +1,66 @@ -const pack=require('./package.json'); +const pack = require ('./package.json'); let ver; -const envConfig=require("./environmentPath.js"); -envConfig.setConfig(); -let mainpack=require(targetPath+"/package.json"); +const envConfig = require ("./environmentPath.js"); +envConfig.setConfig (); +let mainpack = require (targetPath + "/package.json"); -switch (process.argv[2]){ - case "test": - ver="0.0.0" - break; - case "dev": - ver=pack.version; - break; - case "run": - ver=pack.version; - break; - default: - console.error("\u001b[33mPlease set command line argument to test, dev or run\u001b[0m"); - console.error("Running type set to test"); - ver="0.0.0"; - break; -} -const mainver=mainpack.version; - -console.log(`${mainver} ---> ${ver}`); - -const versions=require('./VersionList.json').versions; -const ind=versions.findIndex(versionData=>versionData.version===ver); -const mainInd=versions.findIndex(versionData=>versionData.version===mainver); - -if(ind>mainInd){ - for(let i=mainInd+1;i<=ind;i++){ - if(versions[i].update===true){ - console.log(`Update v${versions[i-1].version} to v${versions[i].version}`); - const Update=require(`./${versions[i].version}/Update.js`); - Update.update(); - } - else{ - console.log(`No updates between v${versions[i-1].version} and v${versions[i].version}`); - } +async function main() { + switch (process.argv[2]) { + case "test": + ver = "0.0.0" + break; + case "dev": + ver = pack.version; + break; + case "run": + ver = pack.version; + break; + default: + console.error ("\u001b[33mPlease set command line argument to test, dev or run\u001b[0m"); + console.error ("Running type set to test"); + ver = "0.0.0"; + break; } -} -else if(ind ${ver}`); + + const versions = require ('./VersionList.json').versions; + const ind = versions.findIndex (versionData => versionData.version === ver); + const mainInd = versions.findIndex (versionData => versionData.version === mainver); + + if (ind > mainInd) { + for (let i = mainInd + 1; i <= ind; i++) { + if (versions[i].update === true) { + console.log (`Update v${versions[i - 1].version} to v${versions[i].version}`); + const Update = require (`./${versions[i].version}/Update.js`); + await Update.update (); + } + else { + console.log (`No updates between v${versions[i - 1].version} and v${versions[i].version}`); + } } - else{ - console.log(`No outdates between v${versions[i].version} and v${versions[i-1].version}`); + } + else if (ind < mainInd) { + for (let i = mainInd; i < ind + 1; i--) { + if (versions[i].outdate === true) { + console.log (`Outdate v${versions[i].version} to v${versions[i - 1].version}`); + const Outdate = require (`./${versions[i].version}/Outdate.js`); + await Outdate.outdate (); + } + else { + console.log (`No outdates between v${versions[i].version} and v${versions[i - 1].version}`); + } } } + else if (ind === mainInd) { + console.log ("No updates needed.") + } + + if (process.argv[2] === "test" && versions[versions.length - 1].outdate === true) { + console.log (`Outdate test`); + const Outdate = require (`./0.0.0/Outdate.js`); + await Outdate.outdate (); + } } -if(ind===mainInd){ - console.log("No updates needed.") -} \ No newline at end of file +main(); \ No newline at end of file diff --git a/VersionList.json b/VersionList.json index b3e7335..7402f4c 100644 --- a/VersionList.json +++ b/VersionList.json @@ -13,6 +13,6 @@ {"version": "4.0.3","update": false,"outdate": false}, {"version": "4.0.4","update": false,"outdate": false}, {"version": "4.0.5","update": false,"outdate": false}, - {"version": "0.0.0","update": true,"outdate": false} + {"version": "0.0.0","update": true, "outdate": false} ] } \ No newline at end of file diff --git a/functions/db.js b/functions/db.js index 456740b..96b8961 100644 --- a/functions/db.js +++ b/functions/db.js @@ -6,12 +6,11 @@ const dbClient = new MongoClient(config.db, { serverApi: ServerApiVersion.v1 }); * @param dbName 取得先データベース名 * @param collectionName 取得先コレクション名 * @param filter フィルターを指定 - * @returns Array型 + * @returns Promise<[object]> */ exports.find = async function (dbName, collectionName, filter) { const collection = dbClient.db(dbName).collection(collectionName); - - return await collection.find(filter).toArray() + return await collection.find(filter).toArray(); } /*** diff --git a/package-lock.json b/package-lock.json index 865f5ce..9443756 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "license": "ISC", "dependencies": { + "fs": "^0.0.1-security", "mongodb": "^5.6.0", "path": "^0.12.7" } @@ -40,6 +41,11 @@ "node": ">=14.20.1" } }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "node_modules/inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", @@ -230,6 +236,11 @@ "resolved": "https://registry.npmjs.org/bson/-/bson-5.3.0.tgz", "integrity": "sha512-ukmCZMneMlaC5ebPHXIkP8YJzNl5DC41N5MAIvKDqLggdao342t4McltoJBQfQya/nHBWAcSsYRqlXPoQkTJag==" }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", diff --git a/package.json b/package.json index a4b7da9..9d3c0ef 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "homepage": "https://github.com/NITKC22s/UpdateSystem#readme", "dependencies": { + "fs": "^0.0.1-security", "mongodb": "^5.6.0", "path": "^0.12.7" } From 5721c714398aa33d25d91a0db73cc22274a4999f Mon Sep 17 00:00:00 2001 From: starkoka Date: Wed, 14 Jun 2023 02:13:31 +0900 Subject: [PATCH 4/7] =?UTF-8?q?close=E3=81=97=E3=81=A6=E7=B5=82=E4=BA=86?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E6=94=B9=E8=89=AF?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=82=E3=81=92=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UpdateSystem.js | 2 ++ VersionList.json | 1 + functions/db.js | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/UpdateSystem.js b/UpdateSystem.js index 13e253b..f0e875b 100644 --- a/UpdateSystem.js +++ b/UpdateSystem.js @@ -3,6 +3,7 @@ let ver; const envConfig = require ("./environmentPath.js"); envConfig.setConfig (); let mainpack = require (targetPath + "/package.json"); +const db = require ("./functions/db.js"); async function main() { switch (process.argv[2]) { @@ -62,5 +63,6 @@ async function main() { const Outdate = require (`./0.0.0/Outdate.js`); await Outdate.outdate (); } + db.close(); } main(); \ No newline at end of file diff --git a/VersionList.json b/VersionList.json index 7402f4c..f2d94b0 100644 --- a/VersionList.json +++ b/VersionList.json @@ -13,6 +13,7 @@ {"version": "4.0.3","update": false,"outdate": false}, {"version": "4.0.4","update": false,"outdate": false}, {"version": "4.0.5","update": false,"outdate": false}, + {"version": "4.0.6","update": false,"outdate": false}, {"version": "0.0.0","update": true, "outdate": false} ] } \ No newline at end of file diff --git a/functions/db.js b/functions/db.js index 96b8961..1baa607 100644 --- a/functions/db.js +++ b/functions/db.js @@ -1,4 +1,4 @@ -const { MongoClient, ServerApiVersion } = require("mongodb"); + const { MongoClient, ServerApiVersion } = require("mongodb"); const dbClient = new MongoClient(config.db, { serverApi: ServerApiVersion.v1 }); /*** @@ -70,4 +70,8 @@ exports.delete = async function run(dbName,collectionName,filter) { } } +exports.close = async function close(){ + await dbClient.close(); + console.log("close"); + } //引数の詳細については、mongodbの公式ドキュメントを参照すること From 21686b8511adb8444210901f4ff7bbd92b8c5023 Mon Sep 17 00:00:00 2001 From: Kou-Ro Date: Wed, 14 Jun 2023 13:41:34 +0900 Subject: [PATCH 5/7] v5.0.0 outdate --- UpdateSystem.js | 2 +- VersionList.json | 2 +- functions/db.js | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/UpdateSystem.js b/UpdateSystem.js index f0e875b..908d86c 100644 --- a/UpdateSystem.js +++ b/UpdateSystem.js @@ -63,6 +63,6 @@ async function main() { const Outdate = require (`./0.0.0/Outdate.js`); await Outdate.outdate (); } - db.close(); + await db.close(); } main(); \ No newline at end of file diff --git a/VersionList.json b/VersionList.json index f2d94b0..56f22dd 100644 --- a/VersionList.json +++ b/VersionList.json @@ -14,6 +14,6 @@ {"version": "4.0.4","update": false,"outdate": false}, {"version": "4.0.5","update": false,"outdate": false}, {"version": "4.0.6","update": false,"outdate": false}, - {"version": "0.0.0","update": true, "outdate": false} + {"version": "0.0.0","update": false, "outdate": true} ] } \ No newline at end of file diff --git a/functions/db.js b/functions/db.js index 1baa607..383bdfd 100644 --- a/functions/db.js +++ b/functions/db.js @@ -69,9 +69,12 @@ exports.delete = async function run(dbName,collectionName,filter) { await console.error(`${dbName}.${collectionName}からレコードを削除できませんでした`,err,`DB削除失敗`); } } - -exports.close = async function close(){ + + /*** + * データーベースとの接続を切る + */ + exports.close = async function close(){ await dbClient.close(); - console.log("close"); + console.log("DBとの接続を終了しました。"); } //引数の詳細については、mongodbの公式ドキュメントを参照すること From e6374285c04472d836a2392bb5c1009f150bf053 Mon Sep 17 00:00:00 2001 From: Kou-Ro Date: Fri, 16 Jun 2023 16:42:51 +0900 Subject: [PATCH 6/7] Update UpdateSystem base --- .run/test.run.xml | 5 -- EnvironmentPath.js | 5 ++ UpdateSystem.js | 172 +++++++++++++++++++++++++++---------- VersionList.json | 3 +- environmentPath.js | 9 -- functions/db.js | 6 +- package-lock.json | 67 +++++++++++++++ package.json | 2 + {0.0.0 => test}/Outdate.js | 5 +- {0.0.0 => test}/Update.js | 0 10 files changed, 209 insertions(+), 65 deletions(-) delete mode 100644 .run/test.run.xml create mode 100644 EnvironmentPath.js delete mode 100644 environmentPath.js rename {0.0.0 => test}/Outdate.js (96%) rename {0.0.0 => test}/Update.js (100%) diff --git a/.run/test.run.xml b/.run/test.run.xml deleted file mode 100644 index 8bf4750..0000000 --- a/.run/test.run.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/EnvironmentPath.js b/EnvironmentPath.js new file mode 100644 index 0000000..89b5d89 --- /dev/null +++ b/EnvironmentPath.js @@ -0,0 +1,5 @@ +exports.setEnvPath=function () { + const Path = require("path"); + global.configPath = Path.resolve(__dirname, global.mode === "run" ? "./config.json" : "./config.dev.json"); + global.config = require(configPath); +} \ No newline at end of file diff --git a/UpdateSystem.js b/UpdateSystem.js index 908d86c..2d3d7f5 100644 --- a/UpdateSystem.js +++ b/UpdateSystem.js @@ -1,68 +1,152 @@ -const pack = require ('./package.json'); -let ver; -const envConfig = require ("./environmentPath.js"); -envConfig.setConfig (); -let mainpack = require (targetPath + "/package.json"); -const db = require ("./functions/db.js"); +const pack = require('./package.json'); +const Path =require("path"); +const db = require("./functions/db.js"); +const Enquirer = require("enquirer"); +const VersionList = require("./VersionList").versions; +const EnvPath=require("./EnvironmentPath.js"); +const {setEnvPath} = require("./EnvironmentPath"); -async function main() { - switch (process.argv[2]) { + +(async() => { + await modeBranch(process.argv[2]); + await db.close(); +})(); + +/*** + * Branch processing by mode + * @param {string} mode Running type + */ +async function modeBranch(mode) { + switch(mode) { case "test": - ver = "0.0.0" + global.mode=mode; + await testMord(); break; case "dev": - ver = pack.version; - break; case "run": - ver = pack.version; + global.mode=mode; + await productMode(); + break; + case undefined: + await modeChoice(); break; default: - console.error ("\u001b[33mPlease set command line argument to test, dev or run\u001b[0m"); - console.error ("Running type set to test"); - ver = "0.0.0"; + console.log("Cannot find the mode "+mode); + await modeChoice(); break; } - const mainver = mainpack.version; +} + +/*** + * Running process of test mode + */ +async function testMord() { + let runType; + await (async() => { + const testRunSet = { + type: "select", + name: "setRunningType", + message: "Please select running type", + choices: ["Update", "Outdate", "Both"] + }; + runType = (await Enquirer.prompt(testRunSet)).setRunningType; + })(); + global.targetPath=Path.resolve(__dirname, "../update-test"); + switch (runType) { + case "Update": + await RunUpdate(); + break; + case "Outdate": + await RunOutdate(); + break; + case "Both": + await RunUpdate(); + await RunOutdate(); + } + +} + +/*** + * Running Update.js in ./test/ + */ +async function RunUpdate(){ + const Update = require("./test/Update.js"); + await Update.update(); +} + +/*** + * Running Outdate.js in ./test/ + */ +async function RunOutdate(){ + const Outdate = require("./test/Outdate.js"); + await Outdate.outdate(); +} + +/*** + * Running process + */ +async function productMode() { + let targetV; + await (async() => { + const targetSelect = { + type: "select", + name: "setTargetVer", + message: "Please select the update (outdate) destination", + choices: VersionList.map(elem => elem.version) + }; + targetV = (await Enquirer.prompt(targetSelect)).setTargetVer; + })(); + await setEnvPath(); + global.targetPath=Path.resolve(__dirname, "../bot-main"); - console.log (`${mainver} ---> ${ver}`); + let mainPack = require(Path.resolve(targetPath,"/package.json")); + const mainV = mainPack.version; + console.log(`${mainV} ---> ${targetV}`); - const versions = require ('./VersionList.json').versions; - const ind = versions.findIndex (versionData => versionData.version === ver); - const mainInd = versions.findIndex (versionData => versionData.version === mainver); + const versions = require('./VersionList.json').versions; + const targetInd = versions.findIndex(versionData => versionData.version === targetV); + const mainInd = versions.findIndex(versionData => versionData.version === mainV); - if (ind > mainInd) { - for (let i = mainInd + 1; i <= ind; i++) { - if (versions[i].update === true) { - console.log (`Update v${versions[i - 1].version} to v${versions[i].version}`); - const Update = require (`./${versions[i].version}/Update.js`); - await Update.update (); + if(targetInd> mainInd) { + for(let i = mainInd + 1; i <= targetInd; i++) { + if(versions[i].update === true) { + console.log(`Update v${versions[i - 1].version} to v${versions[i].version}`); + const Update = require(`./${versions[i].version}/Update.js`); + await Update.update(); } else { - console.log (`No updates between v${versions[i - 1].version} and v${versions[i].version}`); + console.log(`No updates between v${versions[i - 1].version} and v${versions[i].version}`); } } } - else if (ind < mainInd) { - for (let i = mainInd; i < ind + 1; i--) { - if (versions[i].outdate === true) { - console.log (`Outdate v${versions[i].version} to v${versions[i - 1].version}`); - const Outdate = require (`./${versions[i].version}/Outdate.js`); - await Outdate.outdate (); + else if(targetInd < mainInd) { + for(let i = mainInd; i < targetInd + 1; i--) { + if(versions[i].outdate === true) { + console.log(`Outdate v${versions[i].version} to v${versions[i - 1].version}`); + const Outdate = require(`./${versions[i].version}/Outdate.js`); + await Outdate.outdate(); } else { - console.log (`No outdates between v${versions[i].version} and v${versions[i - 1].version}`); + console.log(`No outdates between v${versions[i].version} and v${versions[i - 1].version}`); } } } - else if (ind === mainInd) { - console.log ("No updates needed.") + else if(targetInd === mainInd) { + console.log("No updates needed.") } - - if (process.argv[2] === "test" && versions[versions.length - 1].outdate === true) { - console.log (`Outdate test`); - const Outdate = require (`./0.0.0/Outdate.js`); - await Outdate.outdate (); - } - await db.close(); } -main(); \ No newline at end of file + +/*** + *Select running mode + */ +async function modeChoice() { + await(async() => { + const modeSelect={ + type:"select", + name:"setMode", + message:"Please select running mode", + choices: ["test","dev","run"] + } + await modeBranch((await Enquirer.prompt(modeSelect)).setMode); + })(); +} \ No newline at end of file diff --git a/VersionList.json b/VersionList.json index 56f22dd..ed5f4c3 100644 --- a/VersionList.json +++ b/VersionList.json @@ -13,7 +13,6 @@ {"version": "4.0.3","update": false,"outdate": false}, {"version": "4.0.4","update": false,"outdate": false}, {"version": "4.0.5","update": false,"outdate": false}, - {"version": "4.0.6","update": false,"outdate": false}, - {"version": "0.0.0","update": false, "outdate": true} + {"version": "4.0.6","update": false,"outdate": false} ] } \ No newline at end of file diff --git a/environmentPath.js b/environmentPath.js deleted file mode 100644 index d9a7160..0000000 --- a/environmentPath.js +++ /dev/null @@ -1,9 +0,0 @@ -exports.setConfig=function() { - const Path = require ("path"); - global.configPath = Path.resolve ( - __dirname, - process.argv[2] === "run" ? "./config.json" : "./config.dev.json" - ); - global.config = require (configPath); - global.targetPath=Path.resolve (__dirname,"..",process.argv[2] === "run"?"bot-main":"update-test"); -}; \ No newline at end of file diff --git a/functions/db.js b/functions/db.js index 383bdfd..f107667 100644 --- a/functions/db.js +++ b/functions/db.js @@ -1,5 +1,7 @@ - const { MongoClient, ServerApiVersion } = require("mongodb"); -const dbClient = new MongoClient(config.db, { serverApi: ServerApiVersion.v1 }); +const { MongoClient, ServerApiVersion } = require("mongodb"); +const EnvPath=require("../EnvironmentPath"); +EnvPath.setEnvPath(); +const dbClient = new MongoClient(global.config.db, { serverApi: ServerApiVersion.v1 }); /*** * データベースからデータを取得する diff --git a/package-lock.json b/package-lock.json index 9443756..0fb4c33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,10 @@ "version": "0.0.0", "license": "ISC", "dependencies": { + "enquirer": "^2.3.6", "fs": "^0.0.1-security", "mongodb": "^5.6.0", + "node": "^18.16.0", "path": "^0.12.7" } }, @@ -33,6 +35,14 @@ "@types/webidl-conversions": "*" } }, + "node_modules/ansi-colors": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", + "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", + "engines": { + "node": ">=6" + } + }, "node_modules/bson": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/bson/-/bson-5.3.0.tgz", @@ -41,6 +51,17 @@ "node": ">=14.20.1" } }, + "node_modules/enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dependencies": { + "ansi-colors": "^4.1.1" + }, + "engines": { + "node": ">=8.6" + } + }, "node_modules/fs": { "version": "0.0.1-security", "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", @@ -103,6 +124,26 @@ "whatwg-url": "^11.0.0" } }, + "node_modules/node": { + "version": "18.16.0", + "resolved": "https://registry.npmjs.org/node/-/node-18.16.0.tgz", + "integrity": "sha512-xi2PRz7qrWfzNXCl7F0Y5wVQFIqsP2VZEOkdghIvyhTg3OBDTTPYX0rmB9vDDJ1f/TUA31ldFMnl0zNd4lhNqA==", + "hasInstallScript": true, + "dependencies": { + "node-bin-setup": "^1.0.0" + }, + "bin": { + "node": "bin/node" + }, + "engines": { + "npm": ">=5.0.0" + } + }, + "node_modules/node-bin-setup": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/node-bin-setup/-/node-bin-setup-1.1.3.tgz", + "integrity": "sha512-opgw9iSCAzT2+6wJOETCpeRYAQxSopqQ2z+N6BXwIMsQQ7Zj5M8MaafQY8JMlolRR6R1UXg2WmhKp0p9lSOivg==" + }, "node_modules/path": { "version": "0.12.7", "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", @@ -231,11 +272,24 @@ "@types/webidl-conversions": "*" } }, + "ansi-colors": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", + "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==" + }, "bson": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/bson/-/bson-5.3.0.tgz", "integrity": "sha512-ukmCZMneMlaC5ebPHXIkP8YJzNl5DC41N5MAIvKDqLggdao342t4McltoJBQfQya/nHBWAcSsYRqlXPoQkTJag==" }, + "enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "requires": { + "ansi-colors": "^4.1.1" + } + }, "fs": { "version": "0.0.1-security", "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", @@ -277,6 +331,19 @@ "whatwg-url": "^11.0.0" } }, + "node": { + "version": "18.16.0", + "resolved": "https://registry.npmjs.org/node/-/node-18.16.0.tgz", + "integrity": "sha512-xi2PRz7qrWfzNXCl7F0Y5wVQFIqsP2VZEOkdghIvyhTg3OBDTTPYX0rmB9vDDJ1f/TUA31ldFMnl0zNd4lhNqA==", + "requires": { + "node-bin-setup": "^1.0.0" + } + }, + "node-bin-setup": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/node-bin-setup/-/node-bin-setup-1.1.3.tgz", + "integrity": "sha512-opgw9iSCAzT2+6wJOETCpeRYAQxSopqQ2z+N6BXwIMsQQ7Zj5M8MaafQY8JMlolRR6R1UXg2WmhKp0p9lSOivg==" + }, "path": { "version": "0.12.7", "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", diff --git a/package.json b/package.json index 9d3c0ef..266f537 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,10 @@ }, "homepage": "https://github.com/NITKC22s/UpdateSystem#readme", "dependencies": { + "enquirer": "^2.3.6", "fs": "^0.0.1-security", "mongodb": "^5.6.0", + "node": "^18.16.0", "path": "^0.12.7" } } diff --git a/0.0.0/Outdate.js b/test/Outdate.js similarity index 96% rename from 0.0.0/Outdate.js rename to test/Outdate.js index 06c7125..b8d075b 100644 --- a/0.0.0/Outdate.js +++ b/test/Outdate.js @@ -87,11 +87,10 @@ async function changeDBCC () { } const ccconfigJ = JSON.stringify (ccconfig, null, 2); try { - fs.writeFileSync (targetPath + "/CCConfig.json", ccconfigJ, "utf-8"); + fs.writeFileSync (global.targetPath + "/CCConfig.json", ccconfigJ, "utf-8"); } catch (e) { console.log (e); } - - return; + console.log("hello"); } \ No newline at end of file diff --git a/0.0.0/Update.js b/test/Update.js similarity index 100% rename from 0.0.0/Update.js rename to test/Update.js From 7121fcfe47a658c66ff90cbc6eaa943bdedc0cc8 Mon Sep 17 00:00:00 2001 From: Kou-Ro Date: Sun, 18 Jun 2023 13:33:44 +0900 Subject: [PATCH 7/7] =?UTF-8?q?global.targetPath=E3=81=AE=E5=AE=A3?= =?UTF-8?q?=E8=A8=80=E4=BD=8D=E7=BD=AE=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UpdateSystem.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UpdateSystem.js b/UpdateSystem.js index 2d3d7f5..8c11eb3 100644 --- a/UpdateSystem.js +++ b/UpdateSystem.js @@ -19,11 +19,17 @@ const {setEnvPath} = require("./EnvironmentPath"); async function modeBranch(mode) { switch(mode) { case "test": + global.targetPath=Path.resolve(__dirname, "../update-test"); global.mode=mode; await testMord(); break; case "dev": + global.targetPath=Path.resolve(__dirname, "../update-test"); + global.mode=mode; + await productMode(); + break case "run": + global.targetPath=Path.resolve(__dirname, "../bot-main"); global.mode=mode; await productMode(); break;