Skip to content

Commit

Permalink
fix(ctftime): randomize the user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
hfz1337 committed Apr 22, 2024
1 parent ede2c5b commit 5218129
Show file tree
Hide file tree
Showing 3 changed files with 1,017 additions and 2 deletions.
1 change: 0 additions & 1 deletion eruditus/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ DEVELOPER_USER_ID="305076601253789697"
# CTFtime settings.
DATE_FORMAT="%a, %d %B %Y, %H:%M UTC"
CTFTIME_URL="https://ctftime.org"
USER_AGENT="Eruditus"

# CTF Write-ups Search Index (used by the `/search` command).
# This one is currently down, feel free to deploy your own: github.com:hfz1337/CTF-WSI
Expand Down
18 changes: 17 additions & 1 deletion eruditus/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import random
from pathlib import Path
from typing import Callable, Optional, TypeVar

Expand All @@ -9,6 +10,21 @@
dotenv.load_dotenv()


class RandomUserAgent:
"""A class that represents a random User-Agent."""

def __init__(self):
self.user_agents = [
line.strip()
for line in open(
f"{Path(__file__).parent}/user-agents.txt", encoding="utf-8"
).readlines()
]

def __repr__(self):
return random.choice(self.user_agents)


def load_revision() -> str:
"""Get the current revision.
Expand Down Expand Up @@ -56,7 +72,7 @@ def load_nullable_env_var(
GUILD_ID = int(os.getenv("GUILD_ID"))
MAX_CONTENT_SIZE = int(os.getenv("MAX_CONTENT_SIZE"))
MONGODB_URI = os.getenv("MONGODB_URI")
USER_AGENT = os.getenv("USER_AGENT")
USER_AGENT = RandomUserAgent()
WRITEUP_INDEX_API = os.getenv("WRITEUP_INDEX_API")
TEAM_NAME = os.getenv("TEAM_NAME")
TEAM_EMAIL = os.getenv("TEAM_EMAIL")
Expand Down
Loading

0 comments on commit 5218129

Please sign in to comment.