<commit_before>import * as _ from 'lodash';
import * as TelegramBot from 'node-telegram-bot-api';
import * as Emoji from 'node-emoji';
import { Game } from './src/game';
import { Role } from "./src/role/role";
import { Player } from "./src/player/player";

interface GameSetting {
  id: string;
  roles: string[];
}

const gameSettings: GameSetting[] = [];
const games = [];
const token = process.env.BOT_TOKEN || '<KEY>';
const bot = new TelegramBot(token, { polling: true });
const roles = [
  // { name: Role.DOPPELGANGER, max: 1 },
  { name: Role.WEREWOLF, max: 2 },
  { name: Role.MINION, max: 1 },
  { name: Role.MASON, max: 2 },
  { name: Role.SEER, max: 1 },
  { name: Role.ROBBER, max: 1 },
  { name: Role.TROUBLEMAKER, max: 1 },
  { name: Role.DRUNK, max: 1 },
  { name: Role.INSOMNIAC, max: 1 },
  { name: Role.VILLAGER, max: 3 },
  { name: Role.HUNTER, max: 1 },
  { name: Role.TANNER, max: 1 }
];

bot.onText(/\/setting/, (msg) => {
  const btnPerLine = 3;
  const key = [];
  let pos = 0;

  gameSettings.push({ id: msg.chat.id, roles: []});
  _.map(roles, (role) => {
    let row = pos / btnPerLine | 0;
    if (!key[row]) key[row] = [];
    key[row].push({ text: role.name, callback_data: `SET_ROLE_${role.name}` });
    pos++;
  });

  bot.sendMessage(
    msg.chat.id,
    `${Emoji.get('gear')}  Please click to add roles`,
    {
      reply_markup: JSON.stringify({ inline_keyboard: key })
    }
  );
});

bot.onText(/\/newgame/, (msg) => {
  const id = msg.chat.id;
  // validation and make sure one channel only have one game
  if (_.find(games, (g) => g.id === id)) {
    bot.sendMessage(
      msg.chat.id,
      `${Emoji.get('no_entry_sign')}  Sorry. There is a game start in this channel, please move there and try \/join to join game`
    );
    return;
  }

  const gameSetting = _.find(gameSettings, setting => setting.id === msg.chat.id);
  
  if (!gameSetting) {
    bot.sendMessage(msg.chat.id,
      `${Emoji.get('no_entry_sign')}  Sorry. Please set the game setting before making a new game`
    );
    return;
  }

  const players: Player[] = [
    new Player({ id: msg.from.id, name: msg.from.first_name })
  ];

  games.push(new Game(id, bot, players, gameSetting.roles));
  bot.sendMessage(msg.chat.id, `${Emoji.get('star')}  Created a new game, please enter \/join to join this game`);
  console.log(`GAME ${id} has been created`);
});

bot.onText(/\/join/, (msg) => {
  const game = getGame(msg.chat.id);

  if (!game) return askForCreateNewGame(msg.chat.id);

  // validation game isStarted
  if (game.isStarted()) return bot.sendMessage(
    msg.chat.id,
    `${Emoji.get('no_entry_sign')}  Sorry. The game has been started, please wait until next game`
  );

  const player = new Player({
    id: msg.from.id,
    name: msg.from.first_name
  });

  game.addPlayer(msg, player);
});

