fix main file. adapt dockerfile.

This commit is contained in:
Enzo Nunes
2025-12-02 23:15:40 +00:00
parent 06d3098940
commit 1cac1d2e66
2 changed files with 104 additions and 94 deletions

View File

@@ -2,16 +2,20 @@ FROM python:3.14-slim
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends cloc; \
apt-get dist-clean
apt-get install -y --no-install-recommends cloc git; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN pip install --no-cache-dir discord asyncio requests
RUN pip install --no-cache-dir discord.py requests
COPY main.py .
COPY PICable.py .
RUN useradd -m appuser
RUN useradd -m appuser && \
mkdir -p /temp && \
chown appuser:appuser /temp
USER appuser
CMD ["python", "main.py"]

10
main.py
View File

@@ -11,7 +11,6 @@ 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
storage_condition = Condition()
current_repositories = set()
@@ -24,7 +23,7 @@ if __name__ == "__main__":
intents = Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="/", intents=intents)
client.run(DISCORD_TOKEN)
@client.event
async def on_ready():
@@ -36,11 +35,13 @@ if __name__ == "__main__":
except Exception as e:
print(f"Failed to sync commands: {e}")
@client.tree.command(name="ping", description="Check the bot's latency.")
async def ping(interaction: Interaction):
latency = client.latency * 1000
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):
global current_storage_kb
async with storage_condition:
@@ -50,6 +51,7 @@ if __name__ == "__main__":
print(f"Storage is {current_storage_kb / MAX_STORAGE_KB * 100:.2f}% full.")
return await to_thread(PICable, owner, repository, github_token)
@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")
async def picable(interaction: Interaction, owner: str, repository: str):
@@ -108,3 +110,7 @@ if __name__ == "__main__":
async with storage_condition:
current_storage_kb -= repository_size_kb
storage_condition.notify_all()
if __name__ == "__main__":
client.run(DISCORD_TOKEN)