Skip to content

Commit

Permalink
move to Dockerfile setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Epic428 committed Nov 21, 2023
1 parent 9553373 commit e978d9c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish
on:
workflow_dispatch:
branches:
- master
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: mr-smithers-excellent/docker-build-push@v6
with:
image: Team-Resourceful/discord-bot-ts
registry: ghcr.io
githubOrg: Team-Resourceful # optional
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1

FROM node:18.16-alpine
ENV NODE_ENV=production
WORKDIR /app
COPY ["package.json", "package-lock.json*", "./"]
RUN npm install --production
COPY . .
CMD ["npm", "run", "no-build-start"]
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { token } from "../configs/config.json";
//import { token } from "../configs/config.json";
import {Client, GatewayIntentBits} from "discord.js";
import { Interactions } from "./utils/interactions";
import {Commands} from "./utils/commands";
import * as process from "process";

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages] });
const interactions = new Interactions(client);
Expand All @@ -10,7 +11,11 @@ const commands = new Commands();
const getCommands = () => commands;
const getInteractions = () => interactions;

client.login(token);
if (!process.env.DISCORD_TOKEN) {
throw new Error("DISCORD_TOKEN environment variable missing.")
}

client.login(process.env.DISCORD_TOKEN);

export { getInteractions }
export { getCommands }
Expand Down
4 changes: 3 additions & 1 deletion src/utils/commands.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Collection } from "discord.js";
import { Database } from "./database";
import { databaseOptions } from "../../configs/config.json";
import * as process from "process";

export class Commands {

private readonly database: Database;
private commands: Collection<string, Collection<string, string>>;

constructor() {
this.database = new Database(databaseOptions);
this.database = new Database(`{host: ${process.env.DB_HOST}, database: ${process.env.DB_NAME}, password: ${process.env.DB_PASSWORD}, port: ${process.env.DB_PORT}, user: ${process.env.DB_USER}}`);
this.commands = new Collection<string, Collection<string, string>>(Object.values(CommandType).map(type => [type, new Collection<string, string>()]));

this.database.connect()
.then(() => {
console.log("connected to database!")
for (let type of Object.values(CommandType)) {
this.database.query("SELECT `category`, `key`, `value` FROM `commands` WHERE `category` = ?", [type])
.then(async results => {
Expand Down

0 comments on commit e978d9c

Please sign in to comment.