import Message from 'telegram-api/types/Message';
import request from 'request';

export default function github(bot) {

  const BASE = 'https://api.github.com';
  const METHOD = '/search/repositories?q=';

  const ask = new Message().text('What repository are you searching for?');
  bot.command('github', message => {

    const search = (rep, id) => {
      new Promise((resolve, reject) => {
        request(BASE + METHOD + rep, {
          headers: {
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0'
          }
        }, (err, res, body) => {
          let result = JSON.parse(body);
          result.items.length ? resolve([rep, result.items[0].html_url]) : reject();
        });
      }).then((result) => {
        bot.send(new Message().text(result[0] + '\n' + result[1]).to(id))
      }).catch(() => {
        bot.send(new Message().text('No results found :(').to(id));
      });
    }

    let rep = message.text.slice(7).trim();

    if (!rep) {
      bot.send(ask.to(message.chat.id)).then(answer => {
        search(answer.text, message.chat.id);
      });
    } else {
      search(rep, message.chat.id);
    }
  });
}

@@ -641,16 +641,36 @@
         
+ if (result.items &&
  result.
@@ -685,10 +685,23 @@
 ngth
+) %7B%0A          
  
-?
  res
@@ -741,20 +741,62 @@
 rl%5D)
- : reject();
+;%0A          %7D else %7B%0A            reject();%0A          %7D
 %0A   
@@ -905,16 +905,17 @@
 .to(id))
+;
 %0A      %7D
@@ -1013,16 +1013,17 @@
 );%0A    %7D
+;
 %0A%0A    le

fix github