diff --git a/.env.example b/.env.example index a5cfa00db..a4ee9aee0 100644 --- a/.env.example +++ b/.env.example @@ -10,26 +10,22 @@ PRISMA_DB_URL = postgres://tripsit:SuperSecure123@tripbot_database:5432/tripsit POSTGRES_DB_URL = postgres://tripsit:SuperSecure123@tripbot_database:5432/tripsit # REQUIRED Database password -# This shold be the same as the PRISMA_DB_URL and POSTGRS_DB_URL passwords +# This should be the same as the PRISMA_DB_URL and POSTGRS_DB_URL passwords POSTGRESQL_PASSWORD = SuperSecure123 -## Everything after this is OPTIONAL - # Keep as development NODE_ENV = development # Feel free to change -TIME_ZONE = "America/Chicago" TZ = "America/Chicago" # Used for docker COMPOSE_PROJECT_NAME = 'tripbot' -XID = 1000 -PUID = 1000 -PGID = 1000 + +#### Everything after this is OPTIONAL #### # Domains -DNS_DOMAIN = localhost +DNS_DOMAIN = tripsit.io # PG Admin PGADMIN_PASSWORD = SuperSecure123 diff --git a/docker-compose.yml b/docker-compose.yml index 2631ab329..77140849e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,8 @@ name: tripsit-dev-apps # Common environment values x-environment: &default-tz-puid-pgid TZ: $TZ - PUID: $PUID - PGID: $PGID + PUID: 1000 + PGID: 1000 # Keys common to some of the core services that we always to automatically restart on failure x-common-keys-core: &common-keys-core @@ -46,8 +46,6 @@ services: volumes: - ./src:/usr/src/app/src # Needed for hot-reloading of source code - ./.env:/usr/src/app/.env # Needed for hot-reloading the .env - - /etc/timezone:/etc/timezone:ro - - /etc/localtime:/etc/localtime:ro labels: - com.centurylinklabs.watchtower.enable=false - traefik.enable=true @@ -91,7 +89,6 @@ services: - tripbot_database-net environment: <<: *default-tz-puid-pgid - TZ: America/Chicago PGADMIN_DEFAULT_EMAIL: admin@tripsit.me PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD} labels: @@ -144,12 +141,9 @@ services: - tripbot_redis-net volumes: - ./src:/usr/src/app/src # Needed for hot-reloading of source code - - /etc/timezone:/etc/timezone:ro - - /etc/localtime:/etc/localtime:ro environment: <<: *default-tz-puid-pgid PORT: 5000 - TZ: America/Chicago DATABASE_URL: postgres://tripsit:${POSTGRESQL_PASSWORD}@tripbot_database:5432/tripsit labels: - com.centurylinklabs.watchtower.enable=false diff --git a/src/docker/Dockerfile.tripbot b/src/docker/Dockerfile.tripbot index 5763d0816..c7f19c4d2 100644 --- a/src/docker/Dockerfile.tripbot +++ b/src/docker/Dockerfile.tripbot @@ -7,7 +7,6 @@ FROM node:21.1.0-alpine AS development -ENV TZ="America/Chicago" ENV NODE_ENV=development RUN date @@ -62,7 +61,6 @@ CMD npx prisma migrate deploy && npx tsc-watch --onSuccess "npx nodemon --config FROM node:21.1.0-alpine AS build -ENV TZ="America/Chicago" ENV NODE_ENV=production RUN date @@ -102,7 +100,6 @@ RUN npm ci --omit:dev && npm cache clean --force FROM node:21.1.0-alpine AS production -ENV TZ="America/Chicago" ENV NODE_ENV=production RUN date diff --git a/src/global/commands/g.ai.ts b/src/global/commands/g.ai.ts index 6ee747b7c..3fb4e11a5 100644 --- a/src/global/commands/g.ai.ts +++ b/src/global/commands/g.ai.ts @@ -52,6 +52,9 @@ export async function aiModerateReport( // log.debug(F, `message: ${message}`); // log.debug(F, `results: ${JSON.stringify(results, null, 2)}`); + + if (!env.OPENAI_API_ORG || !env.OPENAI_API_KEY) return undefined; + return openai.moderations .create({ input: message, @@ -60,7 +63,6 @@ export async function aiModerateReport( if (err instanceof OpenAI.APIError) { log.error(F, `${err.status}`); // 400 log.error(F, `${err.name}`); // BadRequestError - log.error(F, `${err.headers}`); // {server: 'nginx', ...} } else { throw err; @@ -160,6 +162,9 @@ export default async function aiChat( // log.debug(F, `payload: ${JSON.stringify(payload, null, 2)}`); let responseMessage = {} as OpenAI.Chat.ChatCompletionMessageParam; + + if (!env.OPENAI_API_ORG || !env.OPENAI_API_KEY) return { response, promptTokens, completionTokens }; + const chatCompletion = await openai.chat.completions .create(payload) .catch(err => { diff --git a/src/global/utils/env.config.ts b/src/global/utils/env.config.ts index 4b92ba2ca..04edef132 100644 --- a/src/global/utils/env.config.ts +++ b/src/global/utils/env.config.ts @@ -21,8 +21,8 @@ export const env = { API_USERNAME: process.env.API_USERNAME, API_PASSWORD: process.env.API_PASSWORD, - OPENAI_API_ORG: process.env.OPENAI_API_ORG, - OPENAI_API_KEY: process.env.OPENAI_API_KEY, + OPENAI_API_ORG: process.env.OPENAI_API_ORG ?? '', + OPENAI_API_KEY: process.env.OPENAI_API_KEY ?? '', IRC_USERNAME: 'TripBot', IRC_PASSWORD: process.env.IRC_PASSWORD, diff --git a/src/global/utils/env.validate.ts b/src/global/utils/env.validate.ts index 83b6a198a..63837e1c4 100644 --- a/src/global/utils/env.validate.ts +++ b/src/global/utils/env.validate.ts @@ -13,14 +13,20 @@ export default function validateEnv( } if (service === 'DISCORD') { - if (!process.env.DISCORD_CLIENT_ID) { - log.error(F, stripIndents`Missing DISCORD_CLIENT_ID: You wont be able to login to discord. \ - You get this from the discord developer portal.`); + if (!process.env.DISCORD_GUILD_ID) { + log.error(F, stripIndents`Missing DISCORD_GUILD_ID: You get this from your discord guild. \ + It should be set by default to "960606557622657026"`); return false; } - if (!process.env.DISCORD_GUILD_ID) { - log.error(F, 'Missing DISCORD_GUILD_ID: You get this from your discord guild.'); + if (!process.env.DISCORD_OWNER_ID) { + log.warn(F, stripIndents`Missing DISCORD_OWNER_ID: Certain commands wont respond right, but nbd. \ + You get this from your own discord user.`); + } + + if (!process.env.DISCORD_CLIENT_ID) { + log.error(F, stripIndents`Missing DISCORD_CLIENT_ID: You wont be able to login to discord. \ + You get this from the discord developer portal.`); return false; } @@ -30,6 +36,24 @@ export default function validateEnv( return false; } + if (!process.env.PRISMA_DB_URL) { + log.error(F, stripIndents`Missing PRISMA_DB_URL: You wont be able to use the database via Prisma.\ + By default this should be set to 'postgres://tripsit:SuperSecure123@tripbot_database:5432/tripsit'.`); + return false; + } + + if (!process.env.POSTGRES_DB_URL) { + log.error(F, stripIndents`Missing POSTGRES_DB_URL: You wont be able to use the database via Knex.\ + By default this should be set to 'postgres://tripsit:SuperSecure123@tripbot_database:5432/tripsit'.`); + return false; + } + + if (!process.env.POSTGRESQL_PASSWORD) { + log.error(F, stripIndents`Missing POSTGRESQL_PASSWORD: You wont be able to use the database.\ + By default this should be set to 'SuperSecure123'.`); + return false; + } + // Check that the discord token is a valid token if (process.env.DISCORD_CLIENT_TOKEN === 'In your Discord Developer Portal') { log.error(F, `Welcome to TripBot. This is likely your first run, congrats on making it this far! @@ -50,12 +74,12 @@ export default function validateEnv( log.warn(F, 'Missing POSTGRES_DB_URL: You wont be able to use the database!'); } - if (!process.env.KEYCLOAK_BASE_URL - || !process.env.KEYCLOAK_REALM_NAME - || !process.env.KEYCLOAK_CLIENT_ID - || !process.env.KEYCLOAK_CLIENT_SECRET) { - log.warn(F, 'Missing keycloak credentials: You won\'t be able to interact with KeyCloak.'); - } + // if (!process.env.KEYCLOAK_BASE_URL + // || !process.env.KEYCLOAK_REALM_NAME + // || !process.env.KEYCLOAK_CLIENT_ID + // || !process.env.KEYCLOAK_CLIENT_SECRET) { + // log.warn(F, 'Missing keycloak credentials: You won\'t be able to interact with KeyCloak.'); + // } if (!process.env.GITHUB_TOKEN) { log.warn(F, 'Missing GITHUB_TOKEN: You wont be able to use /issue');