<commit_before>import plugin from 'fastify-plugin';
import {Mutex} from 'async-mutex';
import {stripIndent} from 'common-tags';
import moment from 'moment';
import {MessageAttachment} from '@slack/web-api';
import {SlackInterface, SlashCommandEndpoint} from '../lib/slack';
import {getMemberIcon, getMemberName, mrkdwn} from '../lib/slackUtils';
import logger from '../lib/logger';
import State from '../lib/state';
import config from './config';
import * as views from './views';
import * as atcoder from './atcoder';
import * as anagol from './anagol';

const USERNAME = 'golfbot';
const ICON_EMOJI = ':golf:';

const mutex = new Mutex();

type ParseResult =
	| {
			type: 'none';
	  }
	| {
			type: 'error';
			message: string;
			subcommand?: string;
	  }
	| {
			type: 'help';
			subcommand?: string;
	  }
	| {
			type: 'join';
			service: string;
			username: string;
	  }
	| {
			type: 'whoami';
	  }
	| {
			type: 'post';
	  }
	| {
			type: 'list';
	  }
	| {
			type: 'remove';
	  };

const parseMessage = (text: string): ParseResult | null => {
	let re: RegExp;
	let match: RegExpMatchArray | null;

	// call
	re = /^@golfbot\b\s*/;
	match = re.exec(text);
	if (!match) return null;
	text = text.replace(re, '');

	// subcommand
	re = /^(?<subcommand>[a-z0-9-]+)\b\s*/i;
	match = re.exec(text);
	if (!match) return {type: 'none'};
	const {subcommand} = match.groups!;
	text = text.replace(re, '');

	switch (subcommand) {
		case 'join': {
			re = /^(?<service>atcoder|anagol)\s+(?<username>[a-z0-9-]+)\s*$/i;
			match = re.exec(text);
			if (!match) {
				return {type: 'error', message: `引数がおかしいよ`, subcommand: 'join'};
			}
			const {service, username} = match.groups!;
			return {type: 'join', service, username};
		}
		case 'whoami': {
			return {type: 'whoami'};
		}
		case 'post': {
			return {type: 'post'};
		}
		case 'list': {
			return {type: 'list'};
		}
		case 'remove': {
			return {type: 'remove'};
		}
		case 'help': {
			re = /^(?<subcommand>[a-z0-9-]+)\s*$/i;<commit_msg>golfbot: change username regexp<commit_after>import plugin from 'fastify-plugin';
import {Mutex} from 'async-mutex';
import {stripIndent} from 'common-tags';
import moment from 'moment';
import {MessageAttachment} from '@slack/web-api';
import {SlackInterface, SlashCommandEndpoint} from '../lib/slack';
import {getMemberIcon, getMemberName, mrkdwn} from '../lib/slackUtils';
import logger from '../lib/logger';
import State from '../lib/state';
import config from './config';
import * as views from './views';
import * as atcoder from './atcoder';
import * as anagol from './anagol';

const USERNAME = 'golfbot';
const ICON_EMOJI = ':golf:';

const mutex = new Mutex();

type ParseResult =
	| {
			type: 'none';
	  }
	| {
			type: 'error';
			message: string;
			subcommand?: string;
	  }
	| {
			type: 'help';
			subcommand?: string;
	  }
	| {
			type: 'join';
			service: string;
			username: string;
	  }
	| {
			type: 'whoami';
	  }
	| {
			type: 'post';
	  }
	| {
			type: 'list';
	  }
	| {
			type: 'remove';
	  };

const parseMessage = (text: string): ParseResult | null => {
	let re: RegExp;
	let match: RegExpMatchArray | null;

	// call
	re = /^@golfbot\b\s*/;
	match = re.exec(text);
	if (!match) return null;
	text = text.replace(re, '');

	// subcommand
	re = /^(?<subcommand>[a-z0-9-]+)\b\s*/i;
	match = re.exec(text);
	if (!match) return {type: 'none'};
	const {subcommand} = match.groups!;
	text = text.replace(re, '');

	switch (subcommand) {
		case 'join': {
			re = /^(?<service>atcoder|anagol)\s+(?<username>.+?)\s*$/i;
			match = re.exec(text);
			if (!match) {
				return {type: 'error', message: `引数がおかしいよ`, subcommand: 'join'};
			}
			const {service, username} = match.groups!;
			return {type: 'join', service, username};
		}
		case 'whoami': {
			return {type: 'whoami'};
		}
		case 'post': {
			return {type: 'post'};
		}
		case 'list': {
			return {type: 'list'};
		}
		case 'remove': {
			return {type: 'remove'};
		}
		case 'help': {
			re = /^(?<subcommand>[a-z0-9-]+)\s*$/i;
{'fraction_non_alphanumeric': 0.20124843945068663, 'fraction_numerical': 0.0024968789013732834, 'mean_word_length': 3.30752688172043, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3550650', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1536, 'n_words': 372}