-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75ba9b4
commit 527fd94
Showing
29 changed files
with
429 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM mcr.microsoft.com/devcontainers/javascript-node:0-18 | ||
ARG MONGO_TOOLS_VERSION=6.0 | ||
RUN . /etc/os-release \ | ||
&& curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ | ||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ | ||
&& apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get install -y mongodb-mongosh \ | ||
&& if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \ | ||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "Node.js & Mongo DB", | ||
"dockerComposeFile": "docker-compose.yml", | ||
"service": "app", | ||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"mongodb.mongodb-vscode" | ||
] | ||
} | ||
}, | ||
"forwardPorts": [3000, 3500, 8081], | ||
"postCreateCommand": "npm install" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: '3.8' | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
container_name: local-app | ||
volumes: | ||
- ../..:/workspaces:cached | ||
command: sleep infinity | ||
network_mode: service:mongo | ||
|
||
mongo: | ||
image: mongo:latest | ||
container_name: local-mongo | ||
restart: unless-stopped | ||
|
||
express: | ||
image: mongo-express:latest | ||
container_name: local-express | ||
restart: unless-stopped | ||
environment: | ||
ME_CONFIG_BASICAUTH_USERNAME: developer | ||
ME_CONFIG_BASICAUTH_PASSWORD: developer | ||
ME_CONFIG_MONGODB_SERVER: local-mongo | ||
network_mode: service:mongo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
# node env ('production' or 'development') | ||
NODE_ENV="development" | ||
|
||
# general | ||
MONGODB_URI="mongodb://local-mongo:27017/app" | ||
GOOGLE_AI_API_KEY="your_google_ai_api_key" | ||
|
||
# discord integration | ||
DISCORD_APP_ID="00000" | ||
DISCORD_BOT_TOKEN="your_discord_bot_token" | ||
|
||
DISCORD_GUILD_ID="00000" | ||
DISCORD_ROLE_ID_ADMIN="00000" | ||
DISCORD_CHANNEL_ID_TERMINAL="00000" | ||
DISCORD_GUILD_ROLE_ID_ADMIN="00000" | ||
DISCORD_GUILD_CHANNEL_ID_TERMINAL="00000" | ||
|
||
# matrix integration | ||
MATRIX_HOMESERVER="https://matrix.org" | ||
MATRIX_USERNAME="your_matrix_username" # e.g. @nymph57021218:matrix.org | ||
MATRIX_PASSWORD="your_matrix_password" | ||
MATRIX_ACCESS_TOKEN="your_matrix_access_token" | ||
|
||
GOOGLE_AI_API_KEY="your_google_ai_api_key" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ prompts.json | |
relay.json | ||
roles.json | ||
|
||
# App data files | ||
data/ | ||
|
||
# Finder config file | ||
.DS_Store | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
"use strict"; | ||
|
||
require("dotenv").config(); | ||
const { | ||
runLoader, | ||
getMust, | ||
} = require("./src/config"); | ||
const { | ||
prepare, | ||
} = require("./src/clients/database"); | ||
|
||
const runners = []; | ||
runLoader(); | ||
|
||
if (process.env.MATRIX_ACCESS_TOKEN) { | ||
const runners = []; | ||
if (getMust("MATRIX_ACCESS_TOKEN")) { | ||
runners.push(require("./src/matrix")); | ||
} | ||
if (process.env.DISCORD_BOT_TOKEN) { | ||
if (getMust("DISCORD_BOT_TOKEN")) { | ||
runners.push(require("./src/discord")); | ||
} | ||
|
||
Promise.all(runners.map( | ||
(runner) => runner(), | ||
)).then(() => { | ||
console.info("Nymph 系統 成功啟動"); | ||
}).catch((e) => { | ||
console.error("Nymph 系統 啟動失敗:", e); | ||
}); | ||
(async () => { | ||
await prepare(); | ||
await Promise.all(runners.map( | ||
(runner) => runner(), | ||
)).then(() => { | ||
console.info("Nymph 系統 成功啟動"); | ||
}).catch((e) => { | ||
console.error("Nymph 系統 啟動失敗:", e); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +0,0 @@ | ||
"use strict"; | ||
|
||
require("dotenv").config(); | ||
|
||
const { | ||
createClient, | ||
} = require("matrix-js-sdk"); | ||
|
||
const { | ||
MATRIX_HOMESERVER: homeserverUrl, | ||
MATRIX_USERNAME: username, | ||
MATRIX_PASSWORD: password, | ||
} = process.env; | ||
|
||
console.info( | ||
"Get the AccessToken from Matrix", | ||
`(homeserver: ${homeserverUrl || "undefined"})`, | ||
"\n", | ||
); | ||
|
||
const client = createClient({baseUrl: homeserverUrl}); | ||
client.login("m.login.password", { | ||
identifier: { | ||
type: "m.id.user", | ||
user: username, | ||
}, | ||
password, | ||
}).then((response) => { | ||
console.info("UserId:", response.user_id); | ||
console.info("AccessToken:", response.access_token); | ||
}).catch((e) => { | ||
console.error("Unauthorized", e); | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"ignore": [ | ||
"data" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
// mongoose is an ODM library for MongoDB. | ||
|
||
// Import config | ||
const {getMust} = require("../config"); | ||
|
||
// Import mongoose | ||
const database = require("mongoose"); | ||
|
||
// Configure mongose | ||
database.set("strictQuery", true); | ||
|
||
// Connect to MongoDB | ||
exports.prepare = () => | ||
database.connect(getMust("MONGODB_URI")); | ||
|
||
// Export as useFunction | ||
exports.useDatabase = () => database; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.