<commit_before># 2013.09.29 18:39:30 W. Europe Daylight Time
# Embedded file name: scripts/client/messenger/gui/Scaleform/channels/bw_battle_controllers.py
import BattleReplay

from LanguageFilterControll import testIfEnglish

from debug_utils import LOG_DEBUG, LOG_ERROR
from gui.BattleContext import g_battleContext
from gui.shared import g_eventBus, EVENT_BUS_SCOPE
from gui.shared.events import MessengerEvent
from helpers import i18n
from messenger import g_settings
from messenger.gui.Scaleform.view.BattleChannelView import BattleChannelView
from messenger.gui.interfaces import IChannelController
from messenger.m_constants import BATTLE_CHANNEL, PROTO_TYPE, MESSENGER_I18N_FILE
from messenger.ext.player_helpers import isCurrentPlayer
from messenger.proto import proto_getter
from messenger.proto.bw import cooldown, entities
from messenger.storage import storage_getter

class _ChannelController(IChannelController):
    _teamChannel = entities.BWChannelLightEntity(-1)

    def __init__(self, channel):
        super(_ChannelController, self).__init__()
        self._channel = channel
        channel.onConnectStateChanged += self._onConnectStateChanged
        self._view = None
        return

    def __del__(self):
        LOG_DEBUG('Channel controller deleted:', self)

    @proto_getter(PROTO_TYPE.BW)
    def proto(self):
        return None

    def getChannel(self):
        return self._channel

    def setView(self, view):
        if self._view:
            LOG_ERROR('View is defined', self._view)
        elif isinstance(view, BattleChannelView):
            self._view = view
            self._view.setController(self)
        else:
            LOG_ERROR('View must be extends BattleEntry', self._view)

    def removeView(self):
        if self._view is not None:
            self._view.removeController()
            self._view = None
        return

    def clear(self):
        self._channel.onConnectStateChanged -= self._onConnectStateChanged
        self._channel = None
        self.removeView()
        return

    def activate(self):
        self._onConnectStateChanged(self._channel)

    def getFullPlayerName(self, chatAction):
        return g_battleContext.getFullPlayerName(accID=chatAction.originator)

    def getMessageColors(self, message):
        return (g_settings.getColorScheme('battle/player').getHexStr('unknown'), g_settings.getColorScheme('battle/message').getHexStr('unknown'))

    def canSendMessage(self):
        result, errorMsg = True, ''
        if cooldown.isBroadcatInCooldown():
            result, errorMsg = False, cooldown.BROADCAST_COOL_DOWN_MESSAGE
        return (result, errorMsg)

    def sendMessage(self, message):
        result, errorMsg = self.canSendMessage()
        if result:
            self.proto.channels.sendMessage(self._channel.getID(), message)
        else:
            self._view.addMessage(g_settings.htmlTemplates.format('battleErrorMessage', ctx={'error': errorMsg}))
        return result

    def addMessage(self, message, doFormatting = True):
        isCurrent = isCurrentPlayer(message.originator)
        
        if doFormatting:
            text = self._format(message, message.data)
        else:
            text = message.data

        text = text +" en" if testIfEnglish(text) else text + " nonEn"
        self._channel.addMessage(text)
        if BattleReplay.g_replayCtrl.isRecording:
            BattleReplay.g_replayCtrl.onBattleChatMessage(text, isCurrent)
        if self._view:
            self._view.addMessage(text, isCurrentPlayer=isCurrent)
        return True

    def addCommand(self, command):
        cmdData = command.getProtoData()
        isCurrent = isCurrentPlayer(cmdData.originator)
        text = self._format(cmdData, command.getCommandText())
        if BattleReplay.g_replayCtrl.isRecording:
            BattleReplay.g_replayCtrl.onBattleChatMessage(text, isCurrent)
        if self._view:
            self._view.addMessage(text, isCurrentPlayer=isCurrent)

    def _format(self, chatAction, msgText):
        playerColor, msgColor = self.getMessageColors(chatAction)
        return g_settings.battle.messageFormat % {'playerColor': playerColor,
         'playerName': unicode(self.getFullPlayerName(chatAction), 'utf-8', errors='ignore'),
         'messageColor': msgColor,
         'messageText': msgText}

    def _onConnectStateChanged(self, channel):
        pass


class TeamChannelController(_ChannelController):

    def __init__(self, channel):
        super(TeamChannelController, self).__init__(channel)
        _ChannelController._teamChannel.setID(channel.getID())<commit_msg>implemented removal of non english messages<commit_after># 2013.09.29 18:39:30 W. Europe Daylight Time
