Preparation for new year of PIC

This commit is contained in:
2025-11-18 15:18:10 +00:00
parent 7c38a708b4
commit 75fcbb4452
5 changed files with 109 additions and 84 deletions

15
Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM python:3.14-slim
# Copy your code
WORKDIR /app
RUN pip install --no-cache-dir discord asyncio requests
COPY main.py .
COPY PICable.py .
# Drop privileges (optional but good practice)
RUN useradd -m appuser
USER appuser
# Start the scheduler script
CMD ["python", "main.py"]

View File

@@ -1,2 +1,3 @@
# PICable
Simple script to determine if a project is eligible as the final PIC of LEIC-T.

8
docker-compose.yml Normal file
View File

@@ -0,0 +1,8 @@
services:
picable:
build: .
container_name: picable
environment:
- PICABLE_DISCORD_TOKEN=yourdiscordtoken
- PICABLE_GITHUB_TOKEN=yourgithubtoken
restart: unless-stopped

46
main.py
View File

@@ -1,5 +1,6 @@
from asyncio import Condition, Lock, create_task, shield, to_thread, wait_for
from sys import argv
from os import getenv
import requests
from discord import Game, Intents, Interaction, app_commands
@@ -8,24 +9,28 @@ from discord.ext import commands
from PICable import PICable
MAX_STORAGE_KB = 10 * 1024 * 1024 # 10GB
current_storage_kb = 0
storage_condition = Condition()
current_repositories = set()
current_repositories_lock = Lock()
if len(argv) != 3:
print("Usage:\n\t" + argv[0] + " <discord_token> <github_token>")
if __name__ == "__main__":
current_storage_kb = 0
storage_condition = Condition()
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:
print("Discord or Github tokens not set in env. Use variables PICABLE_DISCORD_TOKEN and PICABLE_GITHUB_TOKEN")
exit(1)
discord_token = argv[1]
github_token = argv[2]
intents = Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="/", intents=intents)
intents = Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="/", intents=intents)
client.run(discord_token)
@client.event
async def on_ready():
@client.event
async def on_ready():
print(f"We have logged in as {client.user}")
await client.change_presence(activity=Game("with PIC ideas"))
try:
@@ -35,13 +40,13 @@ async def on_ready():
print(f"Failed to sync commands: {e}")
@client.tree.command(name="ping", description="Check the bot's latency.")
async def ping(interaction: Interaction):
@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):
async def handle_picable(owner: str, repository: str, repository_size_kb: int, github_token: str):
global current_storage_kb
async with storage_condition:
await storage_condition.wait_for(lambda: current_storage_kb + repository_size_kb <= MAX_STORAGE_KB)
@@ -51,9 +56,9 @@ async def handle_picable(owner: str, repository: str, repository_size_kb: int, g
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):
@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):
await interaction.response.defer(thinking=True)
repository_full_name = f"{owner}/{repository}"
@@ -109,6 +114,3 @@ async def picable(interaction: Interaction, owner: str, repository: str):
async with storage_condition:
current_storage_kb -= repository_size_kb
storage_condition.notify_all()
client.run(discord_token)

1
run.sh
View File

@@ -1 +0,0 @@
python3 main.py MTM0MzMzNzAzMzkyOTU4ODg5MA.Gx2pEq.uLdXFORUFlYurLUF6Lnsuh_EWFQRI8SAKFebDM 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