<commit_before>'use strict';

// DB
const { getUser } = require('../../stores/user');

const checkUsernameHandler = async ({ message }, next) => {
	if (!message.entities) {
		return next();
	}
	const messageArr = message.text ? message.text.split(' ') : '';
	const isCommand = /^\/\w+/.test(messageArr[0]);
	const hasMention = message.entities.some(entity =>
		entity.type === 'mention');
	const hasTextMention = message.entities.some(entity =>
		entity.type === 'text_mention');

	if (!isCommand) {
		return next();
	}

	if (hasMention) {
		const [ , username ] = messageArr;
		const isUsername = /^@\w+/.test(username);
		if (!isUsername) {
			return next();
		}
		const user = await getUser({ username: username.replace('@', '') });
		if (user) {
			message.text = message.text.replace(` ${username}`, '');
			message.commandMention = user;
		}
		return next();
	}

	if (hasTextMention) {
		const [ { user } ] = message.entities.filter(entity => entity.user);
		const name = user.first_name;
		if (name.split(' ')[0] !== messageArr[1]) {
			return next();
		}
		message.text = message.text.replace(` ${name}`, '');
		message.commandMention = user;
		return next();
	}
	return next();
};

module.exports = checkUsernameHandler;<commit_msg>commands now work with id<commit_after>'use strict';

// DB
const { getUser } = require('../../stores/user');

const checkUsernameHandler = async ({ message }, next) => {
	if (!message.entities) {
		return next();
	}
	const messageArr = message.text ? message.text.split(' ') : '';
	const isCommand = /^\/\w+/.test(messageArr[0]);
	const hasMention = message.entities.some(entity =>
		entity.type === 'mention');
	const hasTextMention = message.entities.some(entity =>
		entity.type === 'text_mention');
	const hasId = /^\d+/.test(messageArr[1]);

	if (!isCommand) {
		return next();
	}

	if (hasMention) {
		const [ , username ] = messageArr;
		const isUsername = /^@\w+/.test(username);
		if (!isUsername) {
			return next();
		}
		const user = await getUser({ username: username.replace('@', '') });
		if (user) {
			message.text = message.text.replace(` ${username}`, '');
			message.commandMention = user;
		}
		return next();
	}

	if (hasTextMention) {
		const [ { user } ] = message.entities.filter(entity => entity.user);
		const name = user.first_name;
		if (name.split(' ')[0] !== messageArr[1]) {
			return next();
		}
		message.text = message.text.replace(` ${name}`, '');
		message.commandMention = user;
		return next();
	}

	if (hasId) {
		const [ , id ] = messageArr;
		const user = await getUser({ id: Number(id) });
		console.log(id, user);
		if (user) {
			message.text = message.text.replace(` ${id}`, '');
			message.commandMention = user;
		}
		return next();
	}
	return next();
};

module.exports = checkUsernameHandler;
{'fraction_non_alphanumeric': 0.19468390804597702, 'fraction_numerical': 0.002514367816091954, 'mean_word_length': 3.680672268907563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6795675', 'n_tokens_mistral': 1003, 'n_tokens_neox': 938, 'n_words': 206}