<commit_before>const info = {
  name: ['profile'],
  description: 'View your profile.',
  usage: config.discriminator + 'profile: View your profile\n' +
    config.discriminator + 'profile @[user]: View another user\'s profile.\n' +
    config.discriminator + 'profile set location [location]: Set your location.\n' +
    config.discriminator + 'profile set country [country emoji]: Set your country.\n' +
    config.discriminator + 'profile set description [description]: Add a profile description.\n' +
    config.discriminator + 'profile set battletag [Battle.net tag]: Set your Blizzard Battletag.',
  type: CommandType.Profile
};

const tt = require(global.paths.lib + 'turntable-handler');
const Discord = require('discord.js');
const db = require(global.paths.lib + 'database-handler').db;
const userHandler = require(global.paths.lib + 'user-handler');
const countryData = require('country-data');
const request = require('request');
const tzlookup = require('tz-lookup');

const handleMessage = function(bot, message) {
  if (message.mentions.users.size > 0) {
    console.log('showing profile for first mention');
    displayProfileForUser(bot, message, message.mentions.users.first());
  } else if (message.content.length > config.discriminator.length + 8) {
    const cmd = message.content.substring(config.discriminator.length, message.content.length).split(' ');
    if (cmd[3]) {
      cmd[3] = cmd.slice(3, cmd.length).join(' ');
    }

    switch(cmd[1]) {
      case 'set':
        switch(cmd[2]) {
          case 'country':
            profileSetCountry(bot, message, cmd[3]);
            break;
          case 'location':
            profileSetLocation(bot, message, cmd[3]);
            break;
          case 'description':
            profileSetDescription(bot, message, cmd[3]);
            break;
          case 'battletag':
            profileSetBattletag(bot, message, cmd[3]);
            break;
          default:
            message.reply('please provide a valid profile section.');
        }
        break;
      default:
        break;
    }
  } else {
    displayProfileForUser(bot, message, message.author);
  }
};

const displayProfileForUser = function(bot, message, user) {
  const embed = new Discord.RichEmbed();

  embed.setAuthor(user.username, user.avatarURL);
  embed.setTimestamp(new Date());
  embed.setThumbnail(user.avatarURL);
  embed.setFooter('Requested by ' + message.author.username, message.author.avatarURL);

  userHandler.getProfile(message.author.id, function(profile) {
    if (!profile) return message.reply('I couldn\'t find a profile for that user!');
    
    const metadata = JSON.parse(profile.metadata);

    if (metadata.description) {
      embed.setDescription(metadata.description);
    }

    // Create Location and Timezone fields
    if (metadata.location) {
      const country = countryData.countries[metadata.location.country];

      let locationString = '';

      if (metadata.location.components) {
        if (metadata.location.components.locality) {
          locationString += metadata.location.components.locality + ', ';
        }

        if (metadata.location.components.postal_town) {
          locationString += metadata.location.components.postal_town + ', ';
        }<commit_msg>Use postal_town or locality, not both<commit_after>const info = {
  name: ['profile'],
  description: 'View your profile.',
  usage: config.discriminator + 'profile: View your profile\n' +
    config.discriminator + 'profile @[user]: View another user\'s profile.\n' +
    config.discriminator + 'profile set location [location]: Set your location.\n' +
    config.discriminator + 'profile set country [country emoji]: Set your country.\n' +
    config.discriminator + 'profile set description [description]: Add a profile description.\n' +
    config.discriminator + 'profile set battletag [Battle.net tag]: Set your Blizzard Battletag.',
  type: CommandType.Profile
};

const tt = require(global.paths.lib + 'turntable-handler');
const Discord = require('discord.js');
const db = require(global.paths.lib + 'database-handler').db;
const userHandler = require(global.paths.lib + 'user-handler');
const countryData = require('country-data');
const request = require('request');
const tzlookup = require('tz-lookup');

const handleMessage = function(bot, message) {
  if (message.mentions.users.size > 0) {
    console.log('showing profile for first mention');
    displayProfileForUser(bot, message, message.mentions.users.first());
  } else if (message.content.length > config.discriminator.length + 8) {
    const cmd = message.content.substring(config.discriminator.length, message.content.length).split(' ');
    if (cmd[3]) {
      cmd[3] = cmd.slice(3, cmd.length).join(' ');
    }

    switch(cmd[1]) {
      case 'set':
        switch(cmd[2]) {
          case 'country':
            profileSetCountry(bot, message, cmd[3]);
            break;
          case 'location':
            profileSetLocation(bot, message, cmd[3]);
            break;
          case 'description':
            profileSetDescription(bot, message, cmd[3]);
            break;
          case 'battletag':
            profileSetBattletag(bot, message, cmd[3]);
            break;
          default:
            message.reply('please provide a valid profile section.');
        }
        break;
      default:
        break;
    }
  } else {
    displayProfileForUser(bot, message, message.author);
  }
};

const displayProfileForUser = function(bot, message, user) {
  const embed = new Discord.RichEmbed();

  embed.setAuthor(user.username, user.avatarURL);
  embed.setTimestamp(new Date());
  embed.setThumbnail(user.avatarURL);
  embed.setFooter('Requested by ' + message.author.username, message.author.avatarURL);

  userHandler.getProfile(message.author.id, function(profile) {
    if (!profile) return message.reply('I couldn\'t find a profile for that user!');
    
    const metadata = JSON.parse(profile.metadata);

    if (metadata.description) {
      embed.setDescription(metadata.description);
    }

    // Create Location and Timezone fields
    if (metadata.location) {
      const country = countryData.countries[metadata.location.country];

      let locationString = '';

      if (metadata.location.components) {
        if (metadata.location.components.locality) {
          locationString += metadata.location.components.locality + ', ';
        } else if (metadata.location.components.postal_town) {
          locationString += metadata.location.components.postal_town + ', ';
        }
{'fraction_non_alphanumeric': 0.1303751143641354, 'fraction_numerical': 0.003354681305275999, 'mean_word_length': 3.1670902160101653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '213224', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1838, 'n_words': 432}