{"action":"created","comment":{"url":"https://api.github.com/repos/ningirsu/taemin/pulls/comments/194239466","pull_request_review_id":127378905,"id":194239466,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDIzOTQ2Ng==","diff_hunk":"@@ -0,0 +1,152 @@\n+#!/usr/bin/env python3\n+# -*- coding: utf8 -*-\n+\n+\"\"\"\n+    Kick Vote Plugin\n+\"\"\"\n+\n+import time\n+from threading import Thread\n+\n+from taemin import plugin\n+\n+class TaeminVoxPopuli(plugin.TaeminPlugin):\n+    \"\"\" Vox Populi Plugin \"\"\"\n+\n+    helper = {\n+        \"voxpopuli\": \"Vote to kick someone: '!voxpopuli [nick] [vote duration (s)]\",\n+    }\n+\n+    def __init__(self, taemin):\n+        plugin.TaeminPlugin.__init__(self, taemin)\n+        self.states = {}\n+\n+    def on_pubmsg(self, msg):\n+        if msg.key not in self.helper:\n+            return\n+\n+        chan = msg.chan.name\n+\n+        if chan not in self.states:\n+            self.states[chan] = VoxWait(self, chan)\n+\n+        if msg.key == \"voxpopuli\":\n+            self.swap_state(chan, self.states[chan].on_msg(msg.value, msg.user.name))\n+\n+    def on_timeout(self, chan):\n+        \"\"\" Called once the vote is finished \"\"\"\n+\n+        if chan not in self.states:\n+            return\n+\n+        self.swap_state(chan, self.states[chan].on_timeout())\n+\n+    def swap_state(self, chan, new_state):\n+        \"\"\" Swap to a new state \"\"\"\n+\n+        if new_state is not None:\n+            self.states[chan] = new_state\n+\n+\n+class VoxState(object):\n+    \"\"\" State for the Plugin \"\"\"\n+\n+    _default_values = {\"duration\" : \"120\", \"nick\" : \"FlyingYeti\"}\n+\n+    def __init__(self, _plugin, chan):\n+        self.plugin = _plugin\n+        self.chan = chan\n+\n+    def on_msg(self, msg, author):\n+        \"\"\" Called when the voxpopuli receives a command \"\"\"\n+        pass\n+\n+    def on_timeout(self):\n+        \"\"\" Called once the vote is finished \"\"\"\n+        pass\n+\n+    def fork(self, constructor, *args):\n+        \"\"\" Create another state for the same chan \"\"\"\n+        return constructor(self.plugin, self.chan, *args)\n+\n+\n+class VoteTimer(Thread):\n+    \"\"\" Timer for the Vote \"\"\"\n+    def __init__(self, _time, _plugin, chan):\n+        Thread.__init__(self)\n+        self.plugin = _plugin\n+        self.chan = chan\n+        self._time = _time\n+\n+    def run(self):\n+        time.sleep(self._time)\n+        self.plugin.on_timeout(self.chan)\n+\n+\n+class VoxWait(VoxState):\n+    \"\"\" Wait for a Vote to be started \"\"\"\n+\n+    def on_msg(self, msg, author):\n+\n+        # Parse the Arguments\n+        tokens = msg.strip().split(\" \") if msg != \"\" else []\n+\n+        nick = VoxState._default_values[\"nick\"]\n+        duration = VoxState._default_values[\"duration\"]\n+\n+        try:\n+            nick = tokens.pop(0)\n+            duration = tokens.pop(0)\n+        except IndexError:\n+            pass\n+\n+        #TODO: Verify if the nick is in the chan\n+\n+        # Parse the Duration\n+        try:\n+            duration = int(float(duration))\n+        except ValueError:\n+            duration = int(float(VoxState._default_values[\"duration\"]))\n+\n+        return self.fork(VoxVote, nick, duration)\n+\n+\n+class VoxVote(VoxState):\n+    \"\"\" Collect the votes \"\"\"\n+\n+    def __init__(self, _plugin, chan, nick, duration):\n+        VoxState.__init__(self, _plugin, chan)\n+\n+        self.nick = nick\n+\n+        timer = VoteTimer(duration, self.plugin, self.chan)\n+        timer.start()\n+\n+        self.votes = {}\n+        self.plugin.privmsg(\n+            self.chan, \"Starting Vote to kick {}. Duration: {} seconds.\".format(\n+                self.nick, duration)\n+            )\n+\n+    def on_timeout(self):\n+        total = len(self.votes)\n+        yes = len([x for x in self.votes.values() if x is True])\n+\n+        self.plugin.privmsg(\n+            self.chan, \"Result of the Vote to kick {}. Yes: {}, No: {}.\".format(\n+                self.nick, yes, total - yes)\n+            )\n+\n+        if yes > int(total/2):\n+            self.plugin.kick(self.chan, self.nick, \"Mouhahaha\")\n+\n+        return self.fork(VoxWait)\n+\n+    def on_msg(self, msg, author):\n+\n+        if author in self.votes:\n+            return self\n+\n+        self.votes[author] = bool(msg == \"yes\")","path":"taemin/plugins/voxpopuli/plugin.py","position":150,"original_position":150,"commit_id":"a16a6087d9fbd04610e33060fdc18f11d1d0805e","original_commit_id":"a16a6087d9fbd04610e33060fdc18f11d1d0805e","user":{"login":"cym13","id":4958985,"node_id":"MDQ6VXNlcjQ5NTg5ODU=","avatar_url":"https://avatars3.githubusercontent.com/u/4958985?v=4","gravatar_id":"","url":"https://api.github.com/users/cym13","html_url":"https://github.com/cym13","followers_url":"https://api.github.com/users/cym13/followers","following_url":"https://api.github.com/users/cym13/following{/other_user}","gists_url":"https://api.github.com/users/cym13/gists{/gist_id}","starred_url":"https://api.github.com/users/cym13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cym13/subscriptions","organizations_url":"https://api.github.com/users/cym13/orgs","repos_url":"https://api.github.com/users/cym13/repos","events_url":"https://api.github.com/users/cym13/events{/privacy}","received_events_url":"https://api.github.com/users/cym13/received_events","type":"User","site_admin":false},"body":"    msg == \"yes\"\r\n\r\nis already a boolean, I'd remove \"bool\" but keep the parentheses to avoid confusion between = and == near each other.","created_at":"2018-06-09T21:35:19Z","updated_at":"2018-06-09T21:40:23Z","html_url":"https://github.com/ningirsu/taemin/pull/5#discussion_r194239466","pull_request_url":"https://api.github.com/repos/ningirsu/taemin/pulls/5","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/ningirsu/taemin/pulls/comments/194239466"},"html":{"href":"https://github.com/ningirsu/taemin/pull/5#discussion_r194239466"},"pull_request":{"href":"https://api.github.com/repos/ningirsu/taemin/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/ningirsu/taemin/pulls/5","id":193796595,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNzk2NTk1","html_url":"https://github.com/ningirsu/taemin/pull/5","diff_url":"https://github.com/ningirsu/taemin/pull/5.diff","patch_url":"https://github.com/ningirsu/taemin/pull/5.patch","issue_url":"https://api.github.com/repos/ningirsu/taemin/issues/5","number":5,"state":"open","locked":false,"title":"Voxpopuli Plugin","user":{"login":"th3oSMith","id":3028783,"node_id":"MDQ6VXNlcjMwMjg3ODM=","avatar_url":"https://avatars2.githubusercontent.com/u/3028783?v=4","gravatar_id":"","url":"https://api.github.com/users/th3oSMith","html_url":"https://github.com/th3oSMith","followers_url":"https://api.github.com/users/th3oSMith/followers","following_url":"https://api.github.com/users/th3oSMith/following{/other_user}","gists_url":"https://api.github.com/users/th3oSMith/gists{/gist_id}","starred_url":"https://api.github.com/users/th3oSMith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/th3oSMith/subscriptions","organizations_url":"https://api.github.com/users/th3oSMith/orgs","repos_url":"https://api.github.com/users/th3oSMith/repos","events_url":"https://api.github.com/users/th3oSMith/events{/privacy}","received_events_url":"https://api.github.com/users/th3oSMith/received_events","type":"User","site_admin":false},"body":"* Add kick command to the plugin\r\n* Implement the Voxpopuli Plugin","created_at":"2018-06-09T21:15:14Z","updated_at":"2018-06-09T21:40:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8acca7bdcaf296e77a6d8a771c7bdec4c35231af","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/ningirsu/taemin/pulls/5/commits","review_comments_url":"https://api.github.com/repos/ningirsu/taemin/pulls/5/comments","review_comment_url":"https://api.github.com/repos/ningirsu/taemin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ningirsu/taemin/issues/5/comments","statuses_url":"https://api.github.com/repos/ningirsu/taemin/statuses/a16a6087d9fbd04610e33060fdc18f11d1d0805e","head":{"label":"th3oSMith:master","ref":"master","sha":"a16a6087d9fbd04610e33060fdc18f11d1d0805e","user":{"login":"th3oSMith","id":3028783,"node_id":"MDQ6VXNlcjMwMjg3ODM=","avatar_url":"https://avatars2.githubusercontent.com/u/3028783?v=4","gravatar_id":"","url":"https://api.github.com/users/th3oSMith","html_url":"https://github.com/th3oSMith","followers_url":"https://api.github.com/users/th3oSMith/followers","following_url":"https://api.github.com/users/th3oSMith/following{/other_user}","gists_url":"https://api.github.com/users/th3oSMith/gists{/gist_id}","starred_url":"https://api.github.com/users/th3oSMith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/th3oSMith/subscriptions","organizations_url":"https://api.github.com/users/th3oSMith/orgs","repos_url":"https://api.github.com/users/th3oSMith/repos","events_url":"https://api.github.com/users/th3oSMith/events{/privacy}","received_events_url":"https://api.github.com/users/th3oSMith/received_events","type":"User","site_admin":false},"repo":{"id":136746001,"node_id":"MDEwOlJlcG9zaXRvcnkxMzY3NDYwMDE=","name":"taemin","full_name":"th3oSMith/taemin","owner":{"login":"th3oSMith","id":3028783,"node_id":"MDQ6VXNlcjMwMjg3ODM=","avatar_url":"https://avatars2.githubusercontent.com/u/3028783?v=4","gravatar_id":"","url":"https://api.github.com/users/th3oSMith","html_url":"https://github.com/th3oSMith","followers_url":"https://api.github.com/users/th3oSMith/followers","following_url":"https://api.github.com/users/th3oSMith/following{/other_user}","gists_url":"https://api.github.com/users/th3oSMith/gists{/gist_id}","starred_url":"https://api.github.com/users/th3oSMith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/th3oSMith/subscriptions","organizations_url":"https://api.github.com/users/th3oSMith/orgs","repos_url":"https://api.github.com/users/th3oSMith/repos","events_url":"https://api.github.com/users/th3oSMith/events{/privacy}","received_events_url":"https://api.github.com/users/th3oSMith/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/th3oSMith/taemin","description":"A beautiful IRC bot","fork":true,"url":"https://api.github.com/repos/th3oSMith/taemin","forks_url":"https://api.github.com/repos/th3oSMith/taemin/forks","keys_url":"https://api.github.com/repos/th3oSMith/taemin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/th3oSMith/taemin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/th3oSMith/taemin/teams","hooks_url":"https://api.github.com/repos/th3oSMith/taemin/hooks","issue_events_url":"https://api.github.com/repos/th3oSMith/taemin/issues/events{/number}","events_url":"https://api.github.com/repos/th3oSMith/taemin/events","assignees_url":"https://api.github.com/repos/th3oSMith/taemin/assignees{/user}","branches_url":"https://api.github.com/repos/th3oSMith/taemin/branches{/branch}","tags_url":"https://api.github.com/repos/th3oSMith/taemin/tags","blobs_url":"https://api.github.com/repos/th3oSMith/taemin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/th3oSMith/taemin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/th3oSMith/taemin/git/refs{/sha}","trees_url":"https://api.github.com/repos/th3oSMith/taemin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/th3oSMith/taemin/statuses/{sha}","languages_url":"https://api.github.com/repos/th3oSMith/taemin/languages","stargazers_url":"https://api.github.com/repos/th3oSMith/taemin/stargazers","contributors_url":"https://api.github.com/repos/th3oSMith/taemin/contributors","subscribers_url":"https://api.github.com/repos/th3oSMith/taemin/subscribers","subscription_url":"https://api.github.com/repos/th3oSMith/taemin/subscription","commits_url":"https://api.github.com/repos/th3oSMith/taemin/commits{/sha}","git_commits_url":"https://api.github.com/repos/th3oSMith/taemin/git/commits{/sha}","comments_url":"https://api.github.com/repos/th3oSMith/taemin/comments{/number}","issue_comment_url":"https://api.github.com/repos/th3oSMith/taemin/issues/comments{/number}","contents_url":"https://api.github.com/repos/th3oSMith/taemin/contents/{+path}","compare_url":"https://api.github.com/repos/th3oSMith/taemin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/th3oSMith/taemin/merges","archive_url":"https://api.github.com/repos/th3oSMith/taemin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/th3oSMith/taemin/downloads","issues_url":"https://api.github.com/repos/th3oSMith/taemin/issues{/number}","pulls_url":"https://api.github.com/repos/th3oSMith/taemin/pulls{/number}","milestones_url":"https://api.github.com/repos/th3oSMith/taemin/milestones{/number}","notifications_url":"https://api.github.com/repos/th3oSMith/taemin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/th3oSMith/taemin/labels{/name}","releases_url":"https://api.github.com/repos/th3oSMith/taemin/releases{/id}","deployments_url":"https://api.github.com/repos/th3oSMith/taemin/deployments","created_at":"2018-06-09T17:56:01Z","updated_at":"2018-06-09T21:14:16Z","pushed_at":"2018-06-09T21:14:15Z","git_url":"git://github.com/th3oSMith/taemin.git","ssh_url":"git@github.com:th3oSMith/taemin.git","clone_url":"https://github.com/th3oSMith/taemin.git","svn_url":"https://github.com/th3oSMith/taemin","homepage":"","size":1146,"stargazers_count":0,"watchers_count":0,"language":"Python","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":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ningirsu:master","ref":"master","sha":"a13087d99543248e7328fd9540603754e564a965","user":{"login":"ningirsu","id":7975575,"node_id":"MDQ6VXNlcjc5NzU1NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/7975575?v=4","gravatar_id":"","url":"https://api.github.com/users/ningirsu","html_url":"https://github.com/ningirsu","followers_url":"https://api.github.com/users/ningirsu/followers","following_url":"https://api.github.com/users/ningirsu/following{/other_user}","gists_url":"https://api.github.com/users/ningirsu/gists{/gist_id}","starred_url":"https://api.github.com/users/ningirsu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ningirsu/subscriptions","organizations_url":"https://api.github.com/users/ningirsu/orgs","repos_url":"https://api.github.com/users/ningirsu/repos","events_url":"https://api.github.com/users/ningirsu/events{/privacy}","received_events_url":"https://api.github.com/users/ningirsu/received_events","type":"User","site_admin":false},"repo":{"id":50047310,"node_id":"MDEwOlJlcG9zaXRvcnk1MDA0NzMxMA==","name":"taemin","full_name":"ningirsu/taemin","owner":{"login":"ningirsu","id":7975575,"node_id":"MDQ6VXNlcjc5NzU1NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/7975575?v=4","gravatar_id":"","url":"https://api.github.com/users/ningirsu","html_url":"https://github.com/ningirsu","followers_url":"https://api.github.com/users/ningirsu/followers","following_url":"https://api.github.com/users/ningirsu/following{/other_user}","gists_url":"https://api.github.com/users/ningirsu/gists{/gist_id}","starred_url":"https://api.github.com/users/ningirsu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ningirsu/subscriptions","organizations_url":"https://api.github.com/users/ningirsu/orgs","repos_url":"https://api.github.com/users/ningirsu/repos","events_url":"https://api.github.com/users/ningirsu/events{/privacy}","received_events_url":"https://api.github.com/users/ningirsu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ningirsu/taemin","description":"A beautiful IRC bot","fork":false,"url":"https://api.github.com/repos/ningirsu/taemin","forks_url":"https://api.github.com/repos/ningirsu/taemin/forks","keys_url":"https://api.github.com/repos/ningirsu/taemin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ningirsu/taemin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ningirsu/taemin/teams","hooks_url":"https://api.github.com/repos/ningirsu/taemin/hooks","issue_events_url":"https://api.github.com/repos/ningirsu/taemin/issues/events{/number}","events_url":"https://api.github.com/repos/ningirsu/taemin/events","assignees_url":"https://api.github.com/repos/ningirsu/taemin/assignees{/user}","branches_url":"https://api.github.com/repos/ningirsu/taemin/branches{/branch}","tags_url":"https://api.github.com/repos/ningirsu/taemin/tags","blobs_url":"https://api.github.com/repos/ningirsu/taemin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ningirsu/taemin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ningirsu/taemin/git/refs{/sha}","trees_url":"https://api.github.com/repos/ningirsu/taemin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ningirsu/taemin/statuses/{sha}","languages_url":"https://api.github.com/repos/ningirsu/taemin/languages","stargazers_url":"https://api.github.com/repos/ningirsu/taemin/stargazers","contributors_url":"https://api.github.com/repos/ningirsu/taemin/contributors","subscribers_url":"https://api.github.com/repos/ningirsu/taemin/subscribers","subscription_url":"https://api.github.com/repos/ningirsu/taemin/subscription","commits_url":"https://api.github.com/repos/ningirsu/taemin/commits{/sha}","git_commits_url":"https://api.github.com/repos/ningirsu/taemin/git/commits{/sha}","comments_url":"https://api.github.com/repos/ningirsu/taemin/comments{/number}","issue_comment_url":"https://api.github.com/repos/ningirsu/taemin/issues/comments{/number}","contents_url":"https://api.github.com/repos/ningirsu/taemin/contents/{+path}","compare_url":"https://api.github.com/repos/ningirsu/taemin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ningirsu/taemin/merges","archive_url":"https://api.github.com/repos/ningirsu/taemin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ningirsu/taemin/downloads","issues_url":"https://api.github.com/repos/ningirsu/taemin/issues{/number}","pulls_url":"https://api.github.com/repos/ningirsu/taemin/pulls{/number}","milestones_url":"https://api.github.com/repos/ningirsu/taemin/milestones{/number}","notifications_url":"https://api.github.com/repos/ningirsu/taemin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ningirsu/taemin/labels{/name}","releases_url":"https://api.github.com/repos/ningirsu/taemin/releases{/id}","deployments_url":"https://api.github.com/repos/ningirsu/taemin/deployments","created_at":"2016-01-20T17:31:33Z","updated_at":"2018-06-09T21:17:30Z","pushed_at":"2018-06-09T21:15:15Z","git_url":"git://github.com/ningirsu/taemin.git","ssh_url":"git@github.com:ningirsu/taemin.git","clone_url":"https://github.com/ningirsu/taemin.git","svn_url":"https://github.com/ningirsu/taemin","homepage":"","size":1146,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":3,"open_issues":3,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ningirsu/taemin/pulls/5"},"html":{"href":"https://github.com/ningirsu/taemin/pull/5"},"issue":{"href":"https://api.github.com/repos/ningirsu/taemin/issues/5"},"comments":{"href":"https://api.github.com/repos/ningirsu/taemin/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/ningirsu/taemin/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/ningirsu/taemin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ningirsu/taemin/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/ningirsu/taemin/statuses/a16a6087d9fbd04610e33060fdc18f11d1d0805e"}},"author_association":"NONE"}}
{"actor":{"display_login":"cym13"}}