Mask sensitive information in player id

This commit is contained in:
luoshuijs 2023-08-26 18:19:00 +08:00 committed by GitHub
parent 54b8ee65f7
commit 468ed22a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 31 additions and 13 deletions

View File

@ -41,6 +41,7 @@ from modules.gacha_log.models import (
UIGFModel, UIGFModel,
) )
from utils.const import PROJECT_ROOT from utils.const import PROJECT_ROOT
from utils.uid import mask_number
if TYPE_CHECKING: if TYPE_CHECKING:
from core.dependence.assets import AssetsService from core.dependence.assets import AssetsService
@ -533,7 +534,7 @@ class GachaLog:
last_time = data[0].time.strftime("%Y-%m-%d %H:%M") last_time = data[0].time.strftime("%Y-%m-%d %H:%M")
first_time = data[-1].time.strftime("%Y-%m-%d %H:%M") first_time = data[-1].time.strftime("%Y-%m-%d %H:%M")
return { return {
"uid": player_id, "uid": mask_number(player_id),
"allNum": total, "allNum": total,
"type": pool.value, "type": pool.value,
"typeName": pool_name, "typeName": pool_name,

View File

@ -11,6 +11,7 @@ from simnet.utils.player import recognize_genshin_server
from modules.pay_log.error import PayLogAuthkeyTimeout, PayLogInvalidAuthkey, PayLogNotFound from modules.pay_log.error import PayLogAuthkeyTimeout, PayLogInvalidAuthkey, PayLogNotFound
from modules.pay_log.models import PayLog as PayLogModel, BaseInfo from modules.pay_log.models import PayLog as PayLogModel, BaseInfo
from utils.const import PROJECT_ROOT from utils.const import PROJECT_ROOT
from utils.uid import mask_number
try: try:
import ujson as jsonlib import ujson as jsonlib
@ -240,7 +241,7 @@ class PayLog:
if price_data[i]["count"] > 0 if price_data[i]["count"] > 0
] ]
return { return {
"uid": player_id, "uid": mask_number(player_id),
"datas": datas, "datas": datas,
"bar_data": month_datas, "bar_data": month_datas,
"pie_data": pie_datas, "pie_data": pie_datas,

View File

@ -20,6 +20,7 @@ from core.services.template.models import RenderGroupResult, RenderResult
from core.services.template.services import TemplateService from core.services.template.services import TemplateService
from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper
from utils.log import logger from utils.log import logger
from utils.uid import mask_number
try: try:
import ujson as jsonlib import ujson as jsonlib
@ -220,7 +221,7 @@ class AbyssPlugin(Plugin):
render_data["time"] = time render_data["time"] = time
render_data["stars"] = total_stars render_data["stars"] = total_stars
render_data["uid"] = uid render_data["uid"] = mask_number(uid)
render_data["floor_colors"] = { render_data["floor_colors"] = {
1: "#374952", 1: "#374952",
2: "#374952", 2: "#374952",

View File

@ -20,6 +20,7 @@ from metadata.genshin import AVATAR_DATA
from modules.wiki.base import Model from modules.wiki.base import Model
from plugins.tools.genshin import CharacterDetails, GenshinHelper from plugins.tools.genshin import CharacterDetails, GenshinHelper
from utils.log import logger from utils.log import logger
from utils.uid import mask_number
if TYPE_CHECKING: if TYPE_CHECKING:
from telegram import Update from telegram import Update
@ -183,7 +184,7 @@ class AvatarListPlugin(Plugin):
name_card, avatar, nickname, rarity = await self.get_final_data(client.player_id, user) name_card, avatar, nickname, rarity = await self.get_final_data(client.player_id, user)
render_data = { render_data = {
"uid": client.player_id, # 玩家uid "uid": mask_number(client.player_id), # 玩家uid
"nickname": nickname, # 玩家昵称 "nickname": nickname, # 玩家昵称
"avatar": avatar, # 玩家头像 "avatar": avatar, # 玩家头像
"rarity": rarity, # 玩家头像对应的角色星级 "rarity": rarity, # 玩家头像对应的角色星级

View File

@ -28,6 +28,7 @@ from core.services.template.services import TemplateService
from metadata.genshin import AVATAR_DATA, HONEY_DATA from metadata.genshin import AVATAR_DATA, HONEY_DATA
from plugins.tools.genshin import CharacterDetails, PlayerNotFoundError, CookiesNotFoundError, GenshinHelper from plugins.tools.genshin import CharacterDetails, PlayerNotFoundError, CookiesNotFoundError, GenshinHelper
from utils.log import logger from utils.log import logger
from utils.uid import mask_number
try: try:
import ujson as jsonlib import ujson as jsonlib
@ -249,7 +250,7 @@ class DailyMaterial(Plugin):
client, user_data = await self._get_data_from_user(user) client, user_data = await self._get_data_from_user(user)
await message.reply_chat_action(ChatAction.TYPING) 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 # 默认养成计算器同步为开启 calculator_sync: bool = True # 默认养成计算器同步为开启
for type_ in ["avatar", "weapon"]: for type_ in ["avatar", "weapon"]:
@ -480,9 +481,9 @@ class DailyMaterial(Plugin):
results = await asyncio.gather(*task_list, return_exceptions=True) # 等待所有任务执行完成 results = await asyncio.gather(*task_list, return_exceptions=True) # 等待所有任务执行完成
for result in results: for result in results:
if isinstance(result, TimeoutException): if isinstance(result, TimeoutException):
notice_text = f"{result.__class__.__name__} 图标素材下载过程中请求超时.\n有关详细信息,请查看日志" notice_text = "图标素材下载过程中请求超时\n有关详细信息,请查看日志"
elif isinstance(result, Exception): elif isinstance(result, Exception):
notice_text = f"{result.__class__.__name__} 图标素材下载过程中发生异常.\n有关详细信息,请查看日志" notice_text = "图标素材下载过程中发生异常\n有关详细信息,请查看日志"
break break
try: try:
await message.edit_text(notice_text) await message.edit_text(notice_text)
@ -520,7 +521,7 @@ class AreaData(BaseModel):
class RenderData(BaseModel): class RenderData(BaseModel):
title: str # 页面标题,主要用于显示星期几 title: str # 页面标题,主要用于显示星期几
time: str # 页面时间 time: str # 页面时间
uid: Optional[int] = None # 用户UID uid: Optional[str] = None # 用户UID
character: List[AreaData] = [] # 角色数据 character: List[AreaData] = [] # 角色数据
weapon: List[AreaData] = [] # 武器数据 weapon: List[AreaData] = [] # 武器数据

View File

@ -11,6 +11,7 @@ from core.services.template.models import RenderResult
from core.services.template.services import TemplateService from core.services.template.services import TemplateService
from plugins.tools.genshin import GenshinHelper from plugins.tools.genshin import GenshinHelper
from utils.log import logger from utils.log import logger
from utils.uid import mask_number
if TYPE_CHECKING: if TYPE_CHECKING:
from simnet import GenshinClient from simnet import GenshinClient
@ -62,7 +63,7 @@ class DailyNotePlugin(Plugin):
transformer_recovery_time = daily_info.transformer_recovery_time.strftime("%m-%d %H:%M") transformer_recovery_time = daily_info.transformer_recovery_time.strftime("%m-%d %H:%M")
render_data = { render_data = {
"uid": client.player_id, "uid": mask_number(client.player_id),
"day": day, "day": day,
"resin_recovery_time": resin_recovery_time, "resin_recovery_time": resin_recovery_time,
"current_resin": daily_info.current_resin, "current_resin": daily_info.current_resin,

View File

@ -13,6 +13,7 @@ from core.services.template.models import RenderResult
from core.services.template.services import TemplateService from core.services.template.services import TemplateService
from plugins.tools.genshin import GenshinHelper from plugins.tools.genshin import GenshinHelper
from utils.log import logger from utils.log import logger
from utils.uid import mask_number
if TYPE_CHECKING: if TYPE_CHECKING:
from telegram import Update from telegram import Update
@ -55,7 +56,7 @@ class LedgerPlugin(Plugin):
return f"{round(amount / 10000, 2)}w" if amount >= 10000 else amount return f"{round(amount / 10000, 2)}w" if amount >= 10000 else amount
ledger_data = { ledger_data = {
"uid": client.player_id, "uid": mask_number(client.player_id),
"day": diary_info.month, "day": diary_info.month,
"current_primogems": format_amount(diary_info.month_data.current_primogems), "current_primogems": format_amount(diary_info.month_data.current_primogems),
"gacha": int(diary_info.month_data.current_primogems / 160), "gacha": int(diary_info.month_data.current_primogems / 160),

View File

@ -37,6 +37,7 @@ from utils.enkanetwork import RedisCache
from utils.helpers import download_resource from utils.helpers import download_resource
from utils.log import logger from utils.log import logger
from utils.patch.aiohttp import AioHttpTimeoutException from utils.patch.aiohttp import AioHttpTimeoutException
from utils.uid import mask_number
if TYPE_CHECKING: if TYPE_CHECKING:
from enkanetwork import CharacterInfo, EquipmentsStats from enkanetwork import CharacterInfo, EquipmentsStats
@ -486,7 +487,7 @@ class RenderTemplate:
artifact_total_score_label = r[0] artifact_total_score_label = r[0]
data = { data = {
"uid": self.uid, "uid": mask_number(self.uid),
"character": self.character, "character": self.character,
"stats": await self.de_stats(), "stats": await self.de_stats(),
"weapon": self.find_weapon(), "weapon": self.find_weapon(),

View File

@ -122,7 +122,7 @@ class Sign(Plugin):
not filters.ChatType.PRIVATE.filter(message), not filters.ChatType.PRIVATE.filter(message),
) )
reply_message = await message.reply_text( 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): if filters.ChatType.GROUPS.filter(reply_message):
self.add_delete_message_job(reply_message) self.add_delete_message_job(reply_message)

View File

@ -11,6 +11,7 @@ from core.services.template.models import RenderResult
from core.services.template.services import TemplateService from core.services.template.services import TemplateService
from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper
from utils.log import logger from utils.log import logger
from utils.uid import mask_number
if TYPE_CHECKING: if TYPE_CHECKING:
from telegram import Update from telegram import Update
@ -77,7 +78,7 @@ class PlayerStatsPlugins(Plugin):
user_info = user_info.copy(deep=True) user_info = user_info.copy(deep=True)
data = { data = {
"uid": uid, "uid": mask_number(uid),
"info": user_info.info, "info": user_info.info,
"stats": user_info.stats, "stats": user_info.stats,
"explorations": user_info.explorations, "explorations": user_info.explorations,

9
utils/uid.py Normal file
View File

@ -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"