<commit_before># Get our toggl statuses
#

module.exports = (robot) ->
  robot.respond /toggl keyadd (.*)/i, (msg) ->
    togglKey = msg.match[1]
    msg.message.user.togglKey = togglKey
    msg.send "Ok, " + msg.message.user.name + ", I added your toggl key."

  robot.respond /toggl keydel (.*)/i, (msg) ->
    user = msg.message.user
    user.togglKey = null
    msg.reply("Ok, I lost your toggl key.")

  robot.respond /toggl status/i, (msg) ->
    msg.send "Stub function.  This is where I would loop through the api keys I have stored and display that status for each of you."<commit_msg>somewhat working toggl - adds and removes keys, shows your own status<commit_after># Show toggl status
#
# hubot toggl keyadd <yourapikey> - Remember my toggl api key
# hubot toggl keydel - Forget my toggl api key
# hubot toggl status - Show my recent time entries
#

module.exports = (robot) ->
  robot.respond /toggl keyadd (.*)/i, (msg) ->
    togglKey = msg.match[1]
    msg.message.user.togglKey = togglKey
    msg.send "Ok, " + msg.message.user.name + ", I added your toggl key."

  robot.respond /toggl keydel (.*)/i, (msg) ->
    user = msg.message.user
    user.togglKey = null
    msg.reply("Ok, I lost your toggl key.")

  robot.respond /toggl status/i, (msg) ->
    users = [msg.message.user]
    users.forEach (user) ->
      if user.togglKey?
        encodedAuth = new Buffer(user.togglKey + ':api_token').toString('base64')

        msg
          .http("https://www.toggl.com/api/v6/time_entries.json")
          .header('Authorization', 'Basic ' + encodedAuth)
          .get() (err, res, body) ->
            resp = user.name + "\n";
            results = JSON.parse(body)
            if results.error
              results.error.errors.forEach (err) ->
                resp += err.message
            else
              results.data.forEach (item) ->
                resp += item.start + " - " + item.description + " - " + item.duration + " sec\n"

            msg.send resp
{'fraction_non_alphanumeric': 0.13746223564954682, 'fraction_numerical': 0.0025176233635448137, 'mean_word_length': 2.295190713101161, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '618245', 'n_tokens_mistral': 664, 'n_tokens_neox': 673, 'n_words': 183}