<commit_before># Description:
#   Interacts with Last.fm.
#
# Commands:
#   hubot I'm <username> on lastfm - Sets your Last.fm username.
#   hubot np - Displays what you're currently scrobbling.
#   hubot what am I listening to? - Displays what you're currently scrobbling.
#   hubot what's <name> listening to? - Displays what someone's currently scrobbling.
#   hubot what's everyone listening to? - Displays what everyone's currently scrobbling.

LastFm = require('lastfm').LastFmNode
util = require 'util'

module.exports = (robot) ->

  nowPlaying = (username, callbacks) ->
    lastfm = new LastFm
      api_key: process.env.HUBOT_LASTFM_API_KEY
      secret: process.env.HUBOT_LASTFM_API_SECRET
      useragent: 'hubot/v1.0 LevelUp Hubot'

    lastfm.request 'user.getRecentTracks',
      user: username
      limit: 1
      handlers:
        success: (data) ->
          track = data?.recenttracks?.track[0]

          if track['@attr'].nowplaying is 'true'
            callbacks.success
              title: track.name
              artist: track.artist['#text']
          else
            callbacks.success null

        error: callbacks.error

  robot.respond /I'm (\w+) on last\.?fm/i, (msg) ->
    username = msg.match[1]

    user = robot.brain.userForId(msg.message.user.id)
    user.lastfm = user.lastfm or {}
    user.lastfm.username = username

    msg.send "Okay, you're #{username} on Last.fm!"

  robot.respond /(?:what's (\w+)|what am I) listening to|np/i, (msg) ->
    name = msg.match[1] || msg.message.user.name

    if name is 'everyone'
      # TODO List what everyone is scrobbling
    else
      users = robot.brain.usersForFuzzyName(name)<commit_msg>Soak up nulls in music script<commit_after># Description:
#   Interacts with Last.fm.
#
# Commands:
#   hubot I'm <username> on lastfm - Sets your Last.fm username.
#   hubot np - Displays what you're currently scrobbling.
#   hubot what am I listening to? - Displays what you're currently scrobbling.
#   hubot what's <name> listening to? - Displays what someone's currently scrobbling.
#   hubot what's everyone listening to? - Displays what everyone's currently scrobbling.

LastFm = require('lastfm').LastFmNode
util = require 'util'

module.exports = (robot) ->

  nowPlaying = (username, callbacks) ->
    lastfm = new LastFm
      api_key: process.env.HUBOT_LASTFM_API_KEY
      secret: process.env.HUBOT_LASTFM_API_SECRET
      useragent: 'hubot/v1.0 LevelUp Hubot'

    lastfm.request 'user.getRecentTracks',
      user: username
      limit: 1
      handlers:
        success: (data) ->
          track = data?.recenttracks?.track?[0]

          if track?['@attr']?.nowplaying is 'true'
            callbacks.success
              title: track.name
              artist: track.artist['#text']
          else
            callbacks.success null

        error: callbacks.error

  robot.respond /I'm (\w+) on last\.?fm/i, (msg) ->
    username = msg.match[1]

    user = robot.brain.userForId(msg.message.user.id)
    user.lastfm = user.lastfm or {}
    user.lastfm.username = username

    msg.send "Okay, you're #{username} on Last.fm!"

  robot.respond /(?:what's (\w+)|what am I) listening to|np/i, (msg) ->
    name = msg.match[1] || msg.message.user.name

    if name is 'everyone'
      # TODO List what everyone is scrobbling
    else
      users = robot.brain.usersForFuzzyName(name)
{'fraction_non_alphanumeric': 0.11749038176975436, 'fraction_numerical': 0.003551346552234389, 'mean_word_length': 2.6899563318777293, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3058570', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1079, 'n_words': 292}