<commit_before>'use strict';

const _ = require('underscore');

const REGEX_MULTI = /가챠|뽑기|gacha|gasha|가샤|ガシャ|がしゃ|ガチャ|がちゃ/;
const REGEX_SINGLE = /단챠|単発/;

class Stream {
	constructor(twit, twit_sub) {
		let self = this;
		self.twit = twit;
		self.twit_sub = twit_sub;
	}
	
	startStream() {
		let self = this;
		
		let stream = self.twit.stream('user');
		let stream_sub = self.twit_sub.stream('user');
		
		stream.on('follow', (data) => {
			if(data.event === 'follow' && data.source.screen_name !== 'drst_bot') {
				self.twit.post('friendships/create', {
					user_id: data.source.id_str
				}, (err, res) => {
					if(err) {
						console.log(err);
					}
				});
			}
		});
		
		stream.on('tweet', (data) => {
			if(!data.retweeted_status && !self.user.limit) {
				let flag = _.some(data.entities.user_mentions, (user) => {
					return user.screen_name === 'drst_bot';
				});
				
				if(flag) {
					let text = data.text.toLowerCase();
					if(text.match(REGEX_MULTI)) {
						self._replyMultiple(data);
					}
					else if(text.match(REGEX_SINGLE)) {
						self._replySingle(data);
					}
				}
			}
		});
		
		stream_sub.on('tweet', (data) => {
			if(!data.retweeted_status && !self.user.limit) {
				let flag = _.some(data.entities.user_mentions, (user) => {
					return user.screen_name === 'drst_bot_1';
				});
				flag &= _.every(data.entities.user_mentions, (user) => {
					return user.screen_name !== 'drst_bot';
				});
				
				if(flag) {
					let text = data.text.toLowerCase();
					if(text.match(REGEX_MULTI)) {
						self._replyMultiple(data);
					}
					else if(text.match(REGEX_SINGLE)) {
						self._replySingle(data);
					}
				}
			}
		});
	}
	
	_replyMultiple(data) {
		let self = this;
		
		let cards = self.card.pickMultipleCards();
		
		self.image.createImage(cards, (buffer) => {
			var str = '@' + data.user.screen_name + '\n';
			for(var i = 0; i < 10; ++i) {
				str += cards[i].rarity.toUpperCase() + ' ' + cards[i].name + '\n';
			}
			self._tweet(str, data.id_str, buffer);
		});
	}
	
	_replySingle(data) {
		var self = this;
		
		let card = self.card.pickSingleCard();
		
		self.image.createImage(card, (buffer) => {
			var str = '@' + data.user.screen_name + '\n';
			str += card.rarity.toUpperCase() + ' ' + card.name + '\n';<commit_msg>remove names<commit_after>'use strict';

const _ = require('underscore');

const REGEX_MULTI = /가챠|뽑기|gacha|gasha|가샤|ガシャ|がしゃ|ガチャ|がちゃ/;
const REGEX_SINGLE = /단챠|単発/;

class Stream {
	constructor(twit, twit_sub) {
		let self = this;
		self.twit = twit;
		self.twit_sub = twit_sub;
	}
	
	startStream() {
		let self = this;
		
		let stream = self.twit.stream('user');
		let stream_sub = self.twit_sub.stream('user');
		
		stream.on('follow', (data) => {
			if(data.event === 'follow' && data.source.screen_name !== 'drst_bot') {
				self.twit.post('friendships/create', {
					user_id: data.source.id_str
				}, (err, res) => {
					if(err) {
						console.log(err);
					}
				});
			}
		});
		
		stream.on('tweet', (data) => {
			if(!data.retweeted_status && !self.user.limit) {
				let flag = _.some(data.entities.user_mentions, (user) => {
					return user.screen_name === 'drst_bot';
				});
				
				if(flag) {
					let text = data.text.toLowerCase();
					if(text.match(REGEX_MULTI)) {
						self._replyMultiple(data);
					}
					else if(text.match(REGEX_SINGLE)) {
						self._replySingle(data);
					}
				}
			}
		});
		
		stream_sub.on('tweet', (data) => {
			if(!data.retweeted_status && !self.user.limit) {
				let flag = _.some(data.entities.user_mentions, (user) => {
					return user.screen_name === 'drst_bot_1';
				});
				flag &= _.every(data.entities.user_mentions, (user) => {
					return user.screen_name !== 'drst_bot';
				});
				
				if(flag) {
					let text = data.text.toLowerCase();
					if(text.match(REGEX_MULTI)) {
						self._replyMultiple(data);
					}
					else if(text.match(REGEX_SINGLE)) {
						self._replySingle(data);
					}
				}
			}
		});
	}
	
	_replyMultiple(data) {
		let self = this;
		
		let cards = self.card.pickMultipleCards();
		
		self.image.createImage(cards, (buffer) => {
			var str = '@' + data.user.screen_name + '\n';
			//for(var i = 0; i < 10; ++i) {
			//	str += cards[i].rarity.toUpperCase() + ' ' + cards[i].name + '\n';
			//}
			self._tweet(str, data.id_str, buffer);
		});
	}
	
	_replySingle(data) {
		var self = this;
		
		let card = self.card.pickSingleCard();
		
		self.image.createImage(card, (buffer) => {
			var str = '@' + data.user.screen_name + '\n';
			//str += card.rarity.toUpperCase() + ' ' + card.name + '\n';
{'fraction_non_alphanumeric': 0.18734952943751368, 'fraction_numerical': 0.0017509301816590063, 'mean_word_length': 2.7459016393442623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '5478200', 'n_tokens_mistral': 2184, 'n_tokens_neox': 1774, 'n_words': 266}