<commit_before>import scrapeIt from 'scrape-it';
import {RTMClient, WebClient} from '@slack/client';


const randomWord = async (): Promise<string> => {
    interface wordData {
	word: string;
    }
    const response = await scrapeIt<wordData>(
	'https://www.weblio.jp/content_find/?random-select=',
	{
	    word: {
		selector: 'h2.midashigo',
		attr: 'title',
	    }
	});
    return response.data.word;
};

interface SlackInterface {
    rtmClient: RTMClient;
    webClient: WebClient;
}

let messageCount = 0;
// About 1400 messages are posted in #sandbox per day on average
const threshold = 1400 / 10;
    
export default async ({rtmClient: rtm, webClient: slack}: SlackInterface) => {
    rtm.on('message', async message => {
	if (message.channel !== process.env.CHANNEL_SANDBOX)
	    return;
	messageCount++;
	if (messageCount >= threshold) {
	    messageCount = 0;
	    const word = await randomWord();
	    slack.chat.postMessage({
		channel: process.env.CHANNEL_SANDBOX,
		icon_emoji: ':context:',
		username: 'context free',
		text: word,
	    });
	}
    });
};<commit_msg>be independent of humans<commit_after>import scrapeIt from 'scrape-it';
import {RTMClient, WebClient} from '@slack/client';


const randomWord = async (): Promise<string> => {
    interface wordData {
	word: string;
    }
    const response = await scrapeIt<wordData>(
	'https://www.weblio.jp/content_find/?random-select=',
	{
	    word: {
		selector: 'h2.midashigo',
		attr: 'title',
	    }
	});
    return response.data.word;
};

const randomInterval = () =>
    1000 * 60 * (90 + (Math.random() - 0.5) * 2 * 60);

interface SlackInterface {
    rtmClient: RTMClient;
    webClient: WebClient;
}
    
export default async ({rtmClient: rtm, webClient: slack}: SlackInterface) => {
    async function postWord() {
	const word = await randomWord();
	slack.chat.postMessage({
	    channel: process.env.CHANNEL_SANDBOX,
	    icon_emoji: ':context:',
	    username: 'context free bot',
	    text: word,
	})
	setTimeout(postWord, randomInterval());
    }
    setTimeout(postWord, randomInterval());
};
{'fraction_non_alphanumeric': 0.14326923076923076, 'fraction_numerical': 0.012980769230769231, 'mean_word_length': 3.5837004405286343, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2058427', 'n_tokens_mistral': 745, 'n_tokens_neox': 679, 'n_words': 165}