Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
582d45f
Initial support for an exposed webhook that runs a piece of code. Thi…
mrjcleaver Jan 25, 2025
654a377
Added configurable webhook, tested against Zapier
mrjcleaver Jan 25, 2025
e4e4d3d
Added channels_to_summarize and altered channel_id to reflect that it…
mrjcleaver Jan 25, 2025
93f9128
gitignore to omit private files
mrjcleaver Jan 25, 2025
7d0a2de
Update webhook-server-example.json
mrjcleaver Jan 25, 2025
3a6e522
Removed webhook-test
mrjcleaver Jan 26, 2025
3bbe5f1
Implement asynchronous LRU cache and integrate with OpenAI summarizat…
mrjcleaver Feb 15, 2025
d99f4df
Remove unused asynchronous LRU cache and related OpenAI summarization…
mrjcleaver Feb 16, 2025
af8c936
Merge branch 'main' of https://github.com/mrjcleaver/summary_bot_open…
mrjcleaver Feb 16, 2025
8f7313e
Added webhook-driven summaries. I'm working on documentation next.
mrjcleaver Feb 17, 2025
0a93c0b
Update README and add TODO notes for code merger and refactoring
mrjcleaver Feb 17, 2025
ebe679f
Moved file
mrjcleaver Feb 17, 2025
87e66d7
Update CONTRIBUTORS.md
mrjcleaver Feb 17, 2025
dcfd6f2
Update CONTRIBUTORS.md
mrjcleaver Feb 17, 2025
6747944
Add APScheduler for webhook scheduling and update dependencies
mrjcleaver Feb 24, 2025
97d608f
Merge branch 'main' of https://github.com/mrjcleaver/summary_bot_open…
mrjcleaver Feb 24, 2025
7849f98
renamed to scheduler
mrjcleaver Feb 24, 2025
a59c81a
Implement TaskWorker for job scheduling
mrjcleaver Feb 24, 2025
a266ac0
Add Google Drive integration and enhance summarization features
mrjcleaver Mar 2, 2025
9d00ff6
Add task list management, tagged channels functionality, and improve …
mrjcleaver Mar 4, 2025
cf547bc
Add Fly.io configuration, Docker setup, and logging enhancements
mrjcleaver Mar 24, 2025
5f91bec
Add debugging support, environment checks, and update Fly.io configur…
mrjcleaver Mar 25, 2025
b7ae007
Refactor debug.py to use logging for debug messages and improve clarity
mrjcleaver Mar 25, 2025
8c59c60
Enhance debugging setup with 6tunnel for IPv6 support, update Dockerf…
mrjcleaver Mar 26, 2025
cb175fa
Switched from fly.io to local Docker instance, got remote IDE breakpo…
mrjcleaver Mar 29, 2025
36d5a08
Refactor debug.py for cleaner debugpy handling, enhance logging level…
mrjcleaver Mar 29, 2025
6ca3991
Implemented changes suggested by Github's AI. Refactored Arun's summa…
mrjcleaver Mar 30, 2025
1e57a49
Update bin/debugpy-connections-test.py
mrjcleaver Mar 30, 2025
e7cbf31
Update bin/fly-set-secrets.ps1
mrjcleaver Mar 30, 2025
0797239
Refactor imports to use src. and invoke as src.main instead of main/ …
mrjcleaver Mar 31, 2025
4db7dd1
Enhance Dockerfile and README; refactor deploy script for better logg…
mrjcleaver Apr 9, 2025
312092e
Merge branch 'main' of https://github.com/mrjcleaver/summary_bot_open…
mrjcleaver Apr 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fly.toml
.git/
__pycache__/
.envrc
.venv/
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,22 @@ cython_debug/
.history
.DS_Store

.vscode
# You can create a .vscode/launch.json file to make debugging easier
.vscode

# Or for PyCharm:
.idea/misc.xml
.idea/modules.xml
.idea/.gitignore
.idea/inspectionProfiles/profiles_settings.xml
.idea/summary_bot_opensource.iml


