NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

util.py (2832B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\chat\client\util.py
      2 import re
      3 import trinity
      4 import carbonui
      5 from carbon.common.script.util.commonutils import StripTags
      6 from eveexceptions import UserError
      7 from eve.common.script.sys.idCheckers import IsNewbieSystem, IsCareerAgentSystem, IsStarterNPCCorporation
      8 from chatutil import StripBreaks
      9 from chat.common.const import ChatCategory, LOCAL_CHAT_CATEGORIES
     10 from chat.client.const import MAX_MESSAGE_SAFEGUARD_LENGTH
     11 from chat.client.hide_messages import get_hide_message_pattern
     12 _NEW_PLAYER_CHAT_BANNED_PATTERN = re.compile('|'.join((re.escape(word) for word in ['/signup?invc='])), re.IGNORECASE)
     13 
     14 def get_chat_default_width():
     15     device_width = trinity.device.width
     16     if device_width >= carbonui.IdealSize.SIZE_1680:
     17         return 450
     18     if device_width >= carbonui.IdealSize.SIZE_1200:
     19         return 360
     20     return 260
     21 
     22 
     23 def get_chat_default_height():
     24     device_height = trinity.device.height
     25     if device_height >= carbonui.IdealSize.SIZE_1200:
     26         return 350
     27     if device_height >= carbonui.IdealSize.SIZE_960:
     28         return 320
     29     return 260
     30 
     31 
     32 def parse_pasted_text(text):
     33     text = text.replace('<t>', '  ')
     34     ignoredTags = ['b', 'i', 'u']
     35     ignoredTags += sm.GetService('helpPointer').FindTagToIgnore(text)
     36     text = StripTags(text, ignoredTags=ignoredTags)
     37     return text
     38 
     39 
     40 def parse_chat_message(text, truncate = True):
     41     text = StripBreaks(text)
     42     ignoredTags = ['b',
     43      'i',
     44      'u',
     45      'url',
     46      'br']
     47     text = StripTags(text, ignoredTags=ignoredTags)
     48     if truncate:
     49         text = truncate_chat_message(text)
     50     return text
     51 
     52 
     53 def truncate_chat_message(text):
     54     if len(text) > MAX_MESSAGE_SAFEGUARD_LENGTH:
     55         return text[:MAX_MESSAGE_SAFEGUARD_LENGTH - 5] + ' ...'
     56     return text
     57 
     58 
     59 def should_hide_message(channel_id, category_id, text):
     60     if _is_new_player_channel(category_id) and bool(_NEW_PLAYER_CHAT_BANNED_PATTERN.search(text)):
     61         return True
     62     if category_id in LOCAL_CHAT_CATEGORIES:
     63         category_id = ChatCategory.LOCAL
     64     hide_message_pattern = get_hide_message_pattern(channel_id, category_id)
     65     return hide_message_pattern and hide_message_pattern.search(text)
     66 
     67 
     68 def check_banned_message_in_new_player_channel(category_id, text):
     69     if _is_new_player_channel(category_id) and _NEW_PLAYER_CHAT_BANNED_PATTERN.search(text):
     70         raise UserError('ChatReferralLinkBanned')
     71 
     72 
     73 def _is_new_player_channel(category_id):
     74     if category_id == ChatCategory.LOCAL:
     75         return IsNewbieSystem(session.solarsystemid2) or IsCareerAgentSystem(session.solarsystemid2)
     76     elif category_id == ChatCategory.CORP:
     77         return IsStarterNPCCorporation(session.corpid)
     78     elif category_id == ChatCategory.SYSTEM:
     79         return True
     80     else:
     81         return False