<commit_before>/* @flow */
'use strict';

const Queue = require('bull');
const TelegramApiClient = require('./lib/telegram-api-client');
const AddbApiClient = require('./lib/addb-api-client');
const config = require('./lib/config');
const logger = require('./lib/logger');
const Repository = require('./lib/repository');
const repository = new Repository();
const queueLogger = logger.child({ source: 'queue' });
const workerLogger = logger.child({ source: 'worker' });

const queueConfig = config.get('queue');
const botConfig = config.get('bot');
const addbConfig = config.get('addb');
const updatesQueue = new Queue('updates', queueConfig.redis.port, queueConfig.redis.host);
const telegramApiClient = new TelegramApiClient(botConfig.token);
const addbApiClient = new AddbApiClient(addbConfig.key);
const inlineResultsPerPage = 10;
const maxIngredientsPerChat = 10;
const maxSearchResultsPerPage = 2;
const maxUnmatchedIngredients = 1;
const ingredientCodeRegEx = /^.*\((.+)\)$/;
const samples = ['orange', 'vodka', 'lime', 'rum', 'ice', 'mint', 'cinnamon', 'aperol', 'syrup'];
const ingredientTypes = {
  BaseSpirit: {
  },
  berries: {
    icon: '🍓',
    notSignificant: true
  },
  brandy: {
  },
  decoration: {
    notSignificant: true
  },
  fruits: {
    icon: '🍐',
    notSignificant: true
  },
  gin: {
  },
  ice: {
    notSignificant: true
  },
  mixers: {
    notSignificant: true
  },
  others: {
    notSignificant: true
  },
  rum: {
  },
  'spices-herbs': {
  },
  'spirits-other': {
  },
  tequila: {
  },
  vodka: {
  },
  whisky: {
  },
};

updatesQueue
  .on('ready', () => queueLogger.info('Queue is ready to process jobs'))
  .on('error', err => queueLogger.error(err, 'Queue error'))
  .on('cleaned', (jobs, type) => queueLogger.info(`Cleaned ${jobs.length} ${type} jobs`))
  .on('failed', (job, err) => queueLogger.warn(err, `Job ${job.jobId} failed`))
  .on('stalled', job => queueLogger.warn(`Job ${job.jobId} stalled`));

function getIngredientURL(ingredientCode) {
  return `http://www.absolutdrinks.com/en/drinks/with/${ingredientCode}/`;
}

function getIngredientImageURL(ingredientCode) {
  return `http://assets.absolutdrinks.com/ingredients/200x200/${ingredientCode}.png`;
}

function getDrinkURL(drinkId) {
  return `http://www.absolutdrinks.com/en/drinks/${drinkId}`;
}

function getDrinkImageURL(drinkId) {
  return `http://assets.absolutdrinks.com/drinks/${drinkId}.png`;
}

function getRandomIngredient() {
  return samples[Math.floor(Math.random() * samples.length)];
}

function getChosenIngredientMessage(ingredient) {
  return `/add@${botConfig.name} *${ingredient.id}*`;
}

function getClearedIngredientsMessage() {
  return 'Cleared available ingredients.';
}

function getRemoveIngredientMessage() {
  return 'Which ingredient you would like to remove?';
}

function getRemovedIngredientMessage(ingredient) {
  return `Removed ${ingredient}.`;
}

function getAddedIngredientMessage(ingredient) {
  return `Added ${ingredient}.`;
}

function getTooManyIngredientsMessage() {
  return `You already have ${maxIngredientsPerChat} ingredients in this chat. I can't handle more.`;
}

function getIngredientExistsMessage() {
  return 'You already have one.';
}

function getNextPageHelpMessage() {
  return 'To view other results tap /next.';
}

function getNoMoreResultsMessage() {
  return 'No more search results. Modify your ingredients list and do /search again.';
}

function getInlineHelpMessage() {
  return 'Start typing an ingredient name. Tap for help.';
}

function getNoDrinksFoundMessage() {
  return 'I\'m sorry, but I couldn\'t find any matching drinks. ' +
    'Try the different set of ingredients.';
}

