From d04284e054a1ca1825e43b77e1f2f13ede0d3837 Mon Sep 17 00:00:00 2001 From: Yami Date: Wed, 12 Apr 2017 19:22:41 +0000 Subject: [PATCH 1/4] feature: add view helper to format global datetime link --- src/viewHelper.js | 4 ++++ test/unitTests.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/viewHelper.js b/src/viewHelper.js index 78e40d2..bbbbdf0 100644 --- a/src/viewHelper.js +++ b/src/viewHelper.js @@ -68,5 +68,9 @@ module.exports = { const parts = relative.split(' '); const timestamp = new Moment().add(parts[0], parts[1]); return timestamp.utc().format('MMM Do [at] HH:mm [UTC]'); + }, + + getDateTimeLink: function(time) { + return `https://www.timeanddate.com/worldclock/fixedtime.html?year=${time.year()}&month=${time.format('MMM')}&day=${time.date()}&hour=${time.hour()}&min=${time.minutes()}&sec=${time.seconds()}`; } }; diff --git a/test/unitTests.js b/test/unitTests.js index 94ecfb6..4836c2e 100644 --- a/test/unitTests.js +++ b/test/unitTests.js @@ -1344,4 +1344,24 @@ describe('viewHelper', () => { it('should work for hours', () => viewHelper.relativeToAbsoluteTime('1 hour').should.equal('Jan 1st at 01:00 UTC')); it('should work for days', () => viewHelper.relativeToAbsoluteTime('1 day').should.equal('Jan 2nd at 00:00 UTC')); }); + + describe('globalDateTimeLink', () => { + //https://www.timeanddate.com/worldclock/fixedtime.html?year=&month=&day=&hour=&min=&sec=0 + let clock; + + beforeEach(() => { + //Set Date to unix epoch (0) + clock = sinon.useFakeTimers(); + }); + + afterEach(() => { + clock.restore(); + }); + + it('should return a string', () => viewHelper.getDateTimeLink(new Moment()).should.be.a('string')); + it('should contain a hyperlink', () => viewHelper.getDateTimeLink(new Moment()).should.contain('https://www.timeanddate.com/worldclock/fixedtime.html')); + it('should return the date passed in', () => viewHelper.getDateTimeLink(new Moment()).should.equal('https://www.timeanddate.com/worldclock/fixedtime.html?year=1970&month=Jan&day=1&hour=0&min=0&sec=0')); + it('should return the date passed in 2', () => viewHelper.getDateTimeLink(new Moment().add(7, 'days')).should.equal('https://www.timeanddate.com/worldclock/fixedtime.html?year=1970&month=Jan&day=8&hour=0&min=0&sec=0')); + }); + }); From 28e6f6eb85a0e8b10254ccb3decc165d030185ae Mon Sep 17 00:00:00 2001 From: Yami Date: Thu, 13 Apr 2017 13:18:01 +0000 Subject: [PATCH 2/4] feature: Add timestamps to outgoing messages using the link functionality --- src/autoGM.js | 20 +++++++++++++------- test/unitTests.js | 9 ++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/autoGM.js b/src/autoGM.js index 967b004..3f7d124 100644 --- a/src/autoGM.js +++ b/src/autoGM.js @@ -174,7 +174,7 @@ exports.createGame = function() { internals.game = g; }) .then(() => internals.game.addModerator(internals.myName)) - .then(() => internals.forum.Post.reply(threadID, undefined, 'Signups are now open!\n To join the game, please type `!join`.\n The game will start in ' + internals.config.phases.init)) + .then(() => internals.forum.Post.reply(threadID, undefined, 'Signups are now open!\n To join the game, please type `!join`.\n The game will start on ' + formatTimeLink(internals.config.phases.init))) .then(() => exports.setTimer(internals.config.phases.init, exports.startGame)); }; @@ -231,6 +231,12 @@ exports.postFlip = function postFlip(username, type) { return internals.forum.Post.reply(internals.game.topicId, undefined, message); }; +function formatTimeLink(offset) { + const timeString = viewHelper.relativeToAbsoluteTime(offset); + const time = Moment(timeString, 'MMM Do [at] HH:mm [UTC]'); + return `${timeString}`; +} + exports.startGame = function startGame() { debug('Running game start routine'); const players = internals.game.livePlayers; @@ -280,9 +286,9 @@ exports.startGame = function startGame() { internals.game.addChat(chatroom.id); }) .then(() => internals.forum.Post.reply(internals.game.topicId, undefined, flavorText[internals.flavor].openingScene)) - .then(() => internals.forum.Post.reply(internals.game.topicId, undefined, 'Let the game begin! It is now day. The day will end in ' + internals.config.phases.day)) + .then(() => internals.forum.Post.reply(internals.game.topicId, undefined, 'Let the game begin! It is now day. The day will end on ' + formatTimeLink(internals.config.phases.day))) .then(() => exports.setTimer(internals.config.phases.day, exports.onDayEnd)) - .then(() => internals.game.setValue('phaseEnd', viewHelper.relativeToAbsoluteTime(internals.config.phases.day))) + .then(() => internals.game.setValue('phaseEnd', formatTimeLink(internals.config.phases.day))) .catch((err) => { debug(err); return internals.forum.Post.reply(internals.game.topicId, undefined, ':wtf: Sorry folks, I need to cancel this one; I\'ve hit an error. \n Error was: ' + err) @@ -300,9 +306,9 @@ exports.startGame = function startGame() { exports.onDayEnd = function onDayEnd() { debug('running Day End routine'); return internals.game.nextPhase() - .then(() => internals.forum.Post.reply(internals.game.topicId, undefined, 'It is now night. Night will end in ' + internals.config.phases.night)) + .then(() => internals.forum.Post.reply(internals.game.topicId, undefined, 'It is now night. Night will end on ' + formatTimeLink(internals.config.phases.night))) .then(() => exports.setTimer(internals.config.phases.night, exports.onNightEnd)) - .then(() => internals.game.setValue('phaseEnd', viewHelper.relativeToAbsoluteTime(internals.config.phases.night))); + .then(() => internals.game.setValue('phaseEnd', formatTimeLink(internals.config.phases.night))); }; exports.onLynch = function(username) { @@ -359,7 +365,7 @@ exports.onNightEnd = function onNightEnd() { } else { return internals.game.newDay() .then(() => internals.forum.Post.reply(internals.game.topicId, undefined, - 'It is now day. Day will end in ' + internals.config.phases.day)) + 'It is now day. Day will end on ' + formatTimeLink(internals.config.phases.day))) .then(() => { if (warn) { return internals.forum.Post.reply(internals.game.topicId, undefined, @@ -367,7 +373,7 @@ exports.onNightEnd = function onNightEnd() { } }) .then(() => exports.setTimer(internals.config.phases.day, exports.onDayEnd)) - .then(() => internals.game.setValue('phaseEnd', viewHelper.relativeToAbsoluteTime(internals.config.phases.day))); + .then(() => internals.game.setValue('phaseEnd', formatTimeLink(internals.config.phases.day))); } }); }; diff --git a/test/unitTests.js b/test/unitTests.js index 4836c2e..22da2ea 100644 --- a/test/unitTests.js +++ b/test/unitTests.js @@ -495,9 +495,10 @@ describe('AutoGM', () => { AutoGM.internals.game.livePlayers = [player('one'), player('two'), player('three'), player('four'), player('five'), player('six')]; sandbox.spy(AutoGM.internals.game, 'setValue'); sandbox.stub(viewHelper, 'relativeToAbsoluteTime').returns('Jan 1st at 2pm'); + sandbox.stub(viewHelper, 'getDateTimeLink').returns('a_hyperlink'); return AutoGM.startGame().then(() => { - AutoGM.internals.game.setValue.should.have.been.calledWith('phaseEnd', 'Jan 1st at 2pm'); + AutoGM.internals.game.setValue.should.have.been.calledWith('phaseEnd', 'Jan 1st at 2pm'); }); }); @@ -645,10 +646,11 @@ describe('AutoGM', () => { sandbox.stub(AutoGM, 'setTimer').resolves(); sandbox.spy(AutoGM.internals.game, 'setValue'); sandbox.stub(viewHelper, 'relativeToAbsoluteTime').returns('Jan 1st at 2pm'); + sandbox.stub(viewHelper, 'getDateTimeLink').returns('a_hyperlink'); return AutoGM.onDayEnd().then(() => { - AutoGM.internals.game.setValue.should.have.been.calledWith('phaseEnd', 'Jan 1st at 2pm'); + AutoGM.internals.game.setValue.should.have.been.calledWith('phaseEnd', 'Jan 1st at 2pm'); }); }); }); @@ -750,11 +752,12 @@ describe('AutoGM', () => { sandbox.stub(AutoGM, 'checkWin').returns(false); sandbox.stub(AutoGM, 'setTimer').resolves(); sandbox.stub(viewHelper, 'relativeToAbsoluteTime').returns('Jan 1st at 2pm'); + sandbox.stub(viewHelper, 'getDateTimeLink').returns('a_hyperlink'); sandbox.spy(AutoGM.internals.game, 'setValue'); return AutoGM.onNightEnd().then(() => { - AutoGM.internals.game.setValue.should.have.been.calledWith('phaseEnd', 'Jan 1st at 2pm'); + AutoGM.internals.game.setValue.should.have.been.calledWith('phaseEnd', 'Jan 1st at 2pm'); }); }); From 43526c330d64debf6e8c3f32e706d4a62e9d285a Mon Sep 17 00:00:00 2001 From: Yami Date: Thu, 13 Apr 2017 15:20:44 +0000 Subject: [PATCH 3/4] chore: bump dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ce9de3..841ad83 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "handlebars": "^4.0.5", "moment": "^2.14.1", "rimraf-promise": "^2.0.0", - "sockmafia": "sockdrawer/SockMafia" + "sockmafia": ">=4.0.2" }, "peerDependencies": { "sockbot": "^4.11.0" From 7dd21ac056c2352d9ee95ee5b9ebb9bd91e31b17 Mon Sep 17 00:00:00 2001 From: Yami Date: Thu, 13 Apr 2017 19:39:56 +0000 Subject: [PATCH 4/4] chore: bump version, update travis --- .travis.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d32bed..402c5f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: node_js node_js: -- '4' - '5' - '6' +- '7' env: global: service_name: travis-ci diff --git a/package.json b/package.json index 841ad83..4bc62f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sockmafia-autogm", - "version": "1.0.0", + "version": "1.1.0", "description": "Auto gamemaster for sockmafia", "main": "src/autoGM.js", "directories": {