<commit_before>const path = require('path');
const fs = require('fs');
const Discord = require('discord.js');

const IMG_PATH = path.join(__dirname, '..', 'assets', 'gifs');
const gifCollection = {};
let lastName = '';

const Gifs = {
  randomName() {
    let count = 0;
    let name;

    for (let gif in gifCollection) {
      if (Math.random() < 1 / ++count) {
        name = gif;
      }
    }

    return name;
  },

  randomGif(name) {
    return gifCollection[name][Math.floor(Math.random()*gifCollection[name].length)];
  },

  fetch() {
    fs.readdirSync(path.join(IMG_PATH)).forEach(file => {
      const name = file.split('_')[0];

      if (!gifCollection[name]) {
        gifCollection[name] = [];
      }

      gifCollection[name].push(file);
    });
  },

  gif(message, args) {
    let name = args[0];

    Gifs.fetch();

    if(!lastName || !name || !gifCollection[name]) {
      name = Gifs.randomName();
    }
<commit_msg>Fix: use name if first use (was using lastname even when name is specified)<commit_after>const path = require('path');
const fs = require('fs');
const Discord = require('discord.js');

const IMG_PATH = path.join(__dirname, '..', 'assets', 'gifs');
const gifCollection = {};
let lastName = '';

const Gifs = {
  randomName() {
    let count = 0;
    let name;

    for (let gif in gifCollection) {
      if (Math.random() < 1 / ++count) {
        name = gif;
      }
    }

    return name;
  },

  randomGif(name) {
    return gifCollection[name][Math.floor(Math.random()*gifCollection[name].length)];
  },

  fetch() {
    fs.readdirSync(path.join(IMG_PATH)).forEach(file => {
      const name = file.split('_')[0];

      if (!gifCollection[name]) {
        gifCollection[name] = [];
      }

      gifCollection[name].push(file);
    });
  },

  gif(message, args) {
    let name = args[0];

    Gifs.fetch();

    if(!lastName && !name) {
      name = Gifs.randomName();
    }

    if(!name || !gifCollection[name]) {
      name = Gifs.randomName();
    }

{'fraction_non_alphanumeric': 0.17723414877683474, 'fraction_numerical': 0.00399400898652022, 'mean_word_length': 2.752808988764045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3455041', 'n_tokens_mistral': 707, 'n_tokens_neox': 674, 'n_words': 140}