function getIngredientListItem(item, isPrivate) {
  let base = `- *${item.ingredientName}* [(details)](${getIngredientURL(item.ingredientCode)})`;
  if (!isPrivate) {
    base += ` by ${item.getFullName()}`;
  }<commit_msg>Add more command hints to bot messages<commit_after>/* @flow */
'use strict';

const Queue = require('bull');
const TelegramApiClient = require('./lib/telegram-api-client');
const AddbApiClient = require('./lib/addb-api-client');
const config = require('./lib/config');
const logger = require('./lib/logger');
const Repository = require('./lib/repository');
const repository = new Repository();
const queueLogger = logger.child({ source: 'queue' });
const workerLogger = logger.child({ source: 'worker' });

const queueConfig = config.get('queue');
const botConfig = config.get('bot');
const addbConfig = config.get('addb');
const updatesQueue = new Queue('updates', queueConfig.redis.port, queueConfig.redis.host);
const telegramApiClient = new TelegramApiClient(botConfig.token);
const addbApiClient = new AddbApiClient(addbConfig.key);
const inlineResultsPerPage = 10;
const maxIngredientsPerChat = 10;
const maxSearchResultsPerPage = 2;
const maxUnmatchedIngredients = 1;
const ingredientCodeRegEx = /^.*\((.+)\)$/;
const samples = ['orange', 'vodka', 'lime', 'rum', 'ice', 'mint', 'cinnamon', 'aperol', 'syrup'];
const ingredientTypes = {
  BaseSpirit: {
  },
  berries: {
    icon: '🍓',
    notSignificant: true
  },
  brandy: {
  },
  decoration: {
    notSignificant: true
  },
  fruits: {
    icon: '🍐',
    notSignificant: true
  },
  gin: {
  },
  ice: {
    notSignificant: true
  },
  mixers: {
    notSignificant: true
  },
  others: {
    notSignificant: true
  },
  rum: {
  },
  'spices-herbs': {
  },
  'spirits-other': {
  },
  tequila: {
  },
  vodka: {
  },
  whisky: {
  },
};

updatesQueue
  .on('ready', () => queueLogger.info('Queue is ready to process jobs'))
  .on('error', err => queueLogger.error(err, 'Queue error'))
  .on('cleaned', (jobs, type) => queueLogger.info(`Cleaned ${jobs.length} ${type} jobs`))
  .on('failed', (job, err) => queueLogger.warn(err, `Job ${job.jobId} failed`))
  .on('stalled', job => queueLogger.warn(`Job ${job.jobId} stalled`));

function getIngredientURL(ingredientCode) {
  return `http://www.absolutdrinks.com/en/drinks/with/${ingredientCode}/`;
}

function getIngredientImageURL(ingredientCode) {
  return `http://assets.absolutdrinks.com/ingredients/200x200/${ingredientCode}.png`;
}

function getDrinkURL(drinkId) {
  return `http://www.absolutdrinks.com/en/drinks/${drinkId}`;
}

function getDrinkImageURL(drinkId) {
  return `http://assets.absolutdrinks.com/drinks/${drinkId}.png`;
}

function getRandomIngredient() {
  return samples[Math.floor(Math.random() * samples.length)];
}

function getChosenIngredientMessage(ingredient) {
  return `/add@${botConfig.name} *${ingredient.id}*`;
}

function getClearedIngredientsMessage() {
  return 'Cleared available ingredients.';
}

function getRemoveIngredientMessage() {
  return 'Which ingredient you would like to remove?';
}

function getRemovedIngredientMessage(ingredient) {
  return `Removed ${ingredient}.`;
}

function getAddedIngredientMessage(ingredient) {
  return `Added ${ingredient}. ` +
    'You may add more ingredients or use /search to find matching drinks.';
}

function getTooManyIngredientsMessage() {
  return `You already have ${maxIngredientsPerChat} ingredients in this chat. I can't handle more.`;
}

function getIngredientExistsMessage() {
  return 'You already have one. You may check your ingredients with /list.';
}

function getNextPageHelpMessage() {
  return 'To view other results tap /next.';
}

function getNoMoreResultsMessage() {
  return 'No more search results. Modify your ingredients list and do /search again.';
}

function getInlineHelpMessage() {
  return 'Start typing an ingredient name. Tap for help.';
}

function getNoDrinksFoundMessage() {
  return 'I\'m sorry, but I couldn\'t find any matching drinks. ' +
    'Try the different set of ingredients.';
}

function getIngredientListItem(item, isPrivate) {
  let base = `- *${item.ingredientName}* [(details)](${getIngredientURL(item.ingredientCode)})`;
  if (!isPrivate) {
    base += ` by ${item.getFullName()}`;
  }
{'fraction_non_alphanumeric': 0.1574892649659005, 'fraction_numerical': 0.0030310684516291994, 'mean_word_length': 4.738405797101449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4167445', 'n_tokens_mistral': 2739, 'n_tokens_neox': 2674, 'n_words': 601}