Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sapphire rewrite #5

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DISCORD_TOKEN=
DEFAULT_PREFIX=!
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
lib-cov
*.seed
*.log
Expand Down
80 changes: 80 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ================ #
# Base Stage #
# ================ #

FROM node:16-buster-slim as base

WORKDIR /opt/app

ENV HUSKY=0
ENV CI=true

RUN apt-get update && \
apt-get upgrade -y --no-install-recommends && \
apt-get install -y --no-install-recommends build-essential python3 libfontconfig1 dumb-init && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# ------------------------------------ #
# Conditional steps for end-users #
# ------------------------------------ #

COPY --chown=node:node yarn.lock .

ENV NODE_OPTIONS="--enable-source-maps"

# ---------------------------------------- #
# End Conditional steps for end-users #
# ---------------------------------------- #

COPY --chown=node:node package.json .
COPY --chown=node:node tsconfig.json .

RUN sed -i 's/"prepare": "husky install\( .github\/husky\)\?"/"prepare": ""/' ./package.json

ENTRYPOINT ["dumb-init", "--"]

# =================== #
# Development Stage #
# =================== #

# Development, used for development only (defaults to watch command)
FROM base as development

ENV NODE_ENV="development"

USER node

CMD [ "npm", "run", "docker:watch"]

# ================ #
# Builder Stage #
# ================ #

# Build stage for production
FROM base as build

RUN npm install

COPY . /opt/app

RUN npm run build

# ==================== #
# Production Stage #
# ==================== #

# Production image used to run the bot in production, only contains node_modules & dist contents.
FROM base as production

ENV NODE_ENV="production"

COPY --from=build /opt/app/dist /opt/app/dist
COPY --from=build /opt/app/node_modules /opt/app/node_modules
COPY --from=build /opt/app/package.json /opt/app/package.json

RUN chown node:node /opt/app/

USER node

CMD [ "npm", "run", "start"]
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

Copyright (C) 2021 NewCircuit
Copyright (C) 2022 FG-Devs

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -651,7 +651,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

Suggestions Bot Copyright (C) 2021 NewCircuit
Suggestions Bot Copyright (C) 2021-2022 FG-Devs
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
7 changes: 0 additions & 7 deletions README.md

This file was deleted.

10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.9"

services:
suggestions-bot:
build:
context: .
target: development
env_file: .env
volumes:
- ./:/opt/app
54 changes: 28 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
{
"name": "suggestions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "tsc && node build/."
},
"keywords": [],
"author": "NewCircuit <https://github.com/NewCircuit>",
"main": "src/index.ts",
"repository": "[email protected]:fg-devs/suggestions.git",
"author": "Matthew Bakhtiari <[email protected]>",
"license": "GPL-3.0",
"dependencies": {
"@types/concat-stream": "^1.6.0",
"@types/js-yaml": "^3.12.5",
"@types/pg": "^7.14.5",
"@types/request": "^2.48.5",
"concat-stream": "^2.0.0",
"discord.js": "^12.3.1",
"discord.js-commando": "github:discordjs/Commando",
"js-yaml": "^3.14.0",
"pg": "^8.3.3",
"request": "^2.88.2"
"scripts": {
"start": "tsc && node dist/index.js"
},
"devDependencies": {
"@types/node": "^14.10.1",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "^7.21.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"typescript": "^4.2.3"
"@sapphire/ts-config": "^3.3.3",
"@types/node": "^17.0.23",
"@types/ws": "^8.5.3",
"prisma": "^3.11.1",
"ts-node": "^10.7.0",
"typescript": "^4.6.2"
},
"dependencies": {
"@discordjs/collection": "^0.5.0",
"@sapphire/decorators": "^4.3.3",
"@sapphire/discord-utilities": "^2.10.2",
"@sapphire/discord.js-utilities": "^4.9.3",
"@sapphire/fetch": "^2.3.0",
"@sapphire/framework": "^3.0.0-next.0ea9553.0",
"@sapphire/plugin-api": "^3.2.0",
"@sapphire/plugin-editable-commands": "^1.2.0",
"@sapphire/plugin-logger": "^2.2.0",
"@sapphire/plugin-subcommands": "^2.2.0",
"@sapphire/time-utilities": "^1.7.3",
"@sapphire/type": "^2.2.0",
"@sapphire/utilities": "^3.6.1",
"discord.js": "^13.6.0",
"dotenv": "^16.0.0"
}
}
66 changes: 0 additions & 66 deletions pg.sql

This file was deleted.

11 changes: 11 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
21 changes: 21 additions & 0 deletions src/commands/General/ping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Command, CommandOptions, PieceContext } from '@sapphire/framework';
import type { Message } from 'discord.js';

export class UserCommand extends Command {
public constructor(context: PieceContext, options: CommandOptions) {
super(context, {
...options,
description: 'ping pong'
});
}

public async messageRun(message: Message) {
const msg = await message.channel.send('Ping?');

return msg.edit(
`Pong from Docker! Bot Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${
msg.createdTimestamp - message.createdTimestamp
}ms.`
);
}
}
Loading