bot.onText(/\/start/, (msg) => {
  const gameSetting = _.find(gameSettings, setting => setting.id === msg.chat.id);
  const game = getGame(msg.chat.id);

  if (!game) return askForCreateNewGame(msg.chat.id);
  if (!gameSetting) {
    bot.sendMessage(msg.message.chat.id, `${Emoji.get('no_entry_sign')}  Sorry. Please run /setting first`);

    return;
  }

  // TODO: hardcode to add dummy players
  if (game.players.length < gameSetting.roles.length)
    for(let i = game.players.length; i < 6; i++)
      game.players.push(new Player({ id: i, name: 'Player'+i }));

  game.start(msg)
    .then(() => {<commit_msg>fix hard code add dummy players<commit_after>import * as _ from 'lodash';
import * as TelegramBot from 'node-telegram-bot-api';
import * as Emoji from 'node-emoji';
import { Game } from './src/game';
import { Role } from "./src/role/role";
import { Player } from "./src/player/player";

interface GameSetting {
  id: string;
  roles: string[];
}

const gameSettings: GameSetting[] = [];
const games = [];
const token = process.env.BOT_TOKEN || '<KEY>';
const bot = new TelegramBot(token, { polling: true });
const roles = [
  // { name: Role.DOPPELGANGER, max: 1 },
  { name: Role.WEREWOLF, max: 2 },
  { name: Role.MINION, max: 1 },
  { name: Role.MASON, max: 2 },
  { name: Role.SEER, max: 1 },
  { name: Role.ROBBER, max: 1 },
  { name: Role.TROUBLEMAKER, max: 1 },
  { name: Role.DRUNK, max: 1 },
  { name: Role.INSOMNIAC, max: 1 },
  { name: Role.VILLAGER, max: 3 },
  { name: Role.HUNTER, max: 1 },
  { name: Role.TANNER, max: 1 }
];

bot.onText(/\/setting/, (msg) => {
  const btnPerLine = 3;
  const key = [];
  let pos = 0;

  gameSettings.push({ id: msg.chat.id, roles: []});
  _.map(roles, (role) => {
    let row = pos / btnPerLine | 0;
    if (!key[row]) key[row] = [];
    key[row].push({ text: role.name, callback_data: `SET_ROLE_${role.name}` });
    pos++;
  });

  bot.sendMessage(
    msg.chat.id,
    `${Emoji.get('gear')}  Please click to add roles`,
    {
      reply_markup: JSON.stringify({ inline_keyboard: key })
    }
  );
});

bot.onText(/\/newgame/, (msg) => {
  const id = msg.chat.id;
  // validation and make sure one channel only have one game
  if (_.find(games, (g) => g.id === id)) {
    bot.sendMessage(
      msg.chat.id,
      `${Emoji.get('no_entry_sign')}  Sorry. There is a game start in this channel, please move there and try \/join to join game`
    );
    return;
  }

  const gameSetting = _.find(gameSettings, setting => setting.id === msg.chat.id);
  
  if (!gameSetting) {
    bot.sendMessage(msg.chat.id,
      `${Emoji.get('no_entry_sign')}  Sorry. Please set the game setting before making a new game`
    );
    return;
  }

  const players: Player[] = [
    new Player({ id: msg.from.id, name: msg.from.first_name })
  ];

  games.push(new Game(id, bot, players, gameSetting.roles));
  bot.sendMessage(msg.chat.id, `${Emoji.get('star')}  Created a new game, please enter \/join to join this game`);
  console.log(`GAME ${id} has been created`);
});

bot.onText(/\/join/, (msg) => {
  const game = getGame(msg.chat.id);

  if (!game) return askForCreateNewGame(msg.chat.id);

  // validation game isStarted
  if (game.isStarted()) return bot.sendMessage(
    msg.chat.id,
    `${Emoji.get('no_entry_sign')}  Sorry. The game has been started, please wait until next game`
  );

  const player = new Player({
    id: msg.from.id,
    name: msg.from.first_name
  });

  game.addPlayer(msg, player);
});

bot.onText(/\/start/, (msg) => {
  const gameSetting = _.find(gameSettings, setting => setting.id === msg.chat.id);
  const game = getGame(msg.chat.id);

  if (!game) return askForCreateNewGame(msg.chat.id);
  if (!gameSetting) {
    bot.sendMessage(msg.message.chat.id, `${Emoji.get('no_entry_sign')}  Sorry. Please run /setting first`);

    return;
  }

  // TODO: hardcode to add dummy players
  if (game.players.length < gameSetting.roles.length)
    for(let i = game.players.length; i < gameSetting.roles.length; i++)
      game.players.push(new Player({ id: i, name: 'Player'+i }));

  game.start(msg)
    .then(() => {
{'fraction_non_alphanumeric': 0.1791648605692819, 'fraction_numerical': 0.0044791215142320475, 'mean_word_length': 3.164861612515042, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '2687553', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2529, 'n_words': 649}