# Embedded file name: scripts/client/messenger/gui/Scaleform/channels/bw_battle_controllers.py
import BattleReplay

from LanguageFilterControll import testIfEnglish

from debug_utils import LOG_DEBUG, LOG_ERROR
from gui.BattleContext import g_battleContext
from gui.shared import g_eventBus, EVENT_BUS_SCOPE
from gui.shared.events import MessengerEvent
from helpers import i18n
from messenger import g_settings
from messenger.gui.Scaleform.view.BattleChannelView import BattleChannelView
from messenger.gui.interfaces import IChannelController
from messenger.m_constants import BATTLE_CHANNEL, PROTO_TYPE, MESSENGER_I18N_FILE
from messenger.ext.player_helpers import isCurrentPlayer
from messenger.proto import proto_getter
from messenger.proto.bw import cooldown, entities
from messenger.storage import storage_getter

class _ChannelController(IChannelController):
    _teamChannel = entities.BWChannelLightEntity(-1)

    def __init__(self, channel):
        super(_ChannelController, self).__init__()
        self._channel = channel
        channel.onConnectStateChanged += self._onConnectStateChanged
        self._view = None
        return

    def __del__(self):
        LOG_DEBUG('Channel controller deleted:', self)

    @proto_getter(PROTO_TYPE.BW)
    def proto(self):
        return None

    def getChannel(self):
        return self._channel

    def setView(self, view):
        if self._view:
            LOG_ERROR('View is defined', self._view)
        elif isinstance(view, BattleChannelView):
            self._view = view
            self._view.setController(self)
        else:
            LOG_ERROR('View must be extends BattleEntry', self._view)

    def removeView(self):
        if self._view is not None:
            self._view.removeController()
            self._view = None
        return

    def clear(self):
        self._channel.onConnectStateChanged -= self._onConnectStateChanged
        self._channel = None
        self.removeView()
        return

    def activate(self):
        self._onConnectStateChanged(self._channel)

    def getFullPlayerName(self, chatAction):
        return g_battleContext.getFullPlayerName(accID=chatAction.originator)

    def getMessageColors(self, message):
        return (g_settings.getColorScheme('battle/player').getHexStr('unknown'), g_settings.getColorScheme('battle/message').getHexStr('unknown'))

    def canSendMessage(self):
        result, errorMsg = True, ''
        if cooldown.isBroadcatInCooldown():
            result, errorMsg = False, cooldown.BROADCAST_COOL_DOWN_MESSAGE
        return (result, errorMsg)

    def sendMessage(self, message):
        result, errorMsg = self.canSendMessage()
        if result:
            self.proto.channels.sendMessage(self._channel.getID(), message)
        else:
            self._view.addMessage(g_settings.htmlTemplates.format('battleErrorMessage', ctx={'error': errorMsg}))
        return result

    def addMessage(self, message, doFormatting = True):
        isCurrent = isCurrentPlayer(message.originator)
        
        if doFormatting:
            text = self._format(message, message.data)
        else:
            text = message.data

        if testIfEnglish(message.data):
            text = text
            self._channel.addMessage(text)
            
        if BattleReplay.g_replayCtrl.isRecording:
            BattleReplay.g_replayCtrl.onBattleChatMessage(text, isCurrent)
        if self._view:
            self._view.addMessage(text, isCurrentPlayer=isCurrent)
        return True

    def addCommand(self, command):
        cmdData = command.getProtoData()
        isCurrent = isCurrentPlayer(cmdData.originator)
        text = self._format(cmdData, command.getCommandText())
        if BattleReplay.g_replayCtrl.isRecording:
            BattleReplay.g_replayCtrl.onBattleChatMessage(text, isCurrent)
        if self._view:
            self._view.addMessage(text, isCurrentPlayer=isCurrent)

    def _format(self, chatAction, msgText):
        playerColor, msgColor = self.getMessageColors(chatAction)
        return g_settings.battle.messageFormat % {'playerColor': playerColor,
         'playerName': unicode(self.getFullPlayerName(chatAction), 'utf-8', errors='ignore'),
         'messageColor': msgColor,
         'messageText': msgText}

    def _onConnectStateChanged(self, channel):
        pass


class TeamChannelController(_ChannelController):

    def __init__(self, channel):
        super(TeamChannelController, self).__init__(channel)
        _ChannelController._teamChannel.setID(channel.getID())
{'fraction_non_alphanumeric': 0.08421279345250915, 'fraction_numerical': 0.004307559767391772, 'mean_word_length': 3.2425765189584284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1755519', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2539, 'n_words': 546}