Skip to content

Commit

Permalink
Merge branch 'api' of https://github.com/tripsit/TripBot into api
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Dec 15, 2023
2 parents 187ed63 + 03e0289 commit 00aad0e
Show file tree
Hide file tree
Showing 32 changed files with 71,889 additions and 35,007 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37,200 changes: 37,200 additions & 0 deletions assets/data/drug_db_psychonaut.json

Large diffs are not rendered by default.

34,437 changes: 34,437 additions & 0 deletions assets/data/drug_db_tripsit.json

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added assets/font/Futura.otf
Binary file not shown.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ services:
- tripbot_website-net
- moodle_data-net
volumes:
- ./assets:/usr/src/app/assets # Needed for hot-reloading of source code
- ./src:/usr/src/app/src # Needed for hot-reloading of source code
- ./.env:/usr/src/app/.env # Needed for hot-reloading the .env
labels:
Expand All @@ -57,8 +58,7 @@ services:
- traefik.http.routers.tripbot.service=tripbot
- traefik.http.routers.tripbot.entrypoints=websecure
- traefik.http.routers.tripbot.tls=true
- traefik.http.routers.tripbot.middlewares=tripbot@file

- traefik.http.routers.tripbot.middlewares=tripbot@file,redirectApi@file

tripbot_database:
<<: *common-keys-apps
Expand Down
322 changes: 162 additions & 160 deletions src/api/apiV1/drugs/drugs.queries.ts

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/api/apiV1/drugs/drugs.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const limiter = RateLimit({
// apply rate limiter to all requests
router.use(limiter);

// getInteraction
// getInteraction - readme
router.get('/getInteraction', (req, res) => {
res.json({
endpoint: 'getInteraction',
Expand All @@ -28,6 +28,8 @@ router.get('/getInteraction', (req, res) => {
example: '/getInteraction/DXM/MDMA',
});
});

// getInteraction - function
router.get('/getInteraction/:drugAName/:drugBName', async (req, res, next) => {
const { drugAName, drugBName } = req.params;
// console.log('drugAName', drugAName);
Expand All @@ -49,7 +51,7 @@ router.get('/getInteraction/:drugAName/:drugBName', async (req, res, next) => {
}
});

// getDrug
// getDrug - readme
router.get('/getDrug', (req, res) => {
res.json({
endpoint: 'getDrug',
Expand All @@ -59,6 +61,8 @@ router.get('/getDrug', (req, res) => {
example: '/getDrug/DXM',
});
});

// getDrug - function
router.get('/getDrug/:name', async (req, res, next) => {
const { name } = req.params;
// log.debug(F, `name: ${name}`);
Expand Down Expand Up @@ -104,6 +108,7 @@ router.get('/getAllDrugNamesByCategory', (req, res) => {
example: '/getAllDrugNamesByCategory/stimulants',
});
});

router.get('/getAllDrugNamesByCategory/:category', async (req, res, next) => {
const { category } = req.params;
// console.log('category', category);
Expand Down
51 changes: 41 additions & 10 deletions src/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,51 @@ app.set('trust proxy', 2);
// Simple IP return to test reverse proxy and "hello world" the api
app.get('/api/ip', (request, response) => response.send(request.ip));

app.get('/', (req, res) => {
res.json({
message: 'This is TripBot`s API',
});
});

app.get('/api', (req, res) => {
res.json({
welcome: 'Welcome to TripSit\'s API endpoint.',
description: 'You likely want one of the below endpoints.',
development: 'Interested in helping out? Join the https://discord.gg/tripsit chat and ask for Moonbear.',
endpoints: [
'/tripsit',
],
development: 'Interested in helping out?',
discord: 'Join the discord https://discord.gg/tripsit and check out the development rooms.',
github: 'Check out the code on the github: https://github.com/TripSit/TripBot/tree/main/src/api',
endpoints: {
'/tripsit': {
description: 'TripSit\'s original API, preserved for legacy purposes.',
endpoints: [
'/getInteraction',
'/getDrug',
'/getAllDrugNames',
'/getAllDrugNamesByCategory',
'/getAllDrugs',
'/getAllCategories',
'/getAllDrugAliases',
],
},
'/v1': {
description: 'Same as /tripsit, just renamed to v1 for consistency.',
endpoints: [
'/getInteraction',
'/getDrug',
'/getAllDrugNames',
'/getAllDrugNamesByCategory',
'/getAllDrugs',
'/getAllCategories',
'/getAllDrugAliases',
],
},
'/v2': {
description: 'TripSit\'s new API, under active development.',
warning: 'This does not work, don\'t use it',
endpoints: [
'/drugs',
'/interactions',
'/combinations',
'/categories',
'/aliases',
'/search',
],
},
},
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/discord/commands/guild/d.leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { resizeText, deFuckifyText, colorDefs } from '../../utils/canvasUtils';
const F = f(__filename);

Canvas.GlobalFonts.registerFromPath(
path.resolve(__dirname, '../../assets/Futura.otf'),
path.resolve(__dirname, '../../../../assets/font/Futura.otf'),
'futura',
);

Expand Down
2 changes: 1 addition & 1 deletion src/discord/commands/guild/d.levels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type LevelData = {
};

Canvas.GlobalFonts.registerFromPath(
path.resolve(__dirname, '../../assets/Futura.otf'),
path.resolve(__dirname, '../../../../assets/font/Futura.otf'),
'futura',
);

Expand Down
5 changes: 4 additions & 1 deletion src/discord/commands/guild/d.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { resizeText, deFuckifyText, colorDefs } from '../../utils/canvasUtils';
const F = f(__filename);

Canvas.GlobalFonts.registerFromPath(
path.resolve(__dirname, '../../assets/Futura.otf'),
path.resolve(__dirname, '../../../assets/font/Futura.otf'),
'futura',
);

Expand Down Expand Up @@ -60,6 +60,9 @@ export const dProfile: SlashCommand = {
interaction,
) {
log.info(F, await commandContext(interaction));

const test = path.resolve(__dirname, '../../../assets/font/Futura.otf');
log.debug(F, `Path ${test}`);
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
const startTime = Date.now();
if (!interaction.guild) {
Expand Down
12 changes: 6 additions & 6 deletions src/discord/events/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
import Fuse from 'fuse.js';

import { PrismaClient, ai_model } from '@prisma/client';
import pillColors from '../../global/assets/data/pill_colors.json';
import pillShapes from '../../global/assets/data/pill_shapes.json';
import drugDataAll from '../../global/assets/data/drug_db_combined.json';
import drugDataTripsit from '../../global/assets/data/drug_db_tripsit.json';
import timezones from '../../global/assets/data/timezones.json';
import unitsOfMeasurement from '../../global/assets/data/units_of_measurement.json';
import pillColors from '../../../assets/data/pill_colors.json';
import pillShapes from '../../../assets/data/pill_shapes.json';
import drugDataAll from '../../../assets/data/drug_db_combined.json';
import drugDataTripsit from '../../../assets/data/drug_db_tripsit.json';
import timezones from '../../../assets/data/timezones.json';
import unitsOfMeasurement from '../../../assets/data/units_of_measurement.json';

const db = new PrismaClient({ log: ['error'] });

Expand Down
111 changes: 0 additions & 111 deletions src/docker/Dockerfile.api

This file was deleted.

13 changes: 7 additions & 6 deletions src/docker/Dockerfile.tripbot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# We stop at the end of this step in development, so it also includes the deploy command
# We install jest, eslint and ts-node so we can run tests and lint.

FROM node:21.1.0-alpine AS development
FROM node:21.4.0-alpine AS development

ENV NODE_ENV=development
RUN date
Expand All @@ -20,7 +20,7 @@ RUN npm install @napi-rs/canvas-linux-x64-musl
RUN npm install -g --save-dev jest ts-node eslint pm2

# We need to copy this asset over so that the bot can use it
COPY --chown=node:node ./src/discord/assets/Futura.otf ./build/discord/assets/Futura.otf
# COPY --chown=node:node ./src/discord/assets/Futura.otf ./build/discord/assets/Futura.otf

# Do all of the above first so that the layers can run faster next time

Expand All @@ -46,9 +46,10 @@ RUN npx prisma generate --schema=./src/prisma/moodle/schema.prisma
# Deploy the commands
# RUN npx ts-node --transpile-only ./src/discord/utils/commandDeploy.ts

# For container development, the following command runs forever, so we can inspect the container
CMD npx prisma migrate deploy && npx tsc-watch --onSuccess "npx nodemon --config ./nodemon.json"
# CMD npx tsc-watch --onSuccess "npx nodemon --config ./nodemon.json"

# For container development, the following command runs forever, so we can inspect the container
# CMD tail -f /dev/null

###################
# BUILD FOR PRODUCTION
Expand All @@ -59,7 +60,7 @@ CMD npx prisma migrate deploy && npx tsc-watch --onSuccess "npx nodemon --config
# We run the build command which creates the production bundle
# We run npm ci --only=production to ensure that only the production dependencies are installed

FROM node:21.1.0-alpine AS build
FROM node:21.4.0-alpine AS build

ENV NODE_ENV=production
RUN date
Expand Down Expand Up @@ -98,7 +99,7 @@ RUN npm ci --omit:dev && npm cache clean --force
# Then we ONLY copy over the /build folder with the js files
# We already deployed before, so the only thing left to do is run the bot with PM2

FROM node:21.1.0-alpine AS production
FROM node:21.4.0-alpine AS production

ENV NODE_ENV=production
RUN date
Expand Down
Loading

0 comments on commit 00aad0e

Please sign in to comment.