← projects

project

Moodle Chat Bot — C Programming Assistant in Moodle Chat

with Felipe Zanoni da Rosa

Moodle Chat Bot — C Programming Assistant in Moodle Chat

A browser extension that turns Moodle's chat into a C compiler and AI tutor.

What it is

A browser extension (Chrome/Firefox) that watches the Moodle chat and turns it into an academic C programming assistant. Right from the course chat, students can compile and run C code, interact with the running program (including feeding input via scanf), ask an AI to explain errors or fix bugs, and keep a history of past conversations and runs — all without leaving the course interface.

How it works

A content script injected into the Moodle page watches the chat for commands starting with !, sent by an authorized user. Each command is forwarded to a local Flask backend, which routes the message: if it's C code, it's compiled with GCC and run in a subprocess, using queues and threads to capture output in real time and detect when the program is waiting for user input. If it's a question, the message — together with whatever previous-run context the user chose to include — is sent to Google's Gemini AI, with automatic fallback across models when quota limits are hit. All message history, AI responses, and run logs are stored in a local DuckDB database.

Tech stack

  • JavaScript (browser extension, Manifest V3)
  • Python + Flask (local backend)
  • Google Gemini API
  • DuckDB for persistence
  • GCC for compiling and running C

Technical highlights

  • Interactive C runner with real-time scanf support through a "silence timer" that decides when to hand output back to the user
  • Automatic #include inference: when Moodle's chat strips symbols like #, the bot recognizes the functions used (printf, malloc, sqrt...) and injects the correct headers
  • Fine-grained AI context system — from "last run" to a specific conversation ID, with rules to include only the question, only the answer, or both
  • Cascading fallback across Gemini models to work around free-tier quota limits
  • Layered backend architecture (routing, execution, AI, header inference, database), keeping each responsibility isolated
ZZZZ