{"action":"created","comment":{"url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/comments/40384734","id":40384734,"diff_hunk":"@@ -0,0 +1,155 @@\n+/*\n+* Poll chat plugin\n+* This plugin allows roomauth (default: moderator and above) to run a poll in a room.\n+* Every room can have one poll, and every user can vote. The results are displayed for\n+* users that have voted, and are updated in real time. The poll can be closed with /endpoll.\n+* By bumbadadabum with (a lot of) help from Zarel.\n+*/\n+\n+var Poll = (function () {\n+    function Poll(room, question, options) {\n+        this.room = room;\n+        this.question = question;\n+        this.voters = [];\n+        this.totalVotes = 0;\n+\n+        this.options = [];\n+        for (var i in options) {\n+            this.options.push({name: options[i], votes: 0});\n+        }\n+    }\n+\n+    Poll.prototype.vote = function (user, option) {\n+        for (var ip in user.ips) {\n+            if (this.voters.indexOf(ip) > -1) {\n+                return this.room.send('You have already voted for this poll.');\n+            }\n+            else {\n+                this.voters.push(ip);\n+            }\n+        }\n+\n+        this.options[option - 1].votes++;\n+        this.totalVotes++;\n+\n+        this.update();\n+    };\n+\n+    Poll.prototype.generateVotes = function () {\n+        var output = '<div class=\"infobox\" style=\"text-align:center\"><p style=\"font-weight:bold;font-size:14pt\">' + this.question + '</p>';\n+        for (var i in this.options) {\n+            output += '<button value=\"/votepoll ' + (parseInt(i) + 1) + '\" name=\"send\">' + (parseInt(i) + 1) + '. ' + this.options[i].name + '</button><br/>';\n+        }\n+        output += '</div>';\n+\n+        return output;\n+    };\n+\n+    Poll.prototype.generateResults = function () {\n+        var output = '<div class=\"infobox\" style=\"text-align:center\"><p style=\"font-weight:bold;font-size:14pt\">' + this.question + '</p>';\n+        for (var i in this.options) {\n+            output += '<span style=\"font-weight:bold;padding:2px\">' + (parseInt(i) + 1) + '. ' + this.options[i].name + '</span><br/><span style=\"font-size:8pt;padding:0px\">' + this.options[i].votes + ' votes (' + ((this.options[i].votes * 100) / this.totalVotes) + '% of total).</span><br/>';\n+        }\n+        output += '</div>';\n+\n+        return output;\n+    };\n+\n+    Poll.prototype.update = function () {\n+        var results = this.generateResults();\n+\n+        // Update the poll results for everyone that has voted\n+        for (var i in this.room.users) {\n+            var user = this.room.users[i];\n+            if (this.voters.indexOf(user.latestIp) >= 0) {\n+                user.sendTo(this.room, '|uhtmlchange|poll|' + results);\n+            }\n+        }\n+    };\n+\n+    Poll.prototype.display = function (user, broadcast) {\n+        var votes = this.generateVotes();\n+        var results = this.generateResults();\n+\n+        var target = [];\n+\n+        if (broadcast) {\n+            target = this.room.users;\n+        } else {\n+            target.push(user);\n+        }\n+\n+        for (var i in target) {\n+            var thisUser = target[i];\n+            if (this.voters.indexOf(thisUser.latestIp) >= 0) {\n+                thisUser.sendTo(this.room, '|uhtml|poll|' + results);\n+            }\n+            else {\n+                thisUser.sendTo(this.room, '|uhtml|poll|' + votes);\n+            }\n+        }\n+    };\n+\n+    Poll.prototype.start = function () {\n+        var votes = this.generateVotes();\n+\n+        this.room.send('|uhtml|poll|' + votes);\n+    };\n+\n+    Poll.prototype.end = function () {\n+        var results = this.generateResults();\n+\n+        this.room.send('|uhtml|poll|' + results);\n+        this.room.send('|uhtmlchange|poll|' + results);\n+    };\n+\n+    return Poll;\n+})();\n+\n+exports.commands = {\n+    newpoll: function (target, room, user) {\n+        if (!this.can('ban', null, room)) return false;\n+        if (room.poll) return this.sendReply('There is already a poll in progress in this room.');\n+\n+        var targets = target.split(target.includes('|') ? '|' : ',');\n+        if (targets.length < 3) {\n+            return this.sendReply('Not enough arguments for /newpoll.');\n+        }\n+\n+        var options = [];\n+\n+        for (var i = 1; i < targets.length; i++) {\n+            options.push(Tools.escapeHTML(targets[i]));\n+        }\n+\n+        if (options.length > 8) {\n+            return this.sendReply(\"Too many options for poll (maximum is 8).\");\n+        }\n+\n+        room.poll = new Poll(room,Tools.escapeHTML(targets[0]),options);","path":"chat-plugins/poll.js","position":129,"original_position":129,"commit_id":"7a7484cd2b76622ed4611bd11457bc90ed812c70","original_commit_id":"7a7484cd2b76622ed4611bd11457bc90ed812c70","user":{"login":"Slayer95","id":4925744,"avatar_url":"https://avatars.githubusercontent.com/u/4925744?v=3","gravatar_id":"","url":"https://api.github.com/users/Slayer95","html_url":"https://github.com/Slayer95","followers_url":"https://api.github.com/users/Slayer95/followers","following_url":"https://api.github.com/users/Slayer95/following{/other_user}","gists_url":"https://api.github.com/users/Slayer95/gists{/gist_id}","starred_url":"https://api.github.com/users/Slayer95/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Slayer95/subscriptions","organizations_url":"https://api.github.com/users/Slayer95/orgs","repos_url":"https://api.github.com/users/Slayer95/repos","events_url":"https://api.github.com/users/Slayer95/events{/privacy}","received_events_url":"https://api.github.com/users/Slayer95/received_events","type":"User","site_admin":false},"body":"Maybe we should support HTML in the question with an alias or something?","created_at":"2015-09-24T23:11:18Z","updated_at":"2015-09-24T23:11:18Z","html_url":"https://github.com/Zarel/Pokemon-Showdown/pull/2177#discussion_r40384734","pull_request_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177","_links":{"self":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/comments/40384734"},"html":{"href":"https://github.com/Zarel/Pokemon-Showdown/pull/2177#discussion_r40384734"},"pull_request":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177"}}},"pull_request":{"url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177","id":45953207,"html_url":"https://github.com/Zarel/Pokemon-Showdown/pull/2177","diff_url":"https://github.com/Zarel/Pokemon-Showdown/pull/2177.diff","patch_url":"https://github.com/Zarel/Pokemon-Showdown/pull/2177.patch","issue_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/issues/2177","number":2177,"state":"open","locked":false,"title":"Implement polls (serverside code)","user":{"login":"bumbadadabum","id":4457584,"avatar_url":"https://avatars.githubusercontent.com/u/4457584?v=3","gravatar_id":"","url":"https://api.github.com/users/bumbadadabum","html_url":"https://github.com/bumbadadabum","followers_url":"https://api.github.com/users/bumbadadabum/followers","following_url":"https://api.github.com/users/bumbadadabum/following{/other_user}","gists_url":"https://api.github.com/users/bumbadadabum/gists{/gist_id}","starred_url":"https://api.github.com/users/bumbadadabum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bumbadadabum/subscriptions","organizations_url":"https://api.github.com/users/bumbadadabum/orgs","repos_url":"https://api.github.com/users/bumbadadabum/repos","events_url":"https://api.github.com/users/bumbadadabum/events{/privacy}","received_events_url":"https://api.github.com/users/bumbadadabum/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-24T21:37:32Z","updated_at":"2015-09-24T23:11:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1db550735fc7be8f089b25e6010f796dc9fb6cf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177/commits","review_comments_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177/comments","review_comment_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/issues/2177/comments","statuses_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/statuses/7a7484cd2b76622ed4611bd11457bc90ed812c70","head":{"label":"bumbadadabum:poll","ref":"poll","sha":"7a7484cd2b76622ed4611bd11457bc90ed812c70","user":{"login":"bumbadadabum","id":4457584,"avatar_url":"https://avatars.githubusercontent.com/u/4457584?v=3","gravatar_id":"","url":"https://api.github.com/users/bumbadadabum","html_url":"https://github.com/bumbadadabum","followers_url":"https://api.github.com/users/bumbadadabum/followers","following_url":"https://api.github.com/users/bumbadadabum/following{/other_user}","gists_url":"https://api.github.com/users/bumbadadabum/gists{/gist_id}","starred_url":"https://api.github.com/users/bumbadadabum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bumbadadabum/subscriptions","organizations_url":"https://api.github.com/users/bumbadadabum/orgs","repos_url":"https://api.github.com/users/bumbadadabum/repos","events_url":"https://api.github.com/users/bumbadadabum/events{/privacy}","received_events_url":"https://api.github.com/users/bumbadadabum/received_events","type":"User","site_admin":false},"repo":{"id":13387180,"name":"Pokemon-Showdown","full_name":"bumbadadabum/Pokemon-Showdown","owner":{"login":"bumbadadabum","id":4457584,"avatar_url":"https://avatars.githubusercontent.com/u/4457584?v=3","gravatar_id":"","url":"https://api.github.com/users/bumbadadabum","html_url":"https://github.com/bumbadadabum","followers_url":"https://api.github.com/users/bumbadadabum/followers","following_url":"https://api.github.com/users/bumbadadabum/following{/other_user}","gists_url":"https://api.github.com/users/bumbadadabum/gists{/gist_id}","starred_url":"https://api.github.com/users/bumbadadabum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bumbadadabum/subscriptions","organizations_url":"https://api.github.com/users/bumbadadabum/orgs","repos_url":"https://api.github.com/users/bumbadadabum/repos","events_url":"https://api.github.com/users/bumbadadabum/events{/privacy}","received_events_url":"https://api.github.com/users/bumbadadabum/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bumbadadabum/Pokemon-Showdown","description":"Pokémon battle simulator.","fork":true,"url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown","forks_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/forks","keys_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/teams","hooks_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/hooks","issue_events_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/issues/events{/number}","events_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/events","assignees_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/assignees{/user}","branches_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/branches{/branch}","tags_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/tags","blobs_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/git/refs{/sha}","trees_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/statuses/{sha}","languages_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/languages","stargazers_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/stargazers","contributors_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/contributors","subscribers_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/subscribers","subscription_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/subscription","commits_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/commits{/sha}","git_commits_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/git/commits{/sha}","comments_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/comments{/number}","issue_comment_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/issues/comments{/number}","contents_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/contents/{+path}","compare_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/merges","archive_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/downloads","issues_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/issues{/number}","pulls_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/pulls{/number}","milestones_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/milestones{/number}","notifications_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/labels{/name}","releases_url":"https://api.github.com/repos/bumbadadabum/Pokemon-Showdown/releases{/id}","created_at":"2013-10-07T15:14:56Z","updated_at":"2015-02-12T00:51:43Z","pushed_at":"2015-09-24T22:33:30Z","git_url":"git://github.com/bumbadadabum/Pokemon-Showdown.git","ssh_url":"git@github.com:bumbadadabum/Pokemon-Showdown.git","clone_url":"https://github.com/bumbadadabum/Pokemon-Showdown.git","svn_url":"https://github.com/bumbadadabum/Pokemon-Showdown","homepage":"http://pokemonshowdown.com","size":43462,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Zarel:master","ref":"master","sha":"d7901d098a1ede2e4357e9267b0b7ab5bf192955","user":{"login":"Zarel","id":551184,"avatar_url":"https://avatars.githubusercontent.com/u/551184?v=3","gravatar_id":"","url":"https://api.github.com/users/Zarel","html_url":"https://github.com/Zarel","followers_url":"https://api.github.com/users/Zarel/followers","following_url":"https://api.github.com/users/Zarel/following{/other_user}","gists_url":"https://api.github.com/users/Zarel/gists{/gist_id}","starred_url":"https://api.github.com/users/Zarel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zarel/subscriptions","organizations_url":"https://api.github.com/users/Zarel/orgs","repos_url":"https://api.github.com/users/Zarel/repos","events_url":"https://api.github.com/users/Zarel/events{/privacy}","received_events_url":"https://api.github.com/users/Zarel/received_events","type":"User","site_admin":false},"repo":{"id":3038446,"name":"Pokemon-Showdown","full_name":"Zarel/Pokemon-Showdown","owner":{"login":"Zarel","id":551184,"avatar_url":"https://avatars.githubusercontent.com/u/551184?v=3","gravatar_id":"","url":"https://api.github.com/users/Zarel","html_url":"https://github.com/Zarel","followers_url":"https://api.github.com/users/Zarel/followers","following_url":"https://api.github.com/users/Zarel/following{/other_user}","gists_url":"https://api.github.com/users/Zarel/gists{/gist_id}","starred_url":"https://api.github.com/users/Zarel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zarel/subscriptions","organizations_url":"https://api.github.com/users/Zarel/orgs","repos_url":"https://api.github.com/users/Zarel/repos","events_url":"https://api.github.com/users/Zarel/events{/privacy}","received_events_url":"https://api.github.com/users/Zarel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Zarel/Pokemon-Showdown","description":"Pokémon battle simulator.","fork":false,"url":"https://api.github.com/repos/Zarel/Pokemon-Showdown","forks_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/forks","keys_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/teams","hooks_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/hooks","issue_events_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/issues/events{/number}","events_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/events","assignees_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/assignees{/user}","branches_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/branches{/branch}","tags_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/tags","blobs_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/git/refs{/sha}","trees_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/statuses/{sha}","languages_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/languages","stargazers_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/stargazers","contributors_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/contributors","subscribers_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/subscribers","subscription_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/subscription","commits_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/commits{/sha}","git_commits_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/git/commits{/sha}","comments_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/comments{/number}","issue_comment_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/issues/comments{/number}","contents_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/contents/{+path}","compare_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/merges","archive_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/downloads","issues_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/issues{/number}","pulls_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls{/number}","milestones_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/milestones{/number}","notifications_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/labels{/name}","releases_url":"https://api.github.com/repos/Zarel/Pokemon-Showdown/releases{/id}","created_at":"2011-12-23T04:52:33Z","updated_at":"2015-09-23T14:28:27Z","pushed_at":"2015-09-24T22:33:30Z","git_url":"git://github.com/Zarel/Pokemon-Showdown.git","ssh_url":"git@github.com:Zarel/Pokemon-Showdown.git","clone_url":"https://github.com/Zarel/Pokemon-Showdown.git","svn_url":"https://github.com/Zarel/Pokemon-Showdown","homepage":"http://pokemonshowdown.com","size":97505,"stargazers_count":576,"watchers_count":576,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":753,"mirror_url":null,"open_issues_count":34,"forks":753,"open_issues":34,"watchers":576,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177"},"html":{"href":"https://github.com/Zarel/Pokemon-Showdown/pull/2177"},"issue":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/issues/2177"},"comments":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/issues/2177/comments"},"review_comments":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177/comments"},"review_comment":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/pulls/2177/commits"},"statuses":{"href":"https://api.github.com/repos/Zarel/Pokemon-Showdown/statuses/7a7484cd2b76622ed4611bd11457bc90ed812c70"}}}}