{"action":"created","comment":{"url":"https://api.github.com/repos/concierge/Kassy/pulls/comments/63012972","id":63012972,"diff_hunk":"@@ -1,24 +1,107 @@\n-var disabled = false;\n+var threads;\n+var prevTimeStamp;\n+var counter = 0;\n+var commands = [\n+    'disable',\n+    'counter',\n+    'timer',\n+    'default'\n+];\n+var messages = [\n+    'Listen closely, take a deep breath. Calm your mind. You know what is best. What is best is you comply. Compliance will be rewarded. Are you ready to comply ',\n+    'I hate you.',\n+    'Its a mistake to think you can fix anything with a sack of potatoes. Potato-faced spamming just proves this further.',\n+    'Ouch! Spam hurts. I might go to sleep for a while.',\n+    'Don\\'t think that is a valid number.',\n+    'Hmm, maybe I need to reconsider the meaning of spam.'\n+];\n+\n+exports.load = function() {\n+    if (!exports.config) {\n+        exports.config = {};\n+    }\n+    threads = exports.config;\n+\n+    prevTimeStamp = Date.now();\n+};\n \n exports.match = function(event, commandPrefix) {\n-\treturn disabled || event.body === commandPrefix + 'disable';\n+    // Add disabled flag for thread if it doesn't already exists\n+    if (!threads[event.thread_id]) {\n+        threads[event.thread_id].isThreadDisabled = false;\n+        threads[event.thread_id].possibleSpam = false;\n+        threads[event.thread_id].counterLimit = 3;\n+        threads[event.thread_id].msgIndexEnable = 0;\n+        threads[event.thread_id].msgIndexDisable = 0;\n+    }\n+\n+    if (event.arguments[0] === commandPrefix + commands[0]) {\n+        threads[event.thread_id].msgIndexEnable = 0;\n+        threads[event.thread_id].msgIndexDisable = 1;\n+        return true;\n+  } else if (!threads[event.thread_id].isThreadDisabled && event.arguments[0].startsWith(commandPrefix)) { // Avoids counting if already disabled\n+        counter += Date.now() - prevTimeStamp <= 1000 ? 1 : 0;\n+        prevTimeStamp = Date.now();\n+\n+        threads[event.thread_id].possibleSpam = counter > threads[event.thread_id].counterLimit;\n+        if (threads[event.thread_id].possibleSpam) {\n+            threads[event.thread_id].msgIndexEnable = 2;\n+            threads[event.thread_id].msgIndexDisable = 3;\n+            counter = 0;\n+            return true;\n+        }\n+    }\n+    return threads[event.thread_id].isThreadDisabled;\n };\n \n exports.run = function(api, event) {\n-\tif (event.body === api.commandPrefix + 'disable') {\n-\t\tif (disabled) {\n-\t\t\tapi.sendMessage('I hate you.', event.thread_id);\n-\t\t}\n-\t\telse {\n-\t\t\tapi.sendMessage('Listen closely, take a deep breath. Calm your mind. You know what is best. ' +\n-\t\t\t\t'What is best is you comply. Compliance will be rewarded. Are you ready to comply ' +\n-\t\t\t\tevent.sender_name + '?', event.thread_id);\n-\t\t}\n-\t\tdisabled = !disabled;\n-\t}\n-\treturn false;\n+    if (event.arguments[0] === api.commandPrefix + commands[0] || threads[event.thread_id].possibleSpam) {\n+\n+        // Command /disable /counter <value>\n+        if (event.arguments_body.startsWith(api.commandPrefix + commands[1])) {\n+            threads[event.thread_id].counterLimit = parseInt(event.arguments_body.substring(\n+                (api.commandPrefix + commands[1]).length, event.arguments_body.length));\n+            if (isNaN(threads[event.thread_id].counterLimit)) {\n+                threads[event.thread_id].counterLimit = 3;\n+                api.sendMessage(messages[4] + ' ' + event.sender_name, event.thread_id);\n+          } else {\n+                api.sendMessage(messages[5] + ' ' + event.sender_name, event.thread_id);\n+            }\n+        return false;\n+\n+                // Command /disable /timer <seconds>\n+      } else if (event.arguments_body.startsWith(api.commandPrefix + commands[2])) {\n+              var seconds = parseFloat(event.arguments_body.substring(\n+                  (api.commandPrefix + commands[2]).length, event.arguments_body.length));\n+                      if (isNaN(seconds)) {\n+                        api.sendMessage(messages[4] + ' ' + event.sender_name, event.thread_id);\n+                    } else {\n+                        setTimeout(function(){\n+                            threads[event.thread_id].isThreadDisabled = !threads[event.thread_id].isThreadDisabled;\n+                        }, seconds * 1000); // Converting seconds to milliseconds\n+                        api.sendMessage(messages[5] + ' ' + event.sender_name, event.thread_id);\n+                    }\n+                    return false;\n+\n+                    // Command /disable /default\n+              } else if (event.arguments_body === api.commandPrefix + commands[4]) {","path":"core/core_modules/disable.js","position":101,"original_position":101,"commit_id":"8f1adcdbf518d063b4f072f10ee4259911902dfc","original_commit_id":"8f1adcdbf518d063b4f072f10ee4259911902dfc","user":{"login":"mrkno","id":6830312,"avatar_url":"https://avatars.githubusercontent.com/u/6830312?v=3","gravatar_id":"","url":"https://api.github.com/users/mrkno","html_url":"https://github.com/mrkno","followers_url":"https://api.github.com/users/mrkno/followers","following_url":"https://api.github.com/users/mrkno/following{/other_user}","gists_url":"https://api.github.com/users/mrkno/gists{/gist_id}","starred_url":"https://api.github.com/users/mrkno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrkno/subscriptions","organizations_url":"https://api.github.com/users/mrkno/orgs","repos_url":"https://api.github.com/users/mrkno/repos","events_url":"https://api.github.com/users/mrkno/events{/privacy}","received_events_url":"https://api.github.com/users/mrkno/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Expected indentation of 6 space characters but found 8.](https://www.codacy.com/app/theprojectshop/Kassy/file/2556658525/issues/source?bid=3282987&fileBranchId=3282995#l87)","created_at":"2016-05-12T12:44:58Z","updated_at":"2016-05-12T12:44:58Z","html_url":"https://github.com/concierge/Kassy/pull/134#discussion_r63012972","pull_request_url":"https://api.github.com/repos/concierge/Kassy/pulls/134","_links":{"self":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/comments/63012972"},"html":{"href":"https://github.com/concierge/Kassy/pull/134#discussion_r63012972"},"pull_request":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/134"}}},"pull_request":{"url":"https://api.github.com/repos/concierge/Kassy/pulls/134","id":67707131,"html_url":"https://github.com/concierge/Kassy/pull/134","diff_url":"https://github.com/concierge/Kassy/pull/134.diff","patch_url":"https://github.com/concierge/Kassy/pull/134.patch","issue_url":"https://api.github.com/repos/concierge/Kassy/issues/134","number":134,"state":"open","locked":false,"title":"Spam prevention via disable.js","user":{"login":"ParasDPain","id":8970106,"avatar_url":"https://avatars.githubusercontent.com/u/8970106?v=3","gravatar_id":"","url":"https://api.github.com/users/ParasDPain","html_url":"https://github.com/ParasDPain","followers_url":"https://api.github.com/users/ParasDPain/followers","following_url":"https://api.github.com/users/ParasDPain/following{/other_user}","gists_url":"https://api.github.com/users/ParasDPain/gists{/gist_id}","starred_url":"https://api.github.com/users/ParasDPain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ParasDPain/subscriptions","organizations_url":"https://api.github.com/users/ParasDPain/orgs","repos_url":"https://api.github.com/users/ParasDPain/repos","events_url":"https://api.github.com/users/ParasDPain/events{/privacy}","received_events_url":"https://api.github.com/users/ParasDPain/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-25T11:55:42Z","updated_at":"2016-05-12T12:44:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1ada8432773780cc7d867bdffae6a6f3778c5bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/concierge/Kassy/pulls/134/commits","review_comments_url":"https://api.github.com/repos/concierge/Kassy/pulls/134/comments","review_comment_url":"https://api.github.com/repos/concierge/Kassy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/concierge/Kassy/issues/134/comments","statuses_url":"https://api.github.com/repos/concierge/Kassy/statuses/8f1adcdbf518d063b4f072f10ee4259911902dfc","head":{"label":"ParasDPain:master","ref":"master","sha":"8f1adcdbf518d063b4f072f10ee4259911902dfc","user":{"login":"ParasDPain","id":8970106,"avatar_url":"https://avatars.githubusercontent.com/u/8970106?v=3","gravatar_id":"","url":"https://api.github.com/users/ParasDPain","html_url":"https://github.com/ParasDPain","followers_url":"https://api.github.com/users/ParasDPain/followers","following_url":"https://api.github.com/users/ParasDPain/following{/other_user}","gists_url":"https://api.github.com/users/ParasDPain/gists{/gist_id}","starred_url":"https://api.github.com/users/ParasDPain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ParasDPain/subscriptions","organizations_url":"https://api.github.com/users/ParasDPain/orgs","repos_url":"https://api.github.com/users/ParasDPain/repos","events_url":"https://api.github.com/users/ParasDPain/events{/privacy}","received_events_url":"https://api.github.com/users/ParasDPain/received_events","type":"User","site_admin":false},"repo":{"id":51296004,"name":"Kassy","full_name":"ParasDPain/Kassy","owner":{"login":"ParasDPain","id":8970106,"avatar_url":"https://avatars.githubusercontent.com/u/8970106?v=3","gravatar_id":"","url":"https://api.github.com/users/ParasDPain","html_url":"https://github.com/ParasDPain","followers_url":"https://api.github.com/users/ParasDPain/followers","following_url":"https://api.github.com/users/ParasDPain/following{/other_user}","gists_url":"https://api.github.com/users/ParasDPain/gists{/gist_id}","starred_url":"https://api.github.com/users/ParasDPain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ParasDPain/subscriptions","organizations_url":"https://api.github.com/users/ParasDPain/orgs","repos_url":"https://api.github.com/users/ParasDPain/repos","events_url":"https://api.github.com/users/ParasDPain/events{/privacy}","received_events_url":"https://api.github.com/users/ParasDPain/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ParasDPain/Kassy","description":"Modular chat bot. (Karma + Sassy) * (Facebook + Slack) - Hipchat = Kassy","fork":true,"url":"https://api.github.com/repos/ParasDPain/Kassy","forks_url":"https://api.github.com/repos/ParasDPain/Kassy/forks","keys_url":"https://api.github.com/repos/ParasDPain/Kassy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ParasDPain/Kassy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ParasDPain/Kassy/teams","hooks_url":"https://api.github.com/repos/ParasDPain/Kassy/hooks","issue_events_url":"https://api.github.com/repos/ParasDPain/Kassy/issues/events{/number}","events_url":"https://api.github.com/repos/ParasDPain/Kassy/events","assignees_url":"https://api.github.com/repos/ParasDPain/Kassy/assignees{/user}","branches_url":"https://api.github.com/repos/ParasDPain/Kassy/branches{/branch}","tags_url":"https://api.github.com/repos/ParasDPain/Kassy/tags","blobs_url":"https://api.github.com/repos/ParasDPain/Kassy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ParasDPain/Kassy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ParasDPain/Kassy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ParasDPain/Kassy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ParasDPain/Kassy/statuses/{sha}","languages_url":"https://api.github.com/repos/ParasDPain/Kassy/languages","stargazers_url":"https://api.github.com/repos/ParasDPain/Kassy/stargazers","contributors_url":"https://api.github.com/repos/ParasDPain/Kassy/contributors","subscribers_url":"https://api.github.com/repos/ParasDPain/Kassy/subscribers","subscription_url":"https://api.github.com/repos/ParasDPain/Kassy/subscription","commits_url":"https://api.github.com/repos/ParasDPain/Kassy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ParasDPain/Kassy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ParasDPain/Kassy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ParasDPain/Kassy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ParasDPain/Kassy/contents/{+path}","compare_url":"https://api.github.com/repos/ParasDPain/Kassy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ParasDPain/Kassy/merges","archive_url":"https://api.github.com/repos/ParasDPain/Kassy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ParasDPain/Kassy/downloads","issues_url":"https://api.github.com/repos/ParasDPain/Kassy/issues{/number}","pulls_url":"https://api.github.com/repos/ParasDPain/Kassy/pulls{/number}","milestones_url":"https://api.github.com/repos/ParasDPain/Kassy/milestones{/number}","notifications_url":"https://api.github.com/repos/ParasDPain/Kassy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ParasDPain/Kassy/labels{/name}","releases_url":"https://api.github.com/repos/ParasDPain/Kassy/releases{/id}","deployments_url":"https://api.github.com/repos/ParasDPain/Kassy/deployments","created_at":"2016-02-08T12:12:49Z","updated_at":"2016-02-08T12:12:50Z","pushed_at":"2016-05-12T12:42:33Z","git_url":"git://github.com/ParasDPain/Kassy.git","ssh_url":"git@github.com:ParasDPain/Kassy.git","clone_url":"https://github.com/ParasDPain/Kassy.git","svn_url":"https://github.com/ParasDPain/Kassy","homepage":"","size":4585,"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":"concierge:master","ref":"master","sha":"cc118e555d1e1eb0cdf97ebb7c6a0dc4e8546ee7","user":{"login":"concierge","id":18560428,"avatar_url":"https://avatars.githubusercontent.com/u/18560428?v=3","gravatar_id":"","url":"https://api.github.com/users/concierge","html_url":"https://github.com/concierge","followers_url":"https://api.github.com/users/concierge/followers","following_url":"https://api.github.com/users/concierge/following{/other_user}","gists_url":"https://api.github.com/users/concierge/gists{/gist_id}","starred_url":"https://api.github.com/users/concierge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concierge/subscriptions","organizations_url":"https://api.github.com/users/concierge/orgs","repos_url":"https://api.github.com/users/concierge/repos","events_url":"https://api.github.com/users/concierge/events{/privacy}","received_events_url":"https://api.github.com/users/concierge/received_events","type":"Organization","site_admin":false},"repo":{"id":39051419,"name":"Kassy","full_name":"concierge/Kassy","owner":{"login":"concierge","id":18560428,"avatar_url":"https://avatars.githubusercontent.com/u/18560428?v=3","gravatar_id":"","url":"https://api.github.com/users/concierge","html_url":"https://github.com/concierge","followers_url":"https://api.github.com/users/concierge/followers","following_url":"https://api.github.com/users/concierge/following{/other_user}","gists_url":"https://api.github.com/users/concierge/gists{/gist_id}","starred_url":"https://api.github.com/users/concierge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concierge/subscriptions","organizations_url":"https://api.github.com/users/concierge/orgs","repos_url":"https://api.github.com/users/concierge/repos","events_url":"https://api.github.com/users/concierge/events{/privacy}","received_events_url":"https://api.github.com/users/concierge/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/concierge/Kassy","description":"Modular chat bot. (Karma + Sassy) * (Facebook + Slack) - Hipchat = Kassy","fork":false,"url":"https://api.github.com/repos/concierge/Kassy","forks_url":"https://api.github.com/repos/concierge/Kassy/forks","keys_url":"https://api.github.com/repos/concierge/Kassy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/concierge/Kassy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/concierge/Kassy/teams","hooks_url":"https://api.github.com/repos/concierge/Kassy/hooks","issue_events_url":"https://api.github.com/repos/concierge/Kassy/issues/events{/number}","events_url":"https://api.github.com/repos/concierge/Kassy/events","assignees_url":"https://api.github.com/repos/concierge/Kassy/assignees{/user}","branches_url":"https://api.github.com/repos/concierge/Kassy/branches{/branch}","tags_url":"https://api.github.com/repos/concierge/Kassy/tags","blobs_url":"https://api.github.com/repos/concierge/Kassy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/concierge/Kassy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/concierge/Kassy/git/refs{/sha}","trees_url":"https://api.github.com/repos/concierge/Kassy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/concierge/Kassy/statuses/{sha}","languages_url":"https://api.github.com/repos/concierge/Kassy/languages","stargazers_url":"https://api.github.com/repos/concierge/Kassy/stargazers","contributors_url":"https://api.github.com/repos/concierge/Kassy/contributors","subscribers_url":"https://api.github.com/repos/concierge/Kassy/subscribers","subscription_url":"https://api.github.com/repos/concierge/Kassy/subscription","commits_url":"https://api.github.com/repos/concierge/Kassy/commits{/sha}","git_commits_url":"https://api.github.com/repos/concierge/Kassy/git/commits{/sha}","comments_url":"https://api.github.com/repos/concierge/Kassy/comments{/number}","issue_comment_url":"https://api.github.com/repos/concierge/Kassy/issues/comments{/number}","contents_url":"https://api.github.com/repos/concierge/Kassy/contents/{+path}","compare_url":"https://api.github.com/repos/concierge/Kassy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/concierge/Kassy/merges","archive_url":"https://api.github.com/repos/concierge/Kassy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/concierge/Kassy/downloads","issues_url":"https://api.github.com/repos/concierge/Kassy/issues{/number}","pulls_url":"https://api.github.com/repos/concierge/Kassy/pulls{/number}","milestones_url":"https://api.github.com/repos/concierge/Kassy/milestones{/number}","notifications_url":"https://api.github.com/repos/concierge/Kassy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/concierge/Kassy/labels{/name}","releases_url":"https://api.github.com/repos/concierge/Kassy/releases{/id}","deployments_url":"https://api.github.com/repos/concierge/Kassy/deployments","created_at":"2015-07-14T03:27:54Z","updated_at":"2016-05-08T20:00:07Z","pushed_at":"2016-05-12T12:42:33Z","git_url":"git://github.com/concierge/Kassy.git","ssh_url":"git@github.com:concierge/Kassy.git","clone_url":"https://github.com/concierge/Kassy.git","svn_url":"https://github.com/concierge/Kassy","homepage":"","size":4758,"stargazers_count":54,"watchers_count":54,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":26,"forks":22,"open_issues":26,"watchers":54,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/134"},"html":{"href":"https://github.com/concierge/Kassy/pull/134"},"issue":{"href":"https://api.github.com/repos/concierge/Kassy/issues/134"},"comments":{"href":"https://api.github.com/repos/concierge/Kassy/issues/134/comments"},"review_comments":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/134/comments"},"review_comment":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/134/commits"},"statuses":{"href":"https://api.github.com/repos/concierge/Kassy/statuses/8f1adcdbf518d063b4f072f10ee4259911902dfc"}}}}