{"action":"created","comment":{"url":"https://api.github.com/repos/Kright/TFS-bot/pulls/comments/110340411","pull_request_review_id":31505704,"id":110340411,"diff_hunk":"@@ -0,0 +1,45 @@\n+package dispatcher\n+\n+import scala.io.Source\n+\n+import telegram.API._\n+import tinkoff.API._\n+\n+/**\n+  * Main polling loop.\n+  */\n+object Dispatcher extends App {\n+\n+  def getFormattedRates(rates: List[Rate]): String = {\n+    val textRatesList = rates.map(x => \"%3s: %7.3f  %7.3f\".format(x.fromCurrency.name, x.buy, x.sell.get))\n+    \"<pre>\" +\n+      \"       Buy      Sell\\n\" +\n+      \"      ------   ------\\n\" +\n+      textRatesList.mkString(\"\\n\") + \"</pre>\"\n+  }\n+\n+  setToken(Source.fromFile(\"TelegramBotToken\").getLines.mkString)\n+\n+  while (true) {\n+    val updatesList = getUpdates()\n+    if (updatesList.nonEmpty)\n+      println(updatesList)\n+\n+    for (update <- updatesList; if update.message.isDefined; message = update.message.get) {\n+        if (message.entities.isDefined)\n+          for (entity <- message.entities.get if entity.`type` == \"bot_command\") {\n+            // (jusual): message.text is defined because text contains name of bot_command\n+            val command = message.text.get.substring(entity.offset, entity.offset + entity.length)","path":"src/main/scala/dispatcher/Dispatcher.scala","position":32,"original_position":32,"commit_id":"229a636d8e261b554918f276fb823a7be603c923","original_commit_id":"229a636d8e261b554918f276fb823a7be603c923","user":{"login":"sergeypopov83","id":20317475,"avatar_url":"https://avatars2.githubusercontent.com/u/20317475?v=3","gravatar_id":"","url":"https://api.github.com/users/sergeypopov83","html_url":"https://github.com/sergeypopov83","followers_url":"https://api.github.com/users/sergeypopov83/followers","following_url":"https://api.github.com/users/sergeypopov83/following{/other_user}","gists_url":"https://api.github.com/users/sergeypopov83/gists{/gist_id}","starred_url":"https://api.github.com/users/sergeypopov83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergeypopov83/subscriptions","organizations_url":"https://api.github.com/users/sergeypopov83/orgs","repos_url":"https://api.github.com/users/sergeypopov83/repos","events_url":"https://api.github.com/users/sergeypopov83/events{/privacy}","received_events_url":"https://api.github.com/users/sergeypopov83/received_events","type":"User","site_admin":false},"body":"get появляться нигде не должен. Если есть уверенность, что text всегда заполнен, убери Option, если такой уверенности нет, как минимум надо сделать  text.getOrElse(\"\") или скорее map, ведь тебе не надо выполнять действия если текста нет","created_at":"2017-04-07T08:28:58Z","updated_at":"2017-04-07T08:38:49Z","html_url":"https://github.com/Kright/TFS-bot/pull/2#discussion_r110340411","pull_request_url":"https://api.github.com/repos/Kright/TFS-bot/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/Kright/TFS-bot/pulls/comments/110340411"},"html":{"href":"https://github.com/Kright/TFS-bot/pull/2#discussion_r110340411"},"pull_request":{"href":"https://api.github.com/repos/Kright/TFS-bot/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/Kright/TFS-bot/pulls/2","id":113792631,"html_url":"https://github.com/Kright/TFS-bot/pull/2","diff_url":"https://github.com/Kright/TFS-bot/pull/2.diff","patch_url":"https://github.com/Kright/TFS-bot/pull/2.patch","issue_url":"https://api.github.com/repos/Kright/TFS-bot/issues/2","number":2,"state":"open","locked":false,"title":"Initial version with '/rates' command support.","user":{"login":"jusual","id":9610326,"avatar_url":"https://avatars3.githubusercontent.com/u/9610326?v=3","gravatar_id":"","url":"https://api.github.com/users/jusual","html_url":"https://github.com/jusual","followers_url":"https://api.github.com/users/jusual/followers","following_url":"https://api.github.com/users/jusual/following{/other_user}","gists_url":"https://api.github.com/users/jusual/gists{/gist_id}","starred_url":"https://api.github.com/users/jusual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jusual/subscriptions","organizations_url":"https://api.github.com/users/jusual/orgs","repos_url":"https://api.github.com/users/jusual/repos","events_url":"https://api.github.com/users/jusual/events{/privacy}","received_events_url":"https://api.github.com/users/jusual/received_events","type":"User","site_admin":false},"body":"We have 3 main modules:\r\n\r\n\t* telegram.API\r\n\t  Two functions was implemented:\r\n\r\n\t\t* getUpdates\r\n\t\t  Requests new updates from Telegram\r\n\t\t  server and parses received json into\r\n\t\t  case class Response.\r\n\r\n\t\t* sendMessage\r\n\t\t  Requests text message sending from Telegram\r\n\t\t  server to desired chat.\r\n\r\n\t* tinkoff.API\r\n\r\n\t\t* getRates\r\n\t\t  Gets currency rates from Tinkoff API\r\n\t\t  server. Parses received json into\r\n\t\t  case class Response. Returns rates for\r\n\t\t  rubles.\r\n\r\n\t* dispatcher\r\n\t\tMain object. Polling cycle:\r\n\t\t1. Get updates from Telegram API.\r\n\t\t2. For every message in updates checks\r\n\t\t   for bot commands and handles them.\r\n\r\nThe bot token located in file ignored by git. Dispatcher\r\nreads token from the file and calls telegram.API.setToken()\r\nto initialize it.\r\n\r\nHelloWorld file was removed.\r\n\r\nSigned-off-by: Julia Suvorova <jusual@mail.ru>","created_at":"2017-04-01T20:04:52Z","updated_at":"2017-04-07T08:38:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c62312680b5eae9522ab02adf06e3cf375ba44e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Kright/TFS-bot/pulls/2/commits","review_comments_url":"https://api.github.com/repos/Kright/TFS-bot/pulls/2/comments","review_comment_url":"https://api.github.com/repos/Kright/TFS-bot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Kright/TFS-bot/issues/2/comments","statuses_url":"https://api.github.com/repos/Kright/TFS-bot/statuses/229a636d8e261b554918f276fb823a7be603c923","head":{"label":"Kright:jusual","ref":"jusual","sha":"229a636d8e261b554918f276fb823a7be603c923","user":{"login":"Kright","id":6692108,"avatar_url":"https://avatars3.githubusercontent.com/u/6692108?v=3","gravatar_id":"","url":"https://api.github.com/users/Kright","html_url":"https://github.com/Kright","followers_url":"https://api.github.com/users/Kright/followers","following_url":"https://api.github.com/users/Kright/following{/other_user}","gists_url":"https://api.github.com/users/Kright/gists{/gist_id}","starred_url":"https://api.github.com/users/Kright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kright/subscriptions","organizations_url":"https://api.github.com/users/Kright/orgs","repos_url":"https://api.github.com/users/Kright/repos","events_url":"https://api.github.com/users/Kright/events{/privacy}","received_events_url":"https://api.github.com/users/Kright/received_events","type":"User","site_admin":false},"repo":{"id":86376854,"name":"TFS-bot","full_name":"Kright/TFS-bot","owner":{"login":"Kright","id":6692108,"avatar_url":"https://avatars3.githubusercontent.com/u/6692108?v=3","gravatar_id":"","url":"https://api.github.com/users/Kright","html_url":"https://github.com/Kright","followers_url":"https://api.github.com/users/Kright/followers","following_url":"https://api.github.com/users/Kright/following{/other_user}","gists_url":"https://api.github.com/users/Kright/gists{/gist_id}","starred_url":"https://api.github.com/users/Kright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kright/subscriptions","organizations_url":"https://api.github.com/users/Kright/orgs","repos_url":"https://api.github.com/users/Kright/repos","events_url":"https://api.github.com/users/Kright/events{/privacy}","received_events_url":"https://api.github.com/users/Kright/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Kright/TFS-bot","description":null,"fork":false,"url":"https://api.github.com/repos/Kright/TFS-bot","forks_url":"https://api.github.com/repos/Kright/TFS-bot/forks","keys_url":"https://api.github.com/repos/Kright/TFS-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kright/TFS-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kright/TFS-bot/teams","hooks_url":"https://api.github.com/repos/Kright/TFS-bot/hooks","issue_events_url":"https://api.github.com/repos/Kright/TFS-bot/issues/events{/number}","events_url":"https://api.github.com/repos/Kright/TFS-bot/events","assignees_url":"https://api.github.com/repos/Kright/TFS-bot/assignees{/user}","branches_url":"https://api.github.com/repos/Kright/TFS-bot/branches{/branch}","tags_url":"https://api.github.com/repos/Kright/TFS-bot/tags","blobs_url":"https://api.github.com/repos/Kright/TFS-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kright/TFS-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kright/TFS-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kright/TFS-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kright/TFS-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/Kright/TFS-bot/languages","stargazers_url":"https://api.github.com/repos/Kright/TFS-bot/stargazers","contributors_url":"https://api.github.com/repos/Kright/TFS-bot/contributors","subscribers_url":"https://api.github.com/repos/Kright/TFS-bot/subscribers","subscription_url":"https://api.github.com/repos/Kright/TFS-bot/subscription","commits_url":"https://api.github.com/repos/Kright/TFS-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kright/TFS-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kright/TFS-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kright/TFS-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kright/TFS-bot/contents/{+path}","compare_url":"https://api.github.com/repos/Kright/TFS-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kright/TFS-bot/merges","archive_url":"https://api.github.com/repos/Kright/TFS-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kright/TFS-bot/downloads","issues_url":"https://api.github.com/repos/Kright/TFS-bot/issues{/number}","pulls_url":"https://api.github.com/repos/Kright/TFS-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/Kright/TFS-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/Kright/TFS-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kright/TFS-bot/labels{/name}","releases_url":"https://api.github.com/repos/Kright/TFS-bot/releases{/id}","deployments_url":"https://api.github.com/repos/Kright/TFS-bot/deployments","created_at":"2017-03-27T19:42:01Z","updated_at":"2017-03-28T18:32:05Z","pushed_at":"2017-04-04T20:35:31Z","git_url":"git://github.com/Kright/TFS-bot.git","ssh_url":"git@github.com:Kright/TFS-bot.git","clone_url":"https://github.com/Kright/TFS-bot.git","svn_url":"https://github.com/Kright/TFS-bot","homepage":"","size":3,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"Kright:master","ref":"master","sha":"ead5d61bc0e6c26d37c87d4efe1995dea20c278b","user":{"login":"Kright","id":6692108,"avatar_url":"https://avatars3.githubusercontent.com/u/6692108?v=3","gravatar_id":"","url":"https://api.github.com/users/Kright","html_url":"https://github.com/Kright","followers_url":"https://api.github.com/users/Kright/followers","following_url":"https://api.github.com/users/Kright/following{/other_user}","gists_url":"https://api.github.com/users/Kright/gists{/gist_id}","starred_url":"https://api.github.com/users/Kright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kright/subscriptions","organizations_url":"https://api.github.com/users/Kright/orgs","repos_url":"https://api.github.com/users/Kright/repos","events_url":"https://api.github.com/users/Kright/events{/privacy}","received_events_url":"https://api.github.com/users/Kright/received_events","type":"User","site_admin":false},"repo":{"id":86376854,"name":"TFS-bot","full_name":"Kright/TFS-bot","owner":{"login":"Kright","id":6692108,"avatar_url":"https://avatars3.githubusercontent.com/u/6692108?v=3","gravatar_id":"","url":"https://api.github.com/users/Kright","html_url":"https://github.com/Kright","followers_url":"https://api.github.com/users/Kright/followers","following_url":"https://api.github.com/users/Kright/following{/other_user}","gists_url":"https://api.github.com/users/Kright/gists{/gist_id}","starred_url":"https://api.github.com/users/Kright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kright/subscriptions","organizations_url":"https://api.github.com/users/Kright/orgs","repos_url":"https://api.github.com/users/Kright/repos","events_url":"https://api.github.com/users/Kright/events{/privacy}","received_events_url":"https://api.github.com/users/Kright/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Kright/TFS-bot","description":null,"fork":false,"url":"https://api.github.com/repos/Kright/TFS-bot","forks_url":"https://api.github.com/repos/Kright/TFS-bot/forks","keys_url":"https://api.github.com/repos/Kright/TFS-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kright/TFS-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kright/TFS-bot/teams","hooks_url":"https://api.github.com/repos/Kright/TFS-bot/hooks","issue_events_url":"https://api.github.com/repos/Kright/TFS-bot/issues/events{/number}","events_url":"https://api.github.com/repos/Kright/TFS-bot/events","assignees_url":"https://api.github.com/repos/Kright/TFS-bot/assignees{/user}","branches_url":"https://api.github.com/repos/Kright/TFS-bot/branches{/branch}","tags_url":"https://api.github.com/repos/Kright/TFS-bot/tags","blobs_url":"https://api.github.com/repos/Kright/TFS-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kright/TFS-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kright/TFS-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kright/TFS-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kright/TFS-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/Kright/TFS-bot/languages","stargazers_url":"https://api.github.com/repos/Kright/TFS-bot/stargazers","contributors_url":"https://api.github.com/repos/Kright/TFS-bot/contributors","subscribers_url":"https://api.github.com/repos/Kright/TFS-bot/subscribers","subscription_url":"https://api.github.com/repos/Kright/TFS-bot/subscription","commits_url":"https://api.github.com/repos/Kright/TFS-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kright/TFS-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kright/TFS-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kright/TFS-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kright/TFS-bot/contents/{+path}","compare_url":"https://api.github.com/repos/Kright/TFS-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kright/TFS-bot/merges","archive_url":"https://api.github.com/repos/Kright/TFS-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kright/TFS-bot/downloads","issues_url":"https://api.github.com/repos/Kright/TFS-bot/issues{/number}","pulls_url":"https://api.github.com/repos/Kright/TFS-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/Kright/TFS-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/Kright/TFS-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kright/TFS-bot/labels{/name}","releases_url":"https://api.github.com/repos/Kright/TFS-bot/releases{/id}","deployments_url":"https://api.github.com/repos/Kright/TFS-bot/deployments","created_at":"2017-03-27T19:42:01Z","updated_at":"2017-03-28T18:32:05Z","pushed_at":"2017-04-04T20:35:31Z","git_url":"git://github.com/Kright/TFS-bot.git","ssh_url":"git@github.com:Kright/TFS-bot.git","clone_url":"https://github.com/Kright/TFS-bot.git","svn_url":"https://github.com/Kright/TFS-bot","homepage":"","size":3,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Kright/TFS-bot/pulls/2"},"html":{"href":"https://github.com/Kright/TFS-bot/pull/2"},"issue":{"href":"https://api.github.com/repos/Kright/TFS-bot/issues/2"},"comments":{"href":"https://api.github.com/repos/Kright/TFS-bot/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/Kright/TFS-bot/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/Kright/TFS-bot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Kright/TFS-bot/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/Kright/TFS-bot/statuses/229a636d8e261b554918f276fb823a7be603c923"}}}}
{"actor":{"display_login":"sergeypopov83"}}