<commit_before>'use strict';

const sprintf = require('sprintf-js').sprintf;

module.exports = srcPath => {
  const B = require(srcPath + 'Broadcast');
  const CommandManager = require(srcPath + 'CommandManager');

  const subcommands = new CommandManager();
  subcommands.add({
    name: 'list',
    command: state => (args, player) => {
      const waypoints = player.getMeta('waypoints');

      if (!waypoints || !waypoints.saved.length) {
        return B.sayAt(player, 'You haven\'t saved any waypoints.');
      }

      B.sayAt(player, 'Waypoints:');
      for (var i = 0; i < waypoints.saved.length; i++) {
        const room = state.RoomManager.getRoom(waypoints.saved[i]);
        B.sayAt(player, sprintf('%2s) %s%s', i + 1, waypoints.home === room.entityReference ? '(H) ' : '', room.title));
      }
    }
  });

  subcommands.add({
    name: 'save',
    command: state => (args, player) => {
      if (!player.room.hasBehavior('waypoint')) {
        return B.sayAt(player, 'You are not at a wayshrine.');
      }

      let waypoints = player.getMeta('waypoints');

      waypoints = waypoints || {
        saved: [],
        home: null
      };

      waypoints.saved.push(player.room.entityReference);
      player.setMeta('waypoints', waypoints);
      B.sayAt(player, `${player.room.title} saved to your waypoints. Use '<b>waypoint home</b>' to set as your home waypoint.`);
    }
  });

  subcommands.add({
    name: 'home',
    command: state => (args, player) => {
      if (!player.room.hasBehavior('waypoint')) {
        return B.sayAt(player, 'You are not at a wayshrine.');
      }

      const waypoints = player.getMeta('waypoints');

      if (!waypoints || !waypoints.saved.includes(player.room.entityReference)) {
        return B.sayAt(player, 'You haven\'t saved this wayshrine.');
      }

      player.setMeta('waypoints.home', player.room.entityReference);
      B.sayAt(player, `${player.room.title} is now your home waypoint.`);
    }
  });

  subcommands.add({<commit_msg>Fix bug with saving the same waypoint more than once<commit_after>'use strict';

const sprintf = require('sprintf-js').sprintf;

module.exports = srcPath => {
  const B = require(srcPath + 'Broadcast');
  const CommandManager = require(srcPath + 'CommandManager');

  const subcommands = new CommandManager();
  subcommands.add({
    name: 'list',
    command: state => (args, player) => {
      const waypoints = player.getMeta('waypoints');

      if (!waypoints || !waypoints.saved.length) {
        return B.sayAt(player, 'You haven\'t saved any waypoints.');
      }

      B.sayAt(player, 'Waypoints:');
      for (var i = 0; i < waypoints.saved.length; i++) {
        const room = state.RoomManager.getRoom(waypoints.saved[i]);
        B.sayAt(player, sprintf('%2s) %s%s', i + 1, waypoints.home === room.entityReference ? '(H) ' : '', room.title));
      }
    }
  });

  subcommands.add({
    name: 'save',
    command: state => (args, player) => {
      if (!player.room.hasBehavior('waypoint')) {
        return B.sayAt(player, 'You are not at a wayshrine.');
      }

      let waypoints = player.getMeta('waypoints');

      waypoints = waypoints || {
        saved: [],
        home: null
      };

      if (waypoints.saved.includes(player.room.entityReference)) {
        return B.sayAt(player, 'You already saved this waypoint.');
      }

      waypoints.saved.push(player.room.entityReference);
      player.setMeta('waypoints', waypoints);
      B.sayAt(player, `${player.room.title} saved to your waypoints. Use '<b>waypoint home</b>' to set as your home waypoint.`);
    }
  });

  subcommands.add({
    name: 'home',
    command: state => (args, player) => {
      if (!player.room.hasBehavior('waypoint')) {
        return B.sayAt(player, 'You are not at a wayshrine.');
      }

      const waypoints = player.getMeta('waypoints');

      if (!waypoints || !waypoints.saved.includes(player.room.entityReference)) {
        return B.sayAt(player, 'You haven\'t saved this wayshrine.');
      }

      player.setMeta('waypoints.home', player.room.entityReference);
      B.sayAt(player, `${player.room.title} is now your home waypoint.`);
    }
  });

  subcommands.add({
{'fraction_non_alphanumeric': 0.16226504877468476, 'fraction_numerical': 0.0014275517487508922, 'mean_word_length': 2.907063197026022, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '3945124', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1317, 'n_words': 303}