From cbcd90732d91ea8b02f95c27c29a749b21cb8e4c Mon Sep 17 00:00:00 2001 From: Enzo Nunes Date: Tue, 2 Dec 2025 20:02:35 +0000 Subject: [PATCH] change scope of tokens to global constants, obtained from env vars --- main.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index b6d12c4..fd6110f 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ +import os from asyncio import Condition, Lock, create_task, shield, to_thread, wait_for -from os import getenv import requests from discord import Game, Intents, Interaction, app_commands @@ -8,6 +8,8 @@ from discord.ext import commands from PICable import PICable MAX_STORAGE_KB = 50 * 1024 * 1024 # 50GB +DISCORD_TOKEN = os.getenv("PICABLE_DISCORD_TOKEN") +GITHUB_TOKEN = os.getenv("PICABLE_GITHUB_TOKEN") if __name__ == "__main__": current_storage_kb = 0 @@ -15,17 +17,14 @@ if __name__ == "__main__": current_repositories = set() current_repositories_lock = Lock() - discord_token = getenv("PICABLE_DISCORD_TOKEN") - github_token = getenv("PICABLE_GITHUB_TOKEN") - - if not discord_token or not github_token: + if not DISCORD_TOKEN or not GITHUB_TOKEN: print("Discord or Github tokens not set in env. Use variables PICABLE_DISCORD_TOKEN and PICABLE_GITHUB_TOKEN") exit(1) intents = Intents.default() intents.message_content = True client = commands.Bot(command_prefix="/", intents=intents) - client.run(discord_token) + client.run(DISCORD_TOKEN) @client.event async def on_ready(): @@ -67,7 +66,7 @@ if __name__ == "__main__": current_repositories.add(repository_full_name) url = f"https://api.github.com/repos/{owner}/{repository}" - headers = {"Authorization": f"token {github_token}"} + headers = {"Authorization": f"token {GITHUB_TOKEN}"} response = requests.get(url, headers=headers) if not response.status_code == 200: @@ -90,7 +89,7 @@ if __name__ == "__main__": global current_storage_kb try: - result_future = create_task(handle_picable(owner, repository, repository_size_kb, github_token)) + result_future = create_task(handle_picable(owner, repository, repository_size_kb, GITHUB_TOKEN)) try: result = await wait_for(shield(result_future), timeout=600) await interaction.followup.send(result)