{"action":"created","comment":{"url":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/comments/204279870","pull_request_review_id":139329565,"id":204279870,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNDI3OTg3MA==","diff_hunk":"@@ -0,0 +1,152 @@\n+import fetch from \"node-fetch\";\n+import Discord = require(\"discord.js\");\n+import { SharedSettings } from \"./SharedSettings\";\n+import * as CheerioAPI from \"cheerio\";\n+import * as momentjs from \"moment\";\n+import Botty from \"./Botty\";\n+\n+interface ESportsAPIReturnData {\n+    resultsHtml: string;\n+    fixturesHtml: string;\n+    resultsMonths: string;\n+    fixturesMonths: string;\n+}\n+\n+interface ESportsLeagueSchedule {\n+    league: string;\n+    time: string;\n+    teamA: string;\n+    teamB: string;\n+}\n+\n+export default class ESportsAPI {\n+    private bot: Discord.Client;\n+    private settings: SharedSettings;\n+\n+    // Map<String, Map<String, ESportsLeagueSchedule>>\n+    private schedule: { [date: string]: { [league: string]: ESportsLeagueSchedule[] } } = {};\n+\n+    constructor(bot: Discord.Client, settings: SharedSettings) {\n+        this.bot = bot;\n+        this.settings = settings;\n+\n+        bot.on(\"ready\", async () => {\n+            await this.loadData();\n+            this.postInfo();\n+        });\n+    }\n+\n+    public onCheckNext(message: Discord.Message, isAdmin: boolean, command: string, args: string[]) {\n+        if (args.length !== 1) return;\n+\n+        // day / month\n+        const formatCheck = new RegExp(\"\\\\d\\\\d/\\\\d\\\\d\");\n+        if (!formatCheck.test(args[0])) return;\n+\n+        const data = args[0].split(\"/\");\n+        const date = `${data[0]} ${data[1]} ${new Date().getFullYear()}`;\n+\n+        this.sendPrintout(message.channel as Discord.TextChannel, this.schedule[date], date);\n+    }\n+\n+    private postInfo() {\n+        const esports = this.bot.guilds.get(this.settings.server)!.channels.find(\"name\", \"esports-spoilers\");\n+        if (!esports) {\n+            console.error(`Esports: Unable to find channel #esports-spoilers`);\n+            return;\n+        }\n+\n+        const now = new Date();\n+        const date = `${now.getDate()} ${(\"0\" + (now.getMonth() + 1)).slice(-2)} ${now.getFullYear()}`;\n+\n+        // filter old games\n+        const prints: { [league: string]: ESportsLeagueSchedule[] } = {};\n+        Object.keys(this.schedule[date]).forEach(league => {\n+            prints[league] = this.schedule[date][league].filter(e => e.time.indexOf(\"ago\") === -1);\n+        });\n+\n+        this.sendPrintout(esports as Discord.TextChannel, prints, date);\n+        setTimeout(this.postInfo, 3600000);\n+    }\n+\n+    private sendPrintout(channel: Discord.TextChannel, data: { [league: string]: ESportsLeagueSchedule[] }, date: string) {\n+        let output = `Games being played ${date.split(\" \").join(\"/\")}:\\n\\`\\`\\``;\n+        const padLeague = Object.keys(data).reduce((a, b) => a.length > b.length ? a : b).length;\n+        Object.keys(data).forEach(league => {\n+            const games = data[league];\n+            for (const game of games) {\n+                output += `[${league.padEnd(padLeague)}] ${game.teamA.padEnd(3)} vs ${game.teamB.padEnd(3)} -- ${game.time}\\n`;\n+            }\n+        });\n+        output += \"```\";\n+\n+        channel.send(output);\n+    }\n+\n+    // this can also check for older games by using resultsHtml instead of fixures\n+    private async loadData() {\n+        // pull data\n+        const data = await fetch(\"https://eu.lolesports.com/en/api/widget/schedule?timezone=Europe%2FOslo&leagues=26&leagues=3&leagues=2&leagues=6&leagues=7&leagues=5&leagues=4&leagues=9&leagues=10&leagues=1&leagues=43&slug=all\");\n+        const html = (await data.json() as ESportsAPIReturnData).fixturesHtml;\n+        const schedule: { [date: string]: { [league: string]: ESportsLeagueSchedule[] } } = {};\n+\n+        // for each date\n+        const asHtml = CheerioAPI.load(html);\n+        const parents = asHtml.root().find(\".schedule__row-group\");\n+        parents.each((indexed, elem) => {\n+            // the current date\n+            const elemRoot = CheerioAPI.load(elem).root();\n+            const date = elemRoot.find(\".schedule__row--date\").find(\"h2\").text().split(\" \");\n+\n+            // hack to get month number from text\n+            const month = (\"0\" + (\"JanFebMarAprMayJunJulAugSepOctNovDec\".indexOf(date[2].substr(0, 3)) / 3 + 1)).slice(-2);","path":"src/ESports.ts","position":124,"original_position":102,"commit_id":"bad2edb8b7b2b34b079ec39db6f1c4ea896fe84c","original_commit_id":"09edb2779f11edbe7010f2ebb2ec443a043cc6b6","user":{"login":"Querijn","id":3397066,"node_id":"MDQ6VXNlcjMzOTcwNjY=","avatar_url":"https://avatars2.githubusercontent.com/u/3397066?v=4","gravatar_id":"","url":"https://api.github.com/users/Querijn","html_url":"https://github.com/Querijn","followers_url":"https://api.github.com/users/Querijn/followers","following_url":"https://api.github.com/users/Querijn/following{/other_user}","gists_url":"https://api.github.com/users/Querijn/gists{/gist_id}","starred_url":"https://api.github.com/users/Querijn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Querijn/subscriptions","organizations_url":"https://api.github.com/users/Querijn/orgs","repos_url":"https://api.github.com/users/Querijn/repos","events_url":"https://api.github.com/users/Querijn/events{/privacy}","received_events_url":"https://api.github.com/users/Querijn/received_events","type":"User","site_admin":false},"body":"Thanks Github for making that a oneliner","created_at":"2018-07-23T04:32:16Z","updated_at":"2018-07-23T04:32:16Z","html_url":"https://github.com/Querijn/BottyMcBotface/pull/102#discussion_r204279870","pull_request_url":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/comments/204279870"},"html":{"href":"https://github.com/Querijn/BottyMcBotface/pull/102#discussion_r204279870"},"pull_request":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102"}},"in_reply_to_id":204254281},"pull_request":{"url":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102","id":203073565,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAzMDczNTY1","html_url":"https://github.com/Querijn/BottyMcBotface/pull/102","diff_url":"https://github.com/Querijn/BottyMcBotface/pull/102.diff","patch_url":"https://github.com/Querijn/BottyMcBotface/pull/102.patch","issue_url":"https://api.github.com/repos/Querijn/BottyMcBotface/issues/102","number":102,"state":"open","locked":false,"title":"Add esports notifications","user":{"login":"stelar7","id":940154,"node_id":"MDQ6VXNlcjk0MDE1NA==","avatar_url":"https://avatars2.githubusercontent.com/u/940154?v=4","gravatar_id":"","url":"https://api.github.com/users/stelar7","html_url":"https://github.com/stelar7","followers_url":"https://api.github.com/users/stelar7/followers","following_url":"https://api.github.com/users/stelar7/following{/other_user}","gists_url":"https://api.github.com/users/stelar7/gists{/gist_id}","starred_url":"https://api.github.com/users/stelar7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stelar7/subscriptions","organizations_url":"https://api.github.com/users/stelar7/orgs","repos_url":"https://api.github.com/users/stelar7/repos","events_url":"https://api.github.com/users/stelar7/events{/privacy}","received_events_url":"https://api.github.com/users/stelar7/received_events","type":"User","site_admin":false},"body":"Fixes #101 ","created_at":"2018-07-22T19:56:24Z","updated_at":"2018-07-23T04:32:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2c31e2c1445a6c71344e78beeef3ad24a5e8947a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102/commits","review_comments_url":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102/comments","review_comment_url":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Querijn/BottyMcBotface/issues/102/comments","statuses_url":"https://api.github.com/repos/Querijn/BottyMcBotface/statuses/bad2edb8b7b2b34b079ec39db6f1c4ea896fe84c","head":{"label":"stelar7:esports","ref":"esports","sha":"bad2edb8b7b2b34b079ec39db6f1c4ea896fe84c","user":{"login":"stelar7","id":940154,"node_id":"MDQ6VXNlcjk0MDE1NA==","avatar_url":"https://avatars2.githubusercontent.com/u/940154?v=4","gravatar_id":"","url":"https://api.github.com/users/stelar7","html_url":"https://github.com/stelar7","followers_url":"https://api.github.com/users/stelar7/followers","following_url":"https://api.github.com/users/stelar7/following{/other_user}","gists_url":"https://api.github.com/users/stelar7/gists{/gist_id}","starred_url":"https://api.github.com/users/stelar7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stelar7/subscriptions","organizations_url":"https://api.github.com/users/stelar7/orgs","repos_url":"https://api.github.com/users/stelar7/repos","events_url":"https://api.github.com/users/stelar7/events{/privacy}","received_events_url":"https://api.github.com/users/stelar7/received_events","type":"User","site_admin":false},"repo":{"id":124522241,"node_id":"MDEwOlJlcG9zaXRvcnkxMjQ1MjIyNDE=","name":"BottyMcBotface","full_name":"stelar7/BottyMcBotface","owner":{"login":"stelar7","id":940154,"node_id":"MDQ6VXNlcjk0MDE1NA==","avatar_url":"https://avatars2.githubusercontent.com/u/940154?v=4","gravatar_id":"","url":"https://api.github.com/users/stelar7","html_url":"https://github.com/stelar7","followers_url":"https://api.github.com/users/stelar7/followers","following_url":"https://api.github.com/users/stelar7/following{/other_user}","gists_url":"https://api.github.com/users/stelar7/gists{/gist_id}","starred_url":"https://api.github.com/users/stelar7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stelar7/subscriptions","organizations_url":"https://api.github.com/users/stelar7/orgs","repos_url":"https://api.github.com/users/stelar7/repos","events_url":"https://api.github.com/users/stelar7/events{/privacy}","received_events_url":"https://api.github.com/users/stelar7/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stelar7/BottyMcBotface","description":"The Riot Games API Bot","fork":true,"url":"https://api.github.com/repos/stelar7/BottyMcBotface","forks_url":"https://api.github.com/repos/stelar7/BottyMcBotface/forks","keys_url":"https://api.github.com/repos/stelar7/BottyMcBotface/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stelar7/BottyMcBotface/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stelar7/BottyMcBotface/teams","hooks_url":"https://api.github.com/repos/stelar7/BottyMcBotface/hooks","issue_events_url":"https://api.github.com/repos/stelar7/BottyMcBotface/issues/events{/number}","events_url":"https://api.github.com/repos/stelar7/BottyMcBotface/events","assignees_url":"https://api.github.com/repos/stelar7/BottyMcBotface/assignees{/user}","branches_url":"https://api.github.com/repos/stelar7/BottyMcBotface/branches{/branch}","tags_url":"https://api.github.com/repos/stelar7/BottyMcBotface/tags","blobs_url":"https://api.github.com/repos/stelar7/BottyMcBotface/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stelar7/BottyMcBotface/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stelar7/BottyMcBotface/git/refs{/sha}","trees_url":"https://api.github.com/repos/stelar7/BottyMcBotface/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stelar7/BottyMcBotface/statuses/{sha}","languages_url":"https://api.github.com/repos/stelar7/BottyMcBotface/languages","stargazers_url":"https://api.github.com/repos/stelar7/BottyMcBotface/stargazers","contributors_url":"https://api.github.com/repos/stelar7/BottyMcBotface/contributors","subscribers_url":"https://api.github.com/repos/stelar7/BottyMcBotface/subscribers","subscription_url":"https://api.github.com/repos/stelar7/BottyMcBotface/subscription","commits_url":"https://api.github.com/repos/stelar7/BottyMcBotface/commits{/sha}","git_commits_url":"https://api.github.com/repos/stelar7/BottyMcBotface/git/commits{/sha}","comments_url":"https://api.github.com/repos/stelar7/BottyMcBotface/comments{/number}","issue_comment_url":"https://api.github.com/repos/stelar7/BottyMcBotface/issues/comments{/number}","contents_url":"https://api.github.com/repos/stelar7/BottyMcBotface/contents/{+path}","compare_url":"https://api.github.com/repos/stelar7/BottyMcBotface/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stelar7/BottyMcBotface/merges","archive_url":"https://api.github.com/repos/stelar7/BottyMcBotface/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stelar7/BottyMcBotface/downloads","issues_url":"https://api.github.com/repos/stelar7/BottyMcBotface/issues{/number}","pulls_url":"https://api.github.com/repos/stelar7/BottyMcBotface/pulls{/number}","milestones_url":"https://api.github.com/repos/stelar7/BottyMcBotface/milestones{/number}","notifications_url":"https://api.github.com/repos/stelar7/BottyMcBotface/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stelar7/BottyMcBotface/labels{/name}","releases_url":"https://api.github.com/repos/stelar7/BottyMcBotface/releases{/id}","deployments_url":"https://api.github.com/repos/stelar7/BottyMcBotface/deployments","created_at":"2018-03-09T09:56:49Z","updated_at":"2018-07-11T22:09:16Z","pushed_at":"2018-07-22T22:21:43Z","git_url":"git://github.com/stelar7/BottyMcBotface.git","ssh_url":"git@github.com:stelar7/BottyMcBotface.git","clone_url":"https://github.com/stelar7/BottyMcBotface.git","svn_url":"https://github.com/stelar7/BottyMcBotface","homepage":null,"size":430,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Querijn:master","ref":"master","sha":"19a83a4b75a5fbb998ea6ccd02b2a6204bb93100","user":{"login":"Querijn","id":3397066,"node_id":"MDQ6VXNlcjMzOTcwNjY=","avatar_url":"https://avatars2.githubusercontent.com/u/3397066?v=4","gravatar_id":"","url":"https://api.github.com/users/Querijn","html_url":"https://github.com/Querijn","followers_url":"https://api.github.com/users/Querijn/followers","following_url":"https://api.github.com/users/Querijn/following{/other_user}","gists_url":"https://api.github.com/users/Querijn/gists{/gist_id}","starred_url":"https://api.github.com/users/Querijn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Querijn/subscriptions","organizations_url":"https://api.github.com/users/Querijn/orgs","repos_url":"https://api.github.com/users/Querijn/repos","events_url":"https://api.github.com/users/Querijn/events{/privacy}","received_events_url":"https://api.github.com/users/Querijn/received_events","type":"User","site_admin":false},"repo":{"id":99312539,"node_id":"MDEwOlJlcG9zaXRvcnk5OTMxMjUzOQ==","name":"BottyMcBotface","full_name":"Querijn/BottyMcBotface","owner":{"login":"Querijn","id":3397066,"node_id":"MDQ6VXNlcjMzOTcwNjY=","avatar_url":"https://avatars2.githubusercontent.com/u/3397066?v=4","gravatar_id":"","url":"https://api.github.com/users/Querijn","html_url":"https://github.com/Querijn","followers_url":"https://api.github.com/users/Querijn/followers","following_url":"https://api.github.com/users/Querijn/following{/other_user}","gists_url":"https://api.github.com/users/Querijn/gists{/gist_id}","starred_url":"https://api.github.com/users/Querijn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Querijn/subscriptions","organizations_url":"https://api.github.com/users/Querijn/orgs","repos_url":"https://api.github.com/users/Querijn/repos","events_url":"https://api.github.com/users/Querijn/events{/privacy}","received_events_url":"https://api.github.com/users/Querijn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Querijn/BottyMcBotface","description":"The Riot Games API Bot","fork":false,"url":"https://api.github.com/repos/Querijn/BottyMcBotface","forks_url":"https://api.github.com/repos/Querijn/BottyMcBotface/forks","keys_url":"https://api.github.com/repos/Querijn/BottyMcBotface/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Querijn/BottyMcBotface/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Querijn/BottyMcBotface/teams","hooks_url":"https://api.github.com/repos/Querijn/BottyMcBotface/hooks","issue_events_url":"https://api.github.com/repos/Querijn/BottyMcBotface/issues/events{/number}","events_url":"https://api.github.com/repos/Querijn/BottyMcBotface/events","assignees_url":"https://api.github.com/repos/Querijn/BottyMcBotface/assignees{/user}","branches_url":"https://api.github.com/repos/Querijn/BottyMcBotface/branches{/branch}","tags_url":"https://api.github.com/repos/Querijn/BottyMcBotface/tags","blobs_url":"https://api.github.com/repos/Querijn/BottyMcBotface/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Querijn/BottyMcBotface/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Querijn/BottyMcBotface/git/refs{/sha}","trees_url":"https://api.github.com/repos/Querijn/BottyMcBotface/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Querijn/BottyMcBotface/statuses/{sha}","languages_url":"https://api.github.com/repos/Querijn/BottyMcBotface/languages","stargazers_url":"https://api.github.com/repos/Querijn/BottyMcBotface/stargazers","contributors_url":"https://api.github.com/repos/Querijn/BottyMcBotface/contributors","subscribers_url":"https://api.github.com/repos/Querijn/BottyMcBotface/subscribers","subscription_url":"https://api.github.com/repos/Querijn/BottyMcBotface/subscription","commits_url":"https://api.github.com/repos/Querijn/BottyMcBotface/commits{/sha}","git_commits_url":"https://api.github.com/repos/Querijn/BottyMcBotface/git/commits{/sha}","comments_url":"https://api.github.com/repos/Querijn/BottyMcBotface/comments{/number}","issue_comment_url":"https://api.github.com/repos/Querijn/BottyMcBotface/issues/comments{/number}","contents_url":"https://api.github.com/repos/Querijn/BottyMcBotface/contents/{+path}","compare_url":"https://api.github.com/repos/Querijn/BottyMcBotface/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Querijn/BottyMcBotface/merges","archive_url":"https://api.github.com/repos/Querijn/BottyMcBotface/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Querijn/BottyMcBotface/downloads","issues_url":"https://api.github.com/repos/Querijn/BottyMcBotface/issues{/number}","pulls_url":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls{/number}","milestones_url":"https://api.github.com/repos/Querijn/BottyMcBotface/milestones{/number}","notifications_url":"https://api.github.com/repos/Querijn/BottyMcBotface/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Querijn/BottyMcBotface/labels{/name}","releases_url":"https://api.github.com/repos/Querijn/BottyMcBotface/releases{/id}","deployments_url":"https://api.github.com/repos/Querijn/BottyMcBotface/deployments","created_at":"2017-08-04T06:47:34Z","updated_at":"2018-07-22T15:00:31Z","pushed_at":"2018-07-22T22:21:45Z","git_url":"git://github.com/Querijn/BottyMcBotface.git","ssh_url":"git@github.com:Querijn/BottyMcBotface.git","clone_url":"https://github.com/Querijn/BottyMcBotface.git","svn_url":"https://github.com/Querijn/BottyMcBotface","homepage":null,"size":411,"stargazers_count":11,"watchers_count":11,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"archived":false,"open_issues_count":8,"license":null,"forks":8,"open_issues":8,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102"},"html":{"href":"https://github.com/Querijn/BottyMcBotface/pull/102"},"issue":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/issues/102"},"comments":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/issues/102/comments"},"review_comments":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102/comments"},"review_comment":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/pulls/102/commits"},"statuses":{"href":"https://api.github.com/repos/Querijn/BottyMcBotface/statuses/bad2edb8b7b2b34b079ec39db6f1c4ea896fe84c"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Querijn"}}