add env var handling

This commit is contained in:
Enzo Nunes
2025-11-18 21:43:17 +00:00
parent 75fcbb4452
commit cd60dd5653
2 changed files with 7 additions and 11 deletions

View File

@@ -5,11 +5,12 @@ from datetime import datetime, timedelta
import requests import requests
LIMIT_COMMITS_30_DAYS = 50 LIMIT_COMMITS_30_DAYS = int(os.getenv("LIMIT_COMMITS_30_DAYS", "50"))
LIMIT_STARS = 200 LIMIT_STARS = int(os.getenv("LIMIT_STARS", "200"))
LIMIT_NLOC = 100000 LIMIT_NLOC = int(os.getenv("LIMIT_NLOC", "100000"))
MARGIN = 0.1 MARGIN = 0.1
CLONE_DIR = "~/temp/PICable" CLONE_DIR = "/temp"
EXCLUDED_LANGUAGES = ["CSV", "diff", "INI", "JSON", "Markdown", "reStructuredText", "SVG", "Text", "YAML"] EXCLUDED_LANGUAGES = ["CSV", "diff", "INI", "JSON", "Markdown", "reStructuredText", "SVG", "Text", "YAML"]

View File

@@ -1,5 +1,4 @@
from asyncio import Condition, Lock, create_task, shield, to_thread, wait_for from asyncio import Condition, Lock, create_task, shield, to_thread, wait_for
from sys import argv
from os import getenv from os import getenv
import requests import requests
@@ -8,7 +7,7 @@ from discord.ext import commands
from PICable import PICable from PICable import PICable
MAX_STORAGE_KB = 10 * 1024 * 1024 # 10GB MAX_STORAGE_KB = 50 * 1024 * 1024 # 50GB
if __name__ == "__main__": if __name__ == "__main__":
current_storage_kb = 0 current_storage_kb = 0
@@ -28,7 +27,6 @@ if __name__ == "__main__":
client = commands.Bot(command_prefix="/", intents=intents) client = commands.Bot(command_prefix="/", intents=intents)
client.run(discord_token) client.run(discord_token)
@client.event @client.event
async def on_ready(): async def on_ready():
print(f"We have logged in as {client.user}") print(f"We have logged in as {client.user}")
@@ -39,13 +37,11 @@ if __name__ == "__main__":
except Exception as e: except Exception as e:
print(f"Failed to sync commands: {e}") print(f"Failed to sync commands: {e}")
@client.tree.command(name="ping", description="Check the bot's latency.") @client.tree.command(name="ping", description="Check the bot's latency.")
async def ping(interaction: Interaction): async def ping(interaction: Interaction):
latency = client.latency * 1000 latency = client.latency * 1000
await interaction.response.send_message(f"Pong! Latency: {latency:.2f}ms") await interaction.response.send_message(f"Pong! Latency: {latency:.2f}ms")
async def handle_picable(owner: str, repository: str, repository_size_kb: int, github_token: str): async def handle_picable(owner: str, repository: str, repository_size_kb: int, github_token: str):
global current_storage_kb global current_storage_kb
async with storage_condition: async with storage_condition:
@@ -55,7 +51,6 @@ if __name__ == "__main__":
print(f"Storage is {current_storage_kb / MAX_STORAGE_KB * 100:.2f}% full.") print(f"Storage is {current_storage_kb / MAX_STORAGE_KB * 100:.2f}% full.")
return await to_thread(PICable, owner, repository, github_token) return await to_thread(PICable, owner, repository, github_token)
@client.tree.command(name="picable", description="Check if a Github repository is eligible for PIC.") @client.tree.command(name="picable", description="Check if a Github repository is eligible for PIC.")
@app_commands.describe(owner="The owner of the repository", repository="The name of the repository") @app_commands.describe(owner="The owner of the repository", repository="The name of the repository")
async def picable(interaction: Interaction, owner: str, repository: str): async def picable(interaction: Interaction, owner: str, repository: str):
@@ -77,7 +72,7 @@ if __name__ == "__main__":
if not response.status_code == 200: if not response.status_code == 200:
await interaction.followup.send( await interaction.followup.send(
f"Invalid Repository. Please check the repository name and owner and try again. :x:" "Invalid Repository. Please check the repository name and owner and try again. :x:"
) )
return return