mirror of
https://github.com/PaiGramTeam/PamGram.git
synced 2024-11-21 21:58:04 +00:00
🎨 Use random
module instead of secrets
module
This commit is contained in:
parent
755c224ca0
commit
d3fb2ef386
@ -1,4 +1,4 @@
|
||||
import secrets
|
||||
import random
|
||||
from typing import Tuple, List
|
||||
|
||||
from modules.gacha.banner import GachaBanner
|
||||
@ -73,8 +73,7 @@ class BannerSystem:
|
||||
if weight < 0:
|
||||
raise GachaIllegalArgument("Weights must be non-negative!")
|
||||
total += weight
|
||||
secrets_random = secrets.SystemRandom()
|
||||
roll = int(secrets_random.random() * min(total, cutoff))
|
||||
roll = random.randint(0, min(total, cutoff)) # nosec
|
||||
sub_total = 0
|
||||
for index, value in enumerate(weights):
|
||||
sub_total += value
|
||||
@ -146,11 +145,8 @@ class BannerSystem:
|
||||
|
||||
@staticmethod
|
||||
def get_random(items) -> int:
|
||||
secrets_random = secrets.SystemRandom()
|
||||
roll = int(secrets_random.random() * len(items))
|
||||
return items[roll]
|
||||
return random.choice(items) # nosec
|
||||
|
||||
@staticmethod
|
||||
def random_range(_mix: int, _max: int) -> int:
|
||||
secrets_random = secrets.SystemRandom()
|
||||
return int(secrets_random.uniform(_mix, _max))
|
||||
return random.randint(_mix, _max) # nosec
|
||||
|
@ -1,4 +1,4 @@
|
||||
import secrets
|
||||
import random
|
||||
from typing import Optional
|
||||
|
||||
from genshin import Client
|
||||
@ -109,7 +109,7 @@ class UserStatsPlugins(Plugin, BasePlugin):
|
||||
("雷神瞳", "electroculi"),
|
||||
("草神瞳", "dendroculi"),
|
||||
],
|
||||
"style": secrets.choice(["mondstadt", "liyue"]),
|
||||
"style": random.choice(["mondstadt", "liyue"]), # nosec
|
||||
}
|
||||
|
||||
# html = await self.template_service.render_async(
|
||||
|
@ -1,6 +1,6 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import secrets
|
||||
import random
|
||||
import time
|
||||
|
||||
from aiohttp import ClientConnectorError
|
||||
@ -37,14 +37,14 @@ class SignJob(Plugin):
|
||||
self.sign_service = sign_service
|
||||
self.cookies_service = cookies_service
|
||||
self.user_service = user_service
|
||||
self.random = secrets.SystemRandom()
|
||||
|
||||
async def single_sign(self, user_id: int) -> str:
|
||||
@staticmethod
|
||||
async def single_sign(user_id: int) -> str:
|
||||
client = await get_genshin_client(user_id)
|
||||
if recognize_genshin_server(client.uid) in ("cn_gf01", "cn_qd01"):
|
||||
await asyncio.sleep(10 + self.random.random() * 300) # 延迟 [10, 300)
|
||||
await asyncio.sleep(random.randint(10, 300)) # nosec
|
||||
else:
|
||||
await asyncio.sleep(self.random.random() * 3) # 延迟 [0, 3)
|
||||
await asyncio.sleep(random.randint(0, 3)) # nosec
|
||||
rewards = await client.get_monthly_rewards(game=Game.GENSHIN, lang="zh-cn")
|
||||
daily_reward_info = await client.get_reward_info(game=Game.GENSHIN)
|
||||
if not daily_reward_info.signed_in:
|
||||
|
@ -1,6 +1,6 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import secrets
|
||||
import random
|
||||
|
||||
from aiohttp import ClientConnectorError
|
||||
from genshin import InvalidCookies, AlreadyClaimed, GenshinException
|
||||
@ -29,7 +29,6 @@ class SignAll(Plugin):
|
||||
self.sign_service = sign_service
|
||||
self.cookies_service = cookies_service
|
||||
self.user_service = user_service
|
||||
self.random = secrets.SystemRandom()
|
||||
|
||||
@handler(CommandHandler, command="sign_all", block=False)
|
||||
@bot_admins_rights_check
|
||||
@ -70,7 +69,8 @@ class SignAll(Plugin):
|
||||
try:
|
||||
if "今天旅行者已经签到过了~" not in text:
|
||||
await context.bot.send_message(sign_db.chat_id, text, parse_mode=ParseMode.HTML)
|
||||
await asyncio.sleep(10 + self.random.random() * 50) # 回复延迟 [10, 60) 避免触发洪水防御
|
||||
await asyncio.sleep(random.randint(10, 50)) # nosec
|
||||
# 回复延迟 [10, 60] 避免触发洪水防御
|
||||
except BadRequest as exc:
|
||||
logger.error(f"执行自动签到时发生错误 用户UID[{user_id}]")
|
||||
logger.exception(exc)
|
||||
|
Loading…
Reference in New Issue
Block a user