{"action":"created","comment":{"url":"https://api.github.com/repos/mdavis1982/eve/pulls/comments/83745250","pull_request_review_id":4567806,"id":83745250,"diff_hunk":"@@ -0,0 +1,133 @@\n+<?php\n+\n+namespace App\\Handlers\\Utility;\n+\n+use App\\Slack\\Event;\n+use App\\Slack\\Message;\n+use App\\Handlers\\Handler;\n+use App\\Loader\\LoadsData;\n+use App\\Loader\\JsonLoader;\n+use Symfony\\Component\\Intl\\Intl;\n+use Illuminate\\Support\\Collection;\n+\n+final class CurrencyHandler extends Handler\n+{\n+    use LoadsData;\n+\n+    protected $dataFile = 'currency.json';\n+\n+    /**\n+     * @param JsonLoader $loader\n+     */\n+    public function __construct(JsonLoader $loader)\n+    {\n+        $this->loader = $loader;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function canHandle(Event $event)\n+    {\n+        return\n+            $event->isMessage() &&\n+            ($event->isDirectMessage() || $event->mentions($this->eve->userId())) &&\n+            $event->matches('/convert .+/i')\n+        ;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function handle(Event $event)\n+    {\n+        $this->loadData();\n+\n+        $arguments = $this->arguments($event);\n+        $content   = '`@eve convert 10 GPB to USD`';\n+        $baseRate  = 1;\n+\n+        if ($arguments->count() == 4 && $this->validArguments($arguments)) {\n+            $rates  = $this->data['rates'];\n+            $result = '';\n+\n+            if (! array_key_exists($arguments[1], $rates) && ! array_key_exists($arguments[3], $rates)) {\n+                return;\n+            }\n+\n+            if (array_key_exists($arguments[1], $rates) && array_key_exists($arguments[3], $rates)) {\n+                $result = number_format($arguments[0] * $rates[strtoupper($arguments[3])], 2);\n+            }\n+\n+            if (array_key_exists($arguments[1], $rates) && ! array_key_exists($arguments[3], $rates)) {\n+                if ($rates[strtoupper($arguments[1])] > $baseRate) {\n+                    $result = number_format($arguments[0] * $rates[strtoupper($arguments[1])], 2);\n+                } else {\n+                    $result = number_format($arguments[0] / $rates[strtoupper($arguments[1])], 2);\n+                }\n+            }\n+\n+            if (! array_key_exists($arguments[1], $rates) && array_key_exists($arguments[3], $rates)) {\n+                if ($rates[strtoupper($arguments[3])] > $baseRate) {\n+                    $result = number_format($arguments[0] / $rates[strtoupper($arguments[3])], 2);\n+                } else {\n+                    $result = number_format($arguments[0] * $rates[strtoupper($arguments[3])], 2);\n+                }\n+            }\n+\n+            $content = sprintf(\n+                \"<@%s> %s%s is around %s%s\",\n+                $event->sender(),\n+                $this->symbol($arguments[1]),\n+                $arguments[0],\n+                $this->symbol($arguments[3]),\n+                $result\n+            );\n+        }\n+\n+        $this->send(\n+            Message::saying($content)\n+            ->inChannel($event->channel())\n+            ->to($event->sender())\n+        );\n+    }\n+\n+    /**\n+     * @param  $arguments\n+     *\n+     * @return boolean\n+     */\n+    private function validArguments($arguments) {\n+        return\n+            preg_match('/[A-Z]{3}/', $arguments[1]) &&\n+            trim($arguments[2] == 'to') &&\n+            preg_match('/[A-Z]{3}/', $arguments[3])\n+        ;\n+    }\n+\n+    /**\n+     * @param  string $currency\n+     *\n+     * @return string\n+     */\n+    private function symbol(string $currency)","path":"app/Handlers/Utility/CurrencyHandler.php","position":113,"original_position":113,"commit_id":"1ca1b4aa6a3ec121ae032a42503251cb2094fcbd","original_commit_id":"1ca1b4aa6a3ec121ae032a42503251cb2094fcbd","user":{"login":"mdavis1982","id":199807,"avatar_url":"https://avatars.githubusercontent.com/u/199807?v=3","gravatar_id":"","url":"https://api.github.com/users/mdavis1982","html_url":"https://github.com/mdavis1982","followers_url":"https://api.github.com/users/mdavis1982/followers","following_url":"https://api.github.com/users/mdavis1982/following{/other_user}","gists_url":"https://api.github.com/users/mdavis1982/gists{/gist_id}","starred_url":"https://api.github.com/users/mdavis1982/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdavis1982/subscriptions","organizations_url":"https://api.github.com/users/mdavis1982/orgs","repos_url":"https://api.github.com/users/mdavis1982/repos","events_url":"https://api.github.com/users/mdavis1982/events{/privacy}","received_events_url":"https://api.github.com/users/mdavis1982/received_events","type":"User","site_admin":false},"body":"Consider renaming this method to make it more obvious what it's doing... Something like `symbolForCurrency`","created_at":"2016-10-17T22:08:56Z","updated_at":"2016-10-17T22:10:04Z","html_url":"https://github.com/mdavis1982/eve/pull/33#discussion_r83745250","pull_request_url":"https://api.github.com/repos/mdavis1982/eve/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/mdavis1982/eve/pulls/comments/83745250"},"html":{"href":"https://github.com/mdavis1982/eve/pull/33#discussion_r83745250"},"pull_request":{"href":"https://api.github.com/repos/mdavis1982/eve/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/mdavis1982/eve/pulls/33","id":89529606,"html_url":"https://github.com/mdavis1982/eve/pull/33","diff_url":"https://github.com/mdavis1982/eve/pull/33.diff","patch_url":"https://github.com/mdavis1982/eve/pull/33.patch","issue_url":"https://api.github.com/repos/mdavis1982/eve/issues/33","number":33,"state":"open","locked":false,"title":"Currency conversion handler and kernel command which fixes #18","user":{"login":"AndreasElia","id":5033092,"avatar_url":"https://avatars.githubusercontent.com/u/5033092?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreasElia","html_url":"https://github.com/AndreasElia","followers_url":"https://api.github.com/users/AndreasElia/followers","following_url":"https://api.github.com/users/AndreasElia/following{/other_user}","gists_url":"https://api.github.com/users/AndreasElia/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreasElia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreasElia/subscriptions","organizations_url":"https://api.github.com/users/AndreasElia/orgs","repos_url":"https://api.github.com/users/AndreasElia/repos","events_url":"https://api.github.com/users/AndreasElia/events{/privacy}","received_events_url":"https://api.github.com/users/AndreasElia/received_events","type":"User","site_admin":false},"body":"### Explanation\r\nAdds a `@eve convert 10 GBP to USD` handler as well as a kernel command to fetch the latest currency conversion rates from fixer.io\r\n\r\nFixes #18 \r\n","created_at":"2016-10-16T15:49:28Z","updated_at":"2016-10-17T22:10:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f90c498fbb90769c95f20ff00b6d12c77f8e1775","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mdavis1982/eve/pulls/33/commits","review_comments_url":"https://api.github.com/repos/mdavis1982/eve/pulls/33/comments","review_comment_url":"https://api.github.com/repos/mdavis1982/eve/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mdavis1982/eve/issues/33/comments","statuses_url":"https://api.github.com/repos/mdavis1982/eve/statuses/1ca1b4aa6a3ec121ae032a42503251cb2094fcbd","head":{"label":"AndreasElia:master","ref":"master","sha":"1ca1b4aa6a3ec121ae032a42503251cb2094fcbd","user":{"login":"AndreasElia","id":5033092,"avatar_url":"https://avatars.githubusercontent.com/u/5033092?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreasElia","html_url":"https://github.com/AndreasElia","followers_url":"https://api.github.com/users/AndreasElia/followers","following_url":"https://api.github.com/users/AndreasElia/following{/other_user}","gists_url":"https://api.github.com/users/AndreasElia/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreasElia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreasElia/subscriptions","organizations_url":"https://api.github.com/users/AndreasElia/orgs","repos_url":"https://api.github.com/users/AndreasElia/repos","events_url":"https://api.github.com/users/AndreasElia/events{/privacy}","received_events_url":"https://api.github.com/users/AndreasElia/received_events","type":"User","site_admin":false},"repo":{"id":70933547,"name":"eve","full_name":"AndreasElia/eve","owner":{"login":"AndreasElia","id":5033092,"avatar_url":"https://avatars.githubusercontent.com/u/5033092?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreasElia","html_url":"https://github.com/AndreasElia","followers_url":"https://api.github.com/users/AndreasElia/followers","following_url":"https://api.github.com/users/AndreasElia/following{/other_user}","gists_url":"https://api.github.com/users/AndreasElia/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreasElia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreasElia/subscriptions","organizations_url":"https://api.github.com/users/AndreasElia/orgs","repos_url":"https://api.github.com/users/AndreasElia/repos","events_url":"https://api.github.com/users/AndreasElia/events{/privacy}","received_events_url":"https://api.github.com/users/AndreasElia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AndreasElia/eve","description":"A Slack Bot","fork":true,"url":"https://api.github.com/repos/AndreasElia/eve","forks_url":"https://api.github.com/repos/AndreasElia/eve/forks","keys_url":"https://api.github.com/repos/AndreasElia/eve/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AndreasElia/eve/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AndreasElia/eve/teams","hooks_url":"https://api.github.com/repos/AndreasElia/eve/hooks","issue_events_url":"https://api.github.com/repos/AndreasElia/eve/issues/events{/number}","events_url":"https://api.github.com/repos/AndreasElia/eve/events","assignees_url":"https://api.github.com/repos/AndreasElia/eve/assignees{/user}","branches_url":"https://api.github.com/repos/AndreasElia/eve/branches{/branch}","tags_url":"https://api.github.com/repos/AndreasElia/eve/tags","blobs_url":"https://api.github.com/repos/AndreasElia/eve/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AndreasElia/eve/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AndreasElia/eve/git/refs{/sha}","trees_url":"https://api.github.com/repos/AndreasElia/eve/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AndreasElia/eve/statuses/{sha}","languages_url":"https://api.github.com/repos/AndreasElia/eve/languages","stargazers_url":"https://api.github.com/repos/AndreasElia/eve/stargazers","contributors_url":"https://api.github.com/repos/AndreasElia/eve/contributors","subscribers_url":"https://api.github.com/repos/AndreasElia/eve/subscribers","subscription_url":"https://api.github.com/repos/AndreasElia/eve/subscription","commits_url":"https://api.github.com/repos/AndreasElia/eve/commits{/sha}","git_commits_url":"https://api.github.com/repos/AndreasElia/eve/git/commits{/sha}","comments_url":"https://api.github.com/repos/AndreasElia/eve/comments{/number}","issue_comment_url":"https://api.github.com/repos/AndreasElia/eve/issues/comments{/number}","contents_url":"https://api.github.com/repos/AndreasElia/eve/contents/{+path}","compare_url":"https://api.github.com/repos/AndreasElia/eve/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AndreasElia/eve/merges","archive_url":"https://api.github.com/repos/AndreasElia/eve/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AndreasElia/eve/downloads","issues_url":"https://api.github.com/repos/AndreasElia/eve/issues{/number}","pulls_url":"https://api.github.com/repos/AndreasElia/eve/pulls{/number}","milestones_url":"https://api.github.com/repos/AndreasElia/eve/milestones{/number}","notifications_url":"https://api.github.com/repos/AndreasElia/eve/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AndreasElia/eve/labels{/name}","releases_url":"https://api.github.com/repos/AndreasElia/eve/releases{/id}","deployments_url":"https://api.github.com/repos/AndreasElia/eve/deployments","created_at":"2016-10-14T17:45:28Z","updated_at":"2016-10-14T17:45:30Z","pushed_at":"2016-10-17T18:34:13Z","git_url":"git://github.com/AndreasElia/eve.git","ssh_url":"git@github.com:AndreasElia/eve.git","clone_url":"https://github.com/AndreasElia/eve.git","svn_url":"https://github.com/AndreasElia/eve","homepage":null,"size":141,"stargazers_count":0,"watchers_count":0,"language":"PHP","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":"mdavis1982:master","ref":"master","sha":"aa515256b8e2035473f596f9de5783c20ab3d9aa","user":{"login":"mdavis1982","id":199807,"avatar_url":"https://avatars.githubusercontent.com/u/199807?v=3","gravatar_id":"","url":"https://api.github.com/users/mdavis1982","html_url":"https://github.com/mdavis1982","followers_url":"https://api.github.com/users/mdavis1982/followers","following_url":"https://api.github.com/users/mdavis1982/following{/other_user}","gists_url":"https://api.github.com/users/mdavis1982/gists{/gist_id}","starred_url":"https://api.github.com/users/mdavis1982/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdavis1982/subscriptions","organizations_url":"https://api.github.com/users/mdavis1982/orgs","repos_url":"https://api.github.com/users/mdavis1982/repos","events_url":"https://api.github.com/users/mdavis1982/events{/privacy}","received_events_url":"https://api.github.com/users/mdavis1982/received_events","type":"User","site_admin":false},"repo":{"id":69302443,"name":"eve","full_name":"mdavis1982/eve","owner":{"login":"mdavis1982","id":199807,"avatar_url":"https://avatars.githubusercontent.com/u/199807?v=3","gravatar_id":"","url":"https://api.github.com/users/mdavis1982","html_url":"https://github.com/mdavis1982","followers_url":"https://api.github.com/users/mdavis1982/followers","following_url":"https://api.github.com/users/mdavis1982/following{/other_user}","gists_url":"https://api.github.com/users/mdavis1982/gists{/gist_id}","starred_url":"https://api.github.com/users/mdavis1982/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdavis1982/subscriptions","organizations_url":"https://api.github.com/users/mdavis1982/orgs","repos_url":"https://api.github.com/users/mdavis1982/repos","events_url":"https://api.github.com/users/mdavis1982/events{/privacy}","received_events_url":"https://api.github.com/users/mdavis1982/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mdavis1982/eve","description":"A Slack Bot","fork":false,"url":"https://api.github.com/repos/mdavis1982/eve","forks_url":"https://api.github.com/repos/mdavis1982/eve/forks","keys_url":"https://api.github.com/repos/mdavis1982/eve/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mdavis1982/eve/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mdavis1982/eve/teams","hooks_url":"https://api.github.com/repos/mdavis1982/eve/hooks","issue_events_url":"https://api.github.com/repos/mdavis1982/eve/issues/events{/number}","events_url":"https://api.github.com/repos/mdavis1982/eve/events","assignees_url":"https://api.github.com/repos/mdavis1982/eve/assignees{/user}","branches_url":"https://api.github.com/repos/mdavis1982/eve/branches{/branch}","tags_url":"https://api.github.com/repos/mdavis1982/eve/tags","blobs_url":"https://api.github.com/repos/mdavis1982/eve/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mdavis1982/eve/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mdavis1982/eve/git/refs{/sha}","trees_url":"https://api.github.com/repos/mdavis1982/eve/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mdavis1982/eve/statuses/{sha}","languages_url":"https://api.github.com/repos/mdavis1982/eve/languages","stargazers_url":"https://api.github.com/repos/mdavis1982/eve/stargazers","contributors_url":"https://api.github.com/repos/mdavis1982/eve/contributors","subscribers_url":"https://api.github.com/repos/mdavis1982/eve/subscribers","subscription_url":"https://api.github.com/repos/mdavis1982/eve/subscription","commits_url":"https://api.github.com/repos/mdavis1982/eve/commits{/sha}","git_commits_url":"https://api.github.com/repos/mdavis1982/eve/git/commits{/sha}","comments_url":"https://api.github.com/repos/mdavis1982/eve/comments{/number}","issue_comment_url":"https://api.github.com/repos/mdavis1982/eve/issues/comments{/number}","contents_url":"https://api.github.com/repos/mdavis1982/eve/contents/{+path}","compare_url":"https://api.github.com/repos/mdavis1982/eve/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mdavis1982/eve/merges","archive_url":"https://api.github.com/repos/mdavis1982/eve/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mdavis1982/eve/downloads","issues_url":"https://api.github.com/repos/mdavis1982/eve/issues{/number}","pulls_url":"https://api.github.com/repos/mdavis1982/eve/pulls{/number}","milestones_url":"https://api.github.com/repos/mdavis1982/eve/milestones{/number}","notifications_url":"https://api.github.com/repos/mdavis1982/eve/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mdavis1982/eve/labels{/name}","releases_url":"https://api.github.com/repos/mdavis1982/eve/releases{/id}","deployments_url":"https://api.github.com/repos/mdavis1982/eve/deployments","created_at":"2016-09-26T23:53:23Z","updated_at":"2016-10-13T12:03:42Z","pushed_at":"2016-10-17T18:34:14Z","git_url":"git://github.com/mdavis1982/eve.git","ssh_url":"git@github.com:mdavis1982/eve.git","clone_url":"https://github.com/mdavis1982/eve.git","svn_url":"https://github.com/mdavis1982/eve","homepage":null,"size":285,"stargazers_count":15,"watchers_count":15,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":8,"forks":11,"open_issues":8,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mdavis1982/eve/pulls/33"},"html":{"href":"https://github.com/mdavis1982/eve/pull/33"},"issue":{"href":"https://api.github.com/repos/mdavis1982/eve/issues/33"},"comments":{"href":"https://api.github.com/repos/mdavis1982/eve/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/mdavis1982/eve/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/mdavis1982/eve/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mdavis1982/eve/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/mdavis1982/eve/statuses/1ca1b4aa6a3ec121ae032a42503251cb2094fcbd"}}}}
{"actor":{"display_login":"mdavis1982"}}