# Your server config goes in static
src/static/*
src/static/summary-bot-firebase-credentials.json


# Ignore debug log files
summaries/*
summaries.old
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Summary Bot Open Source

This script is the main entry point for the Summary Bot, a Discord bot that provides various summarization functionalities using OpenAI's summarization capabilities. The bot also integrates with a Flask-based webhook server to handle external requests.

Architecture:
1. **Discord Bot**: The bot listens to events and commands on Discord servers.
2. **Flask Webhook Server**: A Flask server runs in a separate thread to handle webhook requests.
3. **Task Scheduler**: A task scheduler runs in a separate thread to manage background jobs.

Execution Pathways:
1. **Initialization**:
- Load environment variables using `dotenv`.
- Initialize the Discord bot with default intents.
- Create an instance of `OpenAISummarizer`.
2. **Webhook Server**:
- Define a function `run_webhook` to start the Flask server.
- Run the Flask server in a separate thread to avoid blocking the bot.
3. **Task Scheduler**:
- Define a function `queue_jobs` to manage background tasks.
- Run the task scheduler in a separate thread.
4. **Discord Bot Events**:
- Define `on_ready` event to log bot readiness and accessible channels.
- Define `on_error` event to handle rate limits and other errors.
5. **Discord Bot Commands**:
- Register various slash commands for summarization, settings, and bot information.
- Each command is linked to a corresponding function that implements the desired functionality.
6. **Main Execution**:
- Start the Flask server for webhook handling.
- Run the Discord bot using the token from environment variables.

Diagrams:
1. **Architecture Diagram**:
```ascii
+-------------------+ +-------------------+
| | | |
| Discord Bot | | Flask Webhook |
| | | |
+---------+---------+ +---------+---------+
| |
| |
+---------------------------+
|
|
+---------+---------+
| |
| Task Scheduler |
| |
+-------------------+
```
2. **Execution Flow**:
```ascii
+-------------------+
| |
| Main Script |
| |
+---------+---------+
|
v
+---------+---------+
| |
| Load Environment |
| |
+---------+---------+
|
v
+---------+---------+
| |
| Initialize Bot |
| |
+---------+---------+
|
v
+---------+---------+ +-------------------+
| | | |
| Start Webhook | | Start Task |
| Server Thread | | Scheduler Thread |
| | | |
+---------+---------+ +---------+---------+
| |
v v
+---------+---------+ +---------+---------+
| | | |
| Run Bot Event | | Queue Jobs |
| Loop | | |
| | | |
+-------------------+ +-------------------+
```
This documentation provides an overview of the Summary Bot's architecture, execution pathways, and the services it integrates with. The diagrams illustrate the high-level structure and flow of the application.

4 changes: 4 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Arjun Sahlot - @ArjunSahlot
* Martin Cleaver - @mrjcleaver (Added Tomasz' functions from discord-summarizer-bot, added external webhook implementation)
* The code from discord-summarizer-bot provided `process_channel()`. This was renamed `summarize_contents_of_channel_between_dates()` and the outputs placed in the context of the webhooks.
* Tomasz Zmarz - @nybble16 - code at https://github.com/nybble16/discord-summarizer-bot
200 changes: 200 additions & 0 deletions DEBUGGING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
## Development
Windows
1. IDE Debugpy connection - connect directly in launch.json to docker-host:5678
2. Logs -

## Production
Windows
1. Proxy ```fly proxy 5678:5678```
2. Console ```fly console```
sh diagnostics/
3. Console Logs
```fly logs``` or
+ [Fly Logs Dashboard](https://fly-metrics.net/d/fly-logs/fly-logs?from=now-1h&to=now&var-app=summary-bot-aparine&var-instance=All&orgId=1017766&var-query=)
4. Deploy ```fly deploy --build-arg INSTALL_DEV=true```
5. Start https://fly.io/apps/summary-bot-aparine/machines

Note: https://github.com/microsoft/debugpy/issues/1252
debugpy does not support IPV6. Fly.io only supports IPV6.

The solution shown (and installed here) uses:
1. fly proxy tunnelling between your dev machine and the remote container running your app
2. bridges 6tunnel running on the remote container tunnelling between the inbound IPV6 traffic to the Python IPV4-only version of debugpy.





READ THIS FIRST
* Fly Env Var Precedence
(!) Your fly.toml overrides the command line
✅ fly.toml [env] (strongest)
✅ Secrets (fly secrets)
⚠️ --env on fly deploy (weakest — only works if nothing above exists)




Easiest is to access the remote logs:

``fly logs``


Optional: Debug mode environment toggle
To control debugpy at runtime, you can still pair this with a runtime ENV variable:

``fly secrets set DEBUGPY_ENABLE=true ENV=development``


Then attach your IDE’s remote debugger to localhost:5678.


``fly proxy 5678:5678``


Now let’s get **VS Code** to connect to the remote Python process running `debugpy`.

---

### ✅ 1. Make sure your app is listening for the debugger

Somewhere early in your `main.py` (guarded by `DEBUGPY_ENABLE`), you should have:

```python
import debugpy
debugpy.listen(("0.0.0.0", 5678))
print("🪛 Waiting for debugger attach on port 5678...")
# Optional — pause here until debugger is attached
# debugpy.wait_for_client()
```

Then deploy with:
```bash
fly deploy --env DEBUGPY_ENABLE=true
```

---

### ✅ 2. Create a VS Code debug config

Open your `.vscode/launch.json` (or create one), and add this:

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Fly Remote",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"justMyCode": false
}
]
}
```

#### 🔍 Explanation
* `host: "localhost"` — thanks to `fly proxy`, this connects to your remote app.
* `port: 5678` — where `debugpy` is listening.
* `remoteRoot: "/app"` — this is the working dir in your Docker image (`WORKDIR /app`).
* `localRoot: "${workspaceFolder}"` — your local VS Code project path.

---

### ✅ 3. Attach the debugger

1. In VS Code, open the Run & Debug panel.
2. Choose **"Attach to Fly Remote"**.
3. Click the green ► start button.
4. 🎯 Your app should pause if it’s running `debugpy.wait_for_client()` — or you can add breakpoints.

--

Check the remote machine
`` printenv | egrep 'ENV|FLY_MACHINE_ID|DEBUG'``
FLY_MACHINE_ID=2874577c072558
DEBUGPY_ENABLE=false
ENV=production

I did this:
(.venv) PS summary_bot_opensource>``fly deploy --build-arg INSTALL_DEV=true --env DEBUGPY_ENABLE=true --env ENV=development``

But see this:
```
root@2874577c072558:/app# printenv | egrep 'ENV|FLY_MACHINE_ID|DEBUG'
FLY_MACHINE_ID=2874577c072558
DEBUGPY_ENABLE=false
ENV=production
```

This is a quirk in Fly.io: **`--env` flags in `fly deploy` don’t override existing env vars that are already set as secrets or in your `fly.toml`**.

That means:
* You probably have `DEBUGPY_ENABLE=false` and `ENV=production` **defined in `fly.toml` or as Fly secrets**.
* These override anything passed via `--env` on deploy.

---

### ✅ Fix Options

#### 🔧 **Option 1: Update your `fly.toml` for dev builds**
Edit `fly.toml` to temporarily override those vars:

```toml
[env]
ENV = "development"
DEBUGPY_ENABLE = "true"
```

Then just:
```bash
fly deploy --build-arg INSTALL_DEV=true
```

After you're done debugging, revert the `fly.toml` changes.

---

#### 🔧 **Option 2: Use `fly secrets unset` and let `--env` work**

If you've previously set those as secrets (check with `fly secrets list`), remove them:

```bash
fly secrets unset DEBUGPY_ENABLE ENV
```

Then redeploy with:
```bash
fly deploy --build-arg INSTALL_DEV=true --env DEBUGPY_ENABLE=true --env ENV=development
```

Now `--env` will work as expected since nothing is overriding it.

---

### 🔍 How to confirm
After redeploying, SSH into the instance:

```bash
fly ssh console
printenv | egrep 'DEBUG|ENV'
```

You should see:

```bash
DEBUGPY_ENABLE=true
ENV=development
```

---
Loading