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 committed Aug 26, 2023
1 parent 54b8ee6 commit c129f86
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 26 deletions.
7 changes: 2 additions & 5 deletions core/services/wiki/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ async def refresh_wiki(self) -> NoReturn:
用于把Redis的缓存全部加载进Python
:return:
"""
logger.info("正在重新获取Wiki")
logger.info("正在重新获取武器信息")
await self.refresh_weapon()
logger.info("正在重新获取角色信息")

await self.refresh_characters()
logger.info("刷新成功")


async def init(self) -> NoReturn:
"""
Expand Down
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
4 changes: 2 additions & 2 deletions plugins/genshin/daily/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,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
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
29 changes: 19 additions & 10 deletions plugins/tools/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional, Tuple, List, TYPE_CHECKING

from httpx import TimeoutException
from simnet import Game
from simnet import Game, Region
from simnet.errors import BadRequest as SimnetBadRequest, AlreadyClaimed, InvalidCookies, TimedOut as SimnetTimedOut
from simnet.utils.player import recognize_genshin_server
from sqlalchemy.orm.exc import StaleDataError
Expand Down Expand Up @@ -136,14 +136,23 @@ async def start_sign(
try:
if validate:
logger.info("UID[%s] 正在尝试通过验证码\nchallenge[%s]\nvalidate[%s]", client.player_id, challenge, validate)
request_daily_reward = await client.request_daily_reward(
"sign",
method="POST",
game=Game.GENSHIN,
lang="zh-cn",
challenge=challenge,
validate=validate,
)
if client.region == Region.OVERSEAS:
request_daily_reward = await client.request_daily_reward(
"sign",
method="POST",
challenge="9a7e3af0ef6ae8afcb37f091b4224fb0",
game=Game.GENSHIN,
lang="zh-cn",
)
else:
request_daily_reward = await client.request_daily_reward(
"sign",
method="POST",
game=Game.GENSHIN,
lang="zh-cn",
challenge=challenge,
validate=validate,
)
logger.debug("request_daily_reward 返回 %s", request_daily_reward)
if request_daily_reward and request_daily_reward.get("success", 0) == 1:
# 尝试通过 ajax 请求绕过签到
Expand Down Expand Up @@ -336,4 +345,4 @@ async def do_sign_job(self, context: "ContextTypes.DEFAULT_TYPE", job_type: Sign
try:
await self.sign_service.update(sign_db)
except StaleDataError:
logger.warning("用户 user_id[%s] 自动签到数据过期,跳过更新数据", user_id)
logger.warning("用户 user_id[%s] 自动签到数据过期,跳过更新数据", user_id)
10 changes: 10 additions & 0 deletions utils/uid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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
else:
return "Invalid input"

0 comments on commit c129f86

Please sign in to comment.