Skip to content

Commit

Permalink
✨ Mask sensitive information in player id
Browse files Browse the repository at this point in the history
  • Loading branch information
luoshuijs authored Aug 26, 2023
1 parent 54b8ee6 commit 468ed22
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion modules/gacha_log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
UIGFModel,
)
from utils.const import PROJECT_ROOT
from utils.uid import mask_number

if TYPE_CHECKING:
from core.dependence.assets import AssetsService
Expand Down Expand Up @@ -533,7 +534,7 @@ async def get_analysis(self, user_id: int, player_id: int, pool: BannerType, ass
last_time = data[0].time.strftime("%Y-%m-%d %H:%M")
first_time = data[-1].time.strftime("%Y-%m-%d %H:%M")
return {
"uid": player_id,
"uid": mask_number(player_id),
"allNum": total,
"type": pool.value,
"typeName": pool_name,
Expand Down
3 changes: 2 additions & 1 deletion modules/pay_log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from modules.pay_log.error import PayLogAuthkeyTimeout, PayLogInvalidAuthkey, PayLogNotFound
from modules.pay_log.models import PayLog as PayLogModel, BaseInfo
from utils.const import PROJECT_ROOT
from utils.uid import mask_number

try:
import ujson as jsonlib
Expand Down Expand Up @@ -240,7 +241,7 @@ async def get_analysis(self, user_id: int, player_id: int):
if price_data[i]["count"] > 0
]
return {
"uid": player_id,
"uid": mask_number(player_id),
"datas": datas,
"bar_data": month_datas,
"pie_data": pie_datas,
Expand Down
3 changes: 2 additions & 1 deletion plugins/genshin/abyss.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from core.services.template.services import TemplateService
from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper
from utils.log import logger
from utils.uid import mask_number

try:
import ujson as jsonlib
Expand Down Expand Up @@ -220,7 +221,7 @@ def json_encoder(value):

render_data["time"] = time
render_data["stars"] = total_stars
render_data["uid"] = uid
render_data["uid"] = mask_number(uid)
render_data["floor_colors"] = {
1: "#374952",
2: "#374952",
Expand Down
3 changes: 2 additions & 1 deletion plugins/genshin/avatar_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from modules.wiki.base import Model
from plugins.tools.genshin import CharacterDetails, GenshinHelper
from utils.log import logger
from utils.uid import mask_number

if TYPE_CHECKING:
from telegram import Update
Expand Down Expand Up @@ -183,7 +184,7 @@ async def avatar_list(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE"):
name_card, avatar, nickname, rarity = await self.get_final_data(client.player_id, user)

render_data = {
"uid": client.player_id, # 玩家uid
"uid": mask_number(client.player_id), # 玩家uid
"nickname": nickname, # 玩家昵称
"avatar": avatar, # 玩家头像
"rarity": rarity, # 玩家头像对应的角色星级
Expand Down
9 changes: 5 additions & 4 deletions plugins/genshin/daily/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from metadata.genshin import AVATAR_DATA, HONEY_DATA
from plugins.tools.genshin import CharacterDetails, PlayerNotFoundError, CookiesNotFoundError, GenshinHelper
from utils.log import logger
from utils.uid import mask_number

try:
import ujson as jsonlib
Expand Down Expand Up @@ -249,7 +250,7 @@ async def daily_material(self, update: "Update", context: "ContextTypes.DEFAULT_
client, user_data = await self._get_data_from_user(user)

await message.reply_chat_action(ChatAction.TYPING)
render_data = RenderData(title=title, time=time, uid=client.player_id if client else client)
render_data = RenderData(title=title, time=time, uid=mask_number(client.player_id) if client else client)

calculator_sync: bool = True # 默认养成计算器同步为开启
for type_ in ["avatar", "weapon"]:
Expand Down Expand Up @@ -480,9 +481,9 @@ async def task(item_id, name, item_type):
results = await asyncio.gather(*task_list, return_exceptions=True) # 等待所有任务执行完成
for result in results:
if isinstance(result, TimeoutException):
notice_text = f"{result.__class__.__name__} 图标素材下载过程中请求超时.\n有关详细信息,请查看日志"
notice_text = "图标素材下载过程中请求超时\n有关详细信息,请查看日志"
elif isinstance(result, Exception):
notice_text = f"{result.__class__.__name__} 图标素材下载过程中发生异常.\n有关详细信息,请查看日志"
notice_text = "图标素材下载过程中发生异常\n有关详细信息,请查看日志"
break
try:
await message.edit_text(notice_text)
Expand Down Expand Up @@ -520,7 +521,7 @@ class AreaData(BaseModel):
class RenderData(BaseModel):
title: str # 页面标题,主要用于显示星期几
time: str # 页面时间
uid: Optional[int] = None # 用户UID
uid: Optional[str] = None # 用户UID
character: List[AreaData] = [] # 角色数据
weapon: List[AreaData] = [] # 武器数据

Expand Down
3 changes: 2 additions & 1 deletion plugins/genshin/daily_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from core.services.template.services import TemplateService
from plugins.tools.genshin import GenshinHelper
from utils.log import logger
from utils.uid import mask_number

if TYPE_CHECKING:
from simnet import GenshinClient
Expand Down Expand Up @@ -62,7 +63,7 @@ async def _get_daily_note(self, client: "GenshinClient") -> RenderResult:
transformer_recovery_time = daily_info.transformer_recovery_time.strftime("%m-%d %H:%M")

render_data = {
"uid": client.player_id,
"uid": mask_number(client.player_id),
"day": day,
"resin_recovery_time": resin_recovery_time,
"current_resin": daily_info.current_resin,
Expand Down
3 changes: 2 additions & 1 deletion plugins/genshin/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from core.services.template.services import TemplateService
from plugins.tools.genshin import GenshinHelper
from utils.log import logger
from utils.uid import mask_number

if TYPE_CHECKING:
from telegram import Update
Expand Down Expand Up @@ -55,7 +56,7 @@ def format_amount(amount: int) -> str:
return f"{round(amount / 10000, 2)}w" if amount >= 10000 else amount

ledger_data = {
"uid": client.player_id,
"uid": mask_number(client.player_id),
"day": diary_info.month,
"current_primogems": format_amount(diary_info.month_data.current_primogems),
"gacha": int(diary_info.month_data.current_primogems / 160),
Expand Down
3 changes: 2 additions & 1 deletion plugins/genshin/player_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from utils.helpers import download_resource
from utils.log import logger
from utils.patch.aiohttp import AioHttpTimeoutException
from utils.uid import mask_number

if TYPE_CHECKING:
from enkanetwork import CharacterInfo, EquipmentsStats
Expand Down Expand Up @@ -486,7 +487,7 @@ async def render(self):
artifact_total_score_label = r[0]

data = {
"uid": self.uid,
"uid": mask_number(self.uid),
"character": self.character,
"stats": await self.de_stats(),
"weapon": self.find_weapon(),
Expand Down
2 changes: 1 addition & 1 deletion plugins/genshin/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def command_start(self, update: Update, context: CallbackContext) -> None:
not filters.ChatType.PRIVATE.filter(message),
)
reply_message = await message.reply_text(
f"UID {exc.uid} 签到失败,触发验证码风控,请尝试点击下方按钮重新签到", allow_sending_without_reply=True, reply_markup=button
"签到失败,触发验证码风控,请尝试点击下方按钮重新签到", allow_sending_without_reply=True, reply_markup=button
)
if filters.ChatType.GROUPS.filter(reply_message):
self.add_delete_message_job(reply_message)
Expand Down
3 changes: 2 additions & 1 deletion plugins/genshin/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from core.services.template.services import TemplateService
from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper
from utils.log import logger
from utils.uid import mask_number

if TYPE_CHECKING:
from telegram import Update
Expand Down Expand Up @@ -77,7 +78,7 @@ async def render(self, client: "GenshinClient", uid: Optional[int] = None) -> Re
user_info = user_info.copy(deep=True)

data = {
"uid": uid,
"uid": mask_number(uid),
"info": user_info.info,
"stats": user_info.stats,
"explorations": user_info.explorations,
Expand Down
9 changes: 9 additions & 0 deletions utils/uid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import re


def mask_number(number):
number_str = str(number)
if len(number_str) == 9:
masked_number = re.sub(r"(\d{2})(\d{4})(\d{3})", r"\1****\3", number_str)
return masked_number
return "Invalid input"

0 comments on commit 468ed22

Please sign in to comment.