Last active
February 24, 2016 06:22
-
-
Save AndreClaassen1/c632af798b4fb56d3d9e to your computer and use it in GitHub Desktop.
JavaScript for scheduling my gaming plan every day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ connect the day number with a main game. 0 = sunday | |
var mainGames = { | |
0: "XCOM 2", | |
1: "XCOM 2", | |
3: "The Witcher 3", | |
5: "XCOM 2" | |
} | |
var randomGames = [ | |
"Otherland", "The Secret World", "Otherland", "Elite Dangerous", | |
"Star Drive II", "Wildstar", "City Skylines", "Anno 2270", | |
"Predestination", "The Witcher 3", "Beyond Earth", "Civilization V", | |
"The Elder Scrolls Online", "Pillars of Destiny", "Thea - The Awakening" | |
]; | |
function selectRandomGame() { | |
var n = randomGames.length | |
var i = Math.floor(Math.random() * n); | |
return randomGames[i] | |
} | |
function selectMainGame() { | |
var date = new Date() | |
var day = date.getDay() | |
return mainGames[day] | |
} | |
function ISODateString(d){ | |
function pad(n){return n<10 ? '0'+n : n} | |
return d.getUTCFullYear()+'-' | |
+ pad(d.getUTCMonth()+1)+'-' | |
+ pad(d.getUTCDate()) | |
} | |
function ISODateTimeString(d){ | |
function pad(n){return n<10 ? '0'+n : n} | |
return d.getUTCFullYear()+'-' | |
+ pad(d.getUTCMonth()+1)+'-' | |
+ pad(d.getUTCDate())+'T' | |
+ pad(d.getUTCHours())+':' | |
+ pad(d.getUTCMinutes())+':' | |
+ pad(d.getUTCSeconds())+'Z' | |
} | |
function createGamingEvent(agent, maingame, randomgame) { | |
var today = new Date(); | |
var day = today.getDate(); | |
var month = today.getMonth(); | |
var year = today.getFullYear(); | |
var dayOfTheWeek = today.getDay() | |
// normally, I train on Sunday (day 0 ) at 10 | |
var startHour = dayOfTheWeek == 0 ? 15 : 19 | |
var endHour = startHour + 1 | |
var startDateTime = new Date(year, month, day, startHour, 0, 0, 0) | |
var endDateTime = new Date(year, month, day, endHour, 0, 0, 0) | |
var description = "" | |
if (maingame == null) { | |
description = "Your game for tonigh was selected: \n\n"+ | |
"**** " + randomgame + "****\n\n" + | |
"Have fun!" | |
} else { | |
description = "Please continue your main game: \n\n" + | |
"**** " + maingame + "****\n\n" + | |
"If you have enough time and I assume you haven't, play this game: \n\n" + | |
">>>> " + randomgame + "<<<<\n\n" + | |
"Have fun with both games!" | |
} | |
agent.createEvent({ 'message': | |
{ 'summary': "Dein Spiel für den Spieleabend wurde definiert", | |
'visibility': 'default', | |
'description': description, | |
'start': { | |
'dateTime': ISODateTimeString(startDateTime) | |
}, | |
'end': { | |
'dateTime': ISODateTimeString(endDateTime) | |
} | |
} | |
}); | |
} | |
Agent.check = function() { | |
var maingame = selectMainGame() | |
var randomgame = selectRandomGame() | |
this.log("Maingame: "+maingame) | |
this.log("Random Game: "+randomgame) | |
createGamingEvent(this, maingame, randomgame) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment