From 0fd121c22f68a55de6eb235b79f0a734b130c2b6 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 21 Feb 2024 22:08:33 +0200 Subject: [PATCH] import consistency --- files/classes/comment.py | 1 - files/helpers/lottery.py | 4 ++-- files/helpers/marsify.py | 4 ++-- files/helpers/regex.py | 7 +++---- files/helpers/roulette.py | 4 ++-- files/helpers/treasure.py | 12 ++++++------ files/routes/admin.py | 4 ++-- files/routes/routehelpers.py | 8 ++++---- 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index cf6245cc3..df05b713a 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -1,6 +1,5 @@ import time from math import floor -from random import randint from urllib.parse import parse_qs, urlencode, urlparse from flask import g diff --git a/files/helpers/lottery.py b/files/helpers/lottery.py index c3732b071..162eac028 100644 --- a/files/helpers/lottery.py +++ b/files/helpers/lottery.py @@ -1,5 +1,5 @@ import time -from random import choice +import random from flask import g from files.classes.lottery import Lottery @@ -44,7 +44,7 @@ def end_lottery_session(): active_lottery.is_active = False return True, "Lottery ended with no participants!" - winner = choice(raffle) + winner = random.choice(raffle) active_lottery.winner_id = winner winning_user = next(filter(lambda x: x.id == winner, participating_users)) winning_user.pay_account('coins', active_lottery.prize) diff --git a/files/helpers/marsify.py b/files/helpers/marsify.py index 5f596455d..6e1e03a12 100644 --- a/files/helpers/marsify.py +++ b/files/helpers/marsify.py @@ -1,4 +1,4 @@ -from random import choice +import random from .const_stateful import MARSEY_MAPPINGS @@ -15,6 +15,6 @@ def marsify(text, chud_phrase): x = x.lower() if x in chud_words: continue if len(x) >= 5 and x in MARSEY_MAPPINGS: - marsey = choice(MARSEY_MAPPINGS[x]) + marsey = random.choice(MARSEY_MAPPINGS[x]) new_text += f':{marsey}: ' return new_text diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 0812c11a5..e5b21ebc9 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -1,6 +1,5 @@ import random import re -from random import choice, choices, randint from .config.const import * @@ -159,11 +158,11 @@ def command_regex_matcher(match, upper=False): else: if match.group(2).startswith('roll'): max_num = int(match.group(3)) - result = randint(1, max_num) - color = tuple(choices(range(256), k=3)) + result = random.randint(1, max_num) + color = tuple(random.choices(range(256), k=3)) result = f'Your roll (1-{max_num}): {result}' else: - result = str(choice(commands[match.group(2).lower()])) + result = str(random.choice(commands[match.group(2).lower()])) return match.group(1) + result reason_regex_post = re.compile('(/post/[0-9]+)', flags=re.A) diff --git a/files/helpers/roulette.py b/files/helpers/roulette.py index 071cba7d9..e491bf75f 100644 --- a/files/helpers/roulette.py +++ b/files/helpers/roulette.py @@ -1,6 +1,6 @@ import json from enum import Enum -from random import randint +import random import time from flask import g @@ -166,7 +166,7 @@ def spin_roulette_wheel(): participants, bets, active_games = get_roulette_bets_and_betters() if len(participants) > 0: - number = randint(0, 37) # 37 is 00 + number = random.randint(0, 37) # 37 is 00 winners, payouts, rewards_by_game_id = determine_roulette_winners(number, bets) diff --git a/files/helpers/treasure.py b/files/helpers/treasure.py index 52e4c0e76..b58c0f391 100644 --- a/files/helpers/treasure.py +++ b/files/helpers/treasure.py @@ -1,5 +1,5 @@ from math import floor -from random import randint +import random from files.helpers.config.const import * from files.helpers.lottery import * @@ -15,23 +15,23 @@ def check_for_treasure(from_comment, in_text): if not FEATURES['GAMBLING']: return - seed = randint(1, 1000) + seed = random.randint(1, 1000) is_special = seed == 1000 is_standard = seed >= 990 amount = 0 if is_special: - amount = randint(special_min, special_max) + amount = random.randint(special_min, special_max) elif is_standard: - amount = randint(standard_min, standard_max) - if randint(1, 100) > 90: + amount = random.randint(standard_min, standard_max) + if random.randint(1, 100) > 90: amount = -amount if amount != 0: if amount > 0: active_lottery = get_active_lottery() - lottery_tickets_seed = randint(1, 100) + lottery_tickets_seed = random.randint(1, 100) lottery_tickets_instead = lottery_tickets_seed <= lotterizer_rate if active_lottery and lottery_tickets_instead: diff --git a/files/routes/admin.py b/files/routes/admin.py index 20cf20058..729e4f484 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -2,7 +2,7 @@ import time from math import floor import os import ffmpeg -from random import randint +import random from sqlalchemy.orm import load_only @@ -1894,7 +1894,7 @@ def delete_media_post(v): @admin_level_required(PERMS['USER_RESET_PASSWORD']) def admin_reset_password(user_id, v): user = get_account(user_id) - new_password = secrets.token_urlsafe(randint(27, 33)) + new_password = secrets.token_urlsafe(random.randint(27, 33)) user.passhash = hash_password(new_password) g.db.add(user) diff --git a/files/routes/routehelpers.py b/files/routes/routehelpers.py index ae3b7153f..0c7ed0c50 100644 --- a/files/routes/routehelpers.py +++ b/files/routes/routehelpers.py @@ -1,7 +1,7 @@ import time import uuid +import random -from random import randint from sqlalchemy.orm import aliased, deferred from sqlalchemy.sql import case, literal from sqlalchemy.sql.expression import or_ @@ -143,12 +143,12 @@ def execute_shadowban_viewers_and_voters(v, target): ti = max(int((time.time() - target.created_utc)/60), 3) max_upvotes = min(ti, 13) - rand = randint(0, max_upvotes) + rand = random.randint(0, max_upvotes) if target.upvotes >= rand: return - amount = randint(0, 3) + amount = random.randint(0, 3) target.upvotes += amount if isinstance(target, Post): - target.views += amount*randint(3, 5) + target.views += amount*random.randint(3, 5) g.db.add(target)