Skip to content

Commit

Permalink
shutdown command will now be called called by the daemon until shutdo…
Browse files Browse the repository at this point in the history
…wn occurs. fixed error in month calculation of timehelper.
  • Loading branch information
shukriadams committed Jan 22, 2018
1 parent 7bd6a1b commit 5e85d11
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let codes = require('./codes'),
path = require('path'),
fs = require('fs'),
State = require('./state'),
timeHelper = require('./timeHelper'),
Settings = require('./settings');

class Bot{
Expand Down Expand Up @@ -128,7 +129,7 @@ class Bot{
let store = await Store.instance();
await store.close();

console.log(`Bot lifetime (${this.settings.values.processLifetime}m) expired. Exiting now, this is not an error.`);
console.log(`Bot lifetime (${this.settings.values.processLifetime}m) expired. Exiting now (${timeHelper.toShortDateTimeString(new Date())}), this is not an error.`);
process.exitCode = 0;
process.exit();
}
Expand All @@ -140,7 +141,6 @@ class Bot{
async _onMessage(message){
return new Promise(async function(resolve, reject){
try {

this.busyProcessingMessage = true;

// reject messages @bot (these are public messages), unless message is to set "channel"
Expand Down
8 changes: 5 additions & 3 deletions lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class Daemon {
try
{
// use busy flag to prevent the daemon from running over itself
if (busy || this.willShutdown)
if (this.willShutdown)
return this.onProcessExpired();

if (busy)
return;

busy = true;
Expand Down Expand Up @@ -268,8 +271,7 @@ class Daemon {
if (settings.values.processLifetime && this.onProcessExpired){
let shouldExpire = timeHelper.minutesSince(this.started) >= settings.values.processLifetime;
if (shouldExpire){
this.willShutdown = true;
this.onProcessExpired();
this.willShutdown = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/timeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
if (typeof datetime === 'number')
datetime = new Date(datetime);

return `${datetime.getFullYear()}/${datetime.getMonth()}/${datetime.getDate()} ${datetime.toLocaleTimeString()}`;
return `${datetime.getFullYear()}/${datetime.getMonth() + 1}/${datetime.getDate()} ${datetime.toLocaleTimeString()}`;
},

// returns formatted date string for the time + minutes.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-giveawaybot",
"version": "0.1.3",
"version": "0.1.4",
"description": "A Discord bot that gives games away.",
"private": false,
"author": "[email protected]",
Expand Down

0 comments on commit 5e85d11

Please sign in to comment.