<commit_before># TessuMod: Mod for integrating TeamSpeak into World of Tanks
# Copyright (C) 2014  <NAME>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

def on_talk_status_changed(user, talking):
	'''Called when TeamSpeak user's talk status changes.
	Parameters:
		user: a dict with WOT nickname (empty if not available) and TeamSpeak nickname 
		talking: True if talking, False otherwise
	'''
	if not settings().get_wot_nick_from_ts_metadata():
		user["wot"] = ""
	player_name = user["wot"] if user["wot"] else map_nick_to_wot_nick(extract_nick(user["ts"]))
	talk_status(player_name, talking)
	if talking:
		# set talking state immediately
		update_player_speak_status(player_name)
	else:
		# keep talking state for a little longer
		BigWorld.callback(settings().get_speak_stop_delay(), utils.with_args(update_player_speak_status, player_name))

def extract_nick(ts_nickname):
	'''Extracts WOT nickname (or something that can be passed to mapping
	rules) from 'ts_nickname' using regexp patterns defined in ini-file's
	'nick_extract_patterns'-key.
	Returns 'ts_nickname' if none of the patterns matched.
	'''
	for pattern in settings().get_nick_extract_patterns():
		matches = pattern.match(ts_nickname)
		if matches is not None:
			LOG_DEBUG("TS nickname '{0}' matched to regexp pattern '{1}'".format(ts_nickname, pattern.pattern))
			return matches.group(1)
	return ts_nickname

def map_nick_to_wot_nick(ts_nickname):
	'''Returns 'ts_nickname's matching WOT nickname using values from
	ini-file's [NameMappings] section.
	Returns 'ts_nickname' if mapping didn't exist for it.
	'''
	mapping = settings().get_name_mappings()
	try:
		wot_nickname = mapping[ts_nickname.lower()]
		LOG_DEBUG("TS nickname '{0}' mapped to WOT nickname '{1}'".format(ts_nickname, wot_nickname))
		return wot_nickname
	except:
		return ts_nickname

def talk_status(player_name, talking=None):
	player_name = player_name.lower()
	if talking is not None:
		g_talk_states[player_name] = talking
	try:
		return g_talk_states[player_name]
	except:
		return False

def update_player_speak_status(player_name):
	'''Updates given 'player_name's talking status to VOIP system and minimap.''' 
	player_name = player_name.lower()
	info = utils.get_player_info_by_name(player_name)
	if not info:
		return
	try:
		talking = is_voice_chat_speak_allowed(player_name) and talk_status(player_name)
		VOIP.getVOIPManager().setPlayerTalking(info["dbid"], talking)
	except:
		LOG_CURRENT_EXCEPTION()
	try:
		talking = (
			talk_status(player_name) and
			is_minimap_speak_allowed(player_name) and
			utils.get_vehicle(info["vehicle_id"])["isAlive"]
		)
		if talking:
			g_minimap_ctrl.start(info["vehicle_id"], settings().get_minimap_action(), settings().get_minimap_action_interval())
		else:
			g_minimap_ctrl.stop(info["vehicle_id"])
	except:
		LOG_CURRENT_EXCEPTION()

def is_voice_chat_speak_allowed(player_name):
	if not settings().is_voice_chat_notifications_enabled():
		return False
	if not settings().is_self_voice_chat_notifications_enabled() and utils.get_my_name().lower() == player_name.lower():
		return False
	return True

def is_minimap_speak_allowed(player_name):
	if not settings().is_minimap_notifications_enabled():
		return False
	if not settings().is_self_minimap_notifications_enabled() and utils.get_my_name().lower() == player_name.lower():
		return False<commit_msg>Ignored logging of an exception when player speaks in garage.<commit_after># TessuMod: Mod for integrating TeamSpeak into World of Tanks
# Copyright (C) 2014  <NAME>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

def on_talk_status_changed(user, talking):
	'''Called when TeamSpeak user's talk status changes.
	Parameters:
		user: a dict with WOT nickname (empty if not available) and TeamSpeak nickname 
		talking: True if talking, False otherwise
	'''
	if not settings().get_wot_nick_from_ts_metadata():
		user["wot"] = ""
	player_name = user["wot"] if user["wot"] else map_nick_to_wot_nick(extract_nick(user["ts"]))
	talk_status(player_name, talking)
	if talking:
		# set talking state immediately
		update_player_speak_status(player_name)
	else:
		# keep talking state for a little longer
		BigWorld.callback(settings().get_speak_stop_delay(), utils.with_args(update_player_speak_status, player_name))

def extract_nick(ts_nickname):
	'''Extracts WOT nickname (or something that can be passed to mapping
	rules) from 'ts_nickname' using regexp patterns defined in ini-file's
	'nick_extract_patterns'-key.
	Returns 'ts_nickname' if none of the patterns matched.
	'''
	for pattern in settings().get_nick_extract_patterns():
		matches = pattern.match(ts_nickname)
		if matches is not None:
			LOG_DEBUG("TS nickname '{0}' matched to regexp pattern '{1}'".format(ts_nickname, pattern.pattern))
			return matches.group(1)
	return ts_nickname

def map_nick_to_wot_nick(ts_nickname):
	'''Returns 'ts_nickname's matching WOT nickname using values from
	ini-file's [NameMappings] section.
	Returns 'ts_nickname' if mapping didn't exist for it.
	'''
	mapping = settings().get_name_mappings()
	try:
		wot_nickname = mapping[ts_nickname.lower()]
		LOG_DEBUG("TS nickname '{0}' mapped to WOT nickname '{1}'".format(ts_nickname, wot_nickname))
		return wot_nickname
	except:
		return ts_nickname

def talk_status(player_name, talking=None):
	player_name = player_name.lower()
	if talking is not None:
		g_talk_states[player_name] = talking
	try:
		return g_talk_states[player_name]
	except:
		return False

def update_player_speak_status(player_name):
	'''Updates given 'player_name's talking status to VOIP system and minimap.''' 
	player_name = player_name.lower()
	info = utils.get_player_info_by_name(player_name)
	if not info:
		return
	try:
		talking = is_voice_chat_speak_allowed(player_name) and talk_status(player_name)
		VOIP.getVOIPManager().setPlayerTalking(info["dbid"], talking)
	except:
		LOG_CURRENT_EXCEPTION()
	try:
		talking = (
			talk_status(player_name) and
			is_minimap_speak_allowed(player_name) and
			utils.get_vehicle(info["vehicle_id"])["isAlive"]
		)
		if talking:
			g_minimap_ctrl.start(info["vehicle_id"], settings().get_minimap_action(), settings().get_minimap_action_interval())
		else:
			g_minimap_ctrl.stop(info["vehicle_id"])
	except KeyError:
		# not an error, occurs in garage where there are no vehicles and
		# such no "vehicle_id"
		pass
	except:
		LOG_CURRENT_EXCEPTION()

def is_voice_chat_speak_allowed(player_name):
	if not settings().is_voice_chat_notifications_enabled():
		return False
	if not settings().is_self_voice_chat_notifications_enabled() and utils.get_my_name().lower() == player_name.lower():
		return False
	return True

def is_minimap_speak_allowed(player_name):
	if not settings().is_minimap_notifications_enabled():
		return False
	if not settings().is_self_minimap_notifications_enabled() and utils.get_my_name().lower() == player_name.lower():
		return False
{'fraction_non_alphanumeric': 0.09265330904675168, 'fraction_numerical': 0.005343047965998785, 'mean_word_length': 5.717781402936378, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3268405', 'n_tokens_mistral': 2768, 'n_tokens_neox': 2611, 'n_words': 786}