Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master' into stt
Browse files Browse the repository at this point in the history
  • Loading branch information
glorat committed Feb 9, 2019
2 parents 51282c1 + 4dcd882 commit a83612b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
29 changes: 29 additions & 0 deletions Dockerfile
@@ -0,0 +1,29 @@
FROM node:10-alpine
RUN apk update && apk add wget git jq bash && rm -rf /var/cache/apk/*

WORKDIR /usr/src/gotbot
COPY *.json ./
COPY client client
COPY lib lib
COPY test test
COPY *.ts ./

COPY run ./
COPY gotcron ./

RUN mkdir logs && mkdir data && mkdir client/stt.wiki

RUN chown -R node:node .

RUN chmod -R 777 data

VOLUME /usr/src/gotbot/data

USER node

EXPOSE 3030

RUN npm install
RUN node_modules/typescript/bin/tsc

CMD ./run
4 changes: 2 additions & 2 deletions config.ts
Expand Up @@ -2,8 +2,8 @@ const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
const isTest = nodeEnv === 'test';

let password = isTest ? {prod:'',dev:''} : require('./data/password');
let dataPath = isTest ? './test-data/': './data/';
let dataPath = require('path').resolve(isTest ? './test-data/': './data/')+'/';
let password = isTest ? {prod:'',dev:''} : require(dataPath + 'password');

export default class Config {

Expand Down
21 changes: 21 additions & 0 deletions lib/index.ts
Expand Up @@ -179,3 +179,24 @@ bot.login(cfg.token).then(() => {
console.log('Failed to connect to discord:\n ' + e);
// Now what? In debug, we continue on since the webserver can work...
});

// Schedule the gotcron
const schedule = require('node-schedule');
let crontab = '45 1,5,9,13,17,21 * * *';

console.log(`Scheduling gotcron at ${crontab}`);

schedule.scheduleJob(crontab, function(){
console.log('Running gotcron');
const { spawn } = require('child_process');
const fs = require('fs');

const got = spawn('./gotcron');
got.stdout.pipe(fs.createWriteStream(cfg.dataPath+'logs/gotcron.log', {flags: 'a'}));

got.on('close', (code:any) => {
console.log(`gotcron exited with exit code ${code}`);
console.log(`This process will also exit with ${code} to trigger restart`);
process.exit(code);
});
});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -70,6 +70,7 @@
"nedb": "^1.8.0",
"nedb-async": "0.0.5",
"node-fetch": "^2.3.0",
"node-schedule": "^1.3.1",
"request-json": "^0.6.1",
"underscore": "^1.8.3",
"winston": "^2.4.4"
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion tsconfig.json
Expand Up @@ -62,7 +62,6 @@
"test/**/*/",
"*.ts",
"package.json",
"data/password.js",
"client/*.js"
]
}

0 comments on commit a83612b

Please sign in to comment.