Mask sensitive information in player id

This commit is contained in:
xtaodada 2023-08-26 21:21:26 +08:00
parent 136617e7a3
commit d9af458883
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
12 changed files with 34 additions and 16 deletions

View File

@ -35,6 +35,7 @@ from modules.gacha_log.models import (
SRGFModel, SRGFModel,
) )
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
@ -527,7 +528,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,
@ -579,7 +580,7 @@ class GachaLog:
) )
pool_data = [i for i in pool_data if i["count"] > 0] pool_data = [i for i in pool_data if i["count"] > 0]
return { return {
"uid": player_id, "uid": mask_number(player_id),
"typeName": pool_name, "typeName": pool_name,
"pool": pool_data[:6] if group else pool_data, "pool": pool_data[:6] if group else pool_data,
"hasMore": len(pool_data) > 6, "hasMore": len(pool_data) > 6,
@ -620,7 +621,7 @@ class GachaLog:
for up_pool in pools for up_pool in pools
] ]
return { return {
"uid": player_id, "uid": mask_number(player_id),
"typeName": "五星列表", "typeName": "五星列表",
"pool": pool_data, "pool": pool_data,
"hasMore": False, "hasMore": False,

View File

@ -16,6 +16,7 @@ from core.services.template.services import TemplateService
from gram_core.services.template.models import RenderResult, RenderGroupResult from gram_core.services.template.models import RenderResult, RenderGroupResult
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 StarRailClient from simnet import StarRailClient
@ -100,7 +101,7 @@ class PlayerActivityPlugins(Plugin):
for avatar in record.lineup: for avatar in record.lineup:
avatar_icons[avatar.id] = self.assets.avatar.square(avatar.id).as_uri() avatar_icons[avatar.id] = self.assets.avatar.square(avatar.id).as_uri()
return { return {
"uid": uid, "uid": mask_number(uid),
"records": data.records, "records": data.records,
"avatar_icons": avatar_icons, "avatar_icons": avatar_icons,
} }
@ -156,7 +157,7 @@ class PlayerActivityPlugins(Plugin):
for avatar in record.avatars: for avatar in record.avatars:
avatar_icons[avatar.id] = self.assets.avatar.square(avatar.id).as_uri() avatar_icons[avatar.id] = self.assets.avatar.square(avatar.id).as_uri()
return { return {
"uid": uid, "uid": mask_number(uid),
"records": data.records, "records": data.records,
"avatar_icons": avatar_icons, "avatar_icons": avatar_icons,
} }
@ -230,7 +231,7 @@ class PlayerActivityPlugins(Plugin):
def render(record: StarRailTreasureDungeonRecord) -> Coroutine[Any, Any, RenderResult]: def render(record: StarRailTreasureDungeonRecord) -> Coroutine[Any, Any, RenderResult]:
render_data = { render_data = {
"uid": uid, "uid": mask_number(uid),
"record": record, "record": record,
"avatar_icons": avatar_icons, "avatar_icons": avatar_icons,
} }

View File

@ -13,6 +13,7 @@ from core.services.template.services import TemplateService
from core.services.wiki.services import WikiService from core.services.wiki.services import WikiService
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 StarRailClient from simnet import StarRailClient
@ -123,7 +124,7 @@ class AvatarListPlugin(Plugin):
avatar_datas = await self.get_final_data(characters) avatar_datas = await self.get_final_data(characters)
render_data = { render_data = {
"uid": client.player_id, # 玩家uid "uid": mask_number(client.player_id), # 玩家uid
"nickname": nickname, # 玩家昵称 "nickname": nickname, # 玩家昵称
"avatar_datas": avatar_datas, # 角色数据 "avatar_datas": avatar_datas, # 角色数据
"has_more": has_more, # 是否显示了全部角色 "has_more": has_more, # 是否显示了全部角色

View File

@ -18,6 +18,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 GenshinHelper, CookiesNotFoundError from plugins.tools.genshin import GenshinHelper, CookiesNotFoundError
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
@ -243,7 +244,7 @@ class ChallengePlugin(Plugin):
render_data = { render_data = {
"time": time, "time": time,
"stars": total_stars, "stars": total_stars,
"uid": uid, "uid": mask_number(uid),
"max_floor": abyss_data.max_floor, "max_floor": abyss_data.max_floor,
"total_battles": abyss_data.total_battles, "total_battles": abyss_data.total_battles,
"floor_colors": { "floor_colors": {

View File

@ -12,6 +12,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 StarRailClient from simnet import StarRailClient
@ -52,7 +53,7 @@ class DailyNotePlugin(Plugin):
remained_time = (datetime.now().astimezone() + remained_time).strftime("%m-%d %H:%M") remained_time = (datetime.now().astimezone() + remained_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_stamina, "current_resin": daily_info.current_stamina,

View File

@ -15,6 +15,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 StarRailClient from simnet import StarRailClient
@ -57,7 +58,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": month, "day": month,
"current_hcoin": format_amount(diary_info.month_data.current_hcoin), "current_hcoin": format_amount(diary_info.month_data.current_hcoin),
"gacha": int(diary_info.month_data.current_hcoin / 160), "gacha": int(diary_info.month_data.current_hcoin / 160),

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, CookiesNotFoundError from plugins.tools.genshin import GenshinHelper, CookiesNotFoundError
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 StarRailClient from simnet import StarRailClient
@ -107,7 +108,7 @@ class PlayerMuseumPlugins(Plugin):
exhibitions.append(exhibition) exhibitions.append(exhibition)
all_exhibitions = [exhibitions[i : i + 7] for i in range(0, len(exhibitions), 7)] all_exhibitions = [exhibitions[i : i + 7] for i in range(0, len(exhibitions), 7)]
return { return {
"uid": uid, "uid": mask_number(uid),
"basic": basic, "basic": basic,
"all_exhibitions": all_exhibitions, "all_exhibitions": all_exhibitions,
"directors": detail.director, "directors": detail.director,

View File

@ -19,6 +19,7 @@ from modules.apihelper.client.components.player_cards import PlayerCards as Play
from modules.playercards.fight_prop import EquipmentsStats from modules.playercards.fight_prop import EquipmentsStats
from modules.playercards.helpers import ArtifactStatsTheory from modules.playercards.helpers import ArtifactStatsTheory
from utils.log import logger from utils.log import logger
from utils.uid import mask_number
if TYPE_CHECKING: if TYPE_CHECKING:
from telegram.ext import ContextTypes from telegram.ext import ContextTypes
@ -375,7 +376,7 @@ class PlayerCards(Plugin):
if idx > 3: if idx > 3:
break break
return { return {
"uid": data.uid, "uid": mask_number(data.uid),
"level": data.level or 0, "level": data.level or 0,
"signature": data.signature or "", "signature": data.signature or "",
"characters": characters_data, "characters": characters_data,
@ -478,7 +479,7 @@ class RenderTemplate:
for index in range(5): for index in range(5):
skills[index] = self.character.skillTreeList[index].level skills[index] = self.character.skillTreeList[index].level
data = { data = {
"uid": self.uid, "uid": mask_number(self.uid),
"character": self.character, "character": self.character,
"character_detail": self.wiki_service.character.get_by_id(self.character.avatarId), "character_detail": self.wiki_service.character.get_by_id(self.character.avatarId),
"weapon": weapon, "weapon": weapon,

View File

@ -14,6 +14,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, CookiesNotFoundError from plugins.tools.genshin import GenshinHelper, CookiesNotFoundError
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 StarRailClient from simnet import StarRailClient
@ -137,7 +138,7 @@ class PlayerRoguePlugins(Plugin):
new_avatars[idx] = RogueCharacter(**old_avatar) new_avatars[idx] = RogueCharacter(**old_avatar)
return { return {
"uid": uid, "uid": mask_number(uid),
"basic": data.basic_info, "basic": data.basic_info,
"name": f"{record.name} {luo_ma_bum[record.difficulty]}", "name": f"{record.name} {luo_ma_bum[record.difficulty]}",
"finish_cnt": record_raw.basic.finish_cnt, "finish_cnt": record_raw.basic.finish_cnt,

View File

@ -114,7 +114,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 GenshinHelper, CookiesNotFoundError from plugins.tools.genshin import GenshinHelper, CookiesNotFoundError
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 StarRailClient from simnet import StarRailClient
@ -100,7 +101,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,
"stats_labels": [ "stats_labels": [

8
utils/uid.py Normal file
View File

@ -0,0 +1,8 @@
from typing import Union
def mask_number(number: int) -> Union[int, str]:
if 100000000 <= number < 1000000000:
number_str = str(number)
return f"{number_str[0:2]}****{number_str[6:9]}"
return number