Open_file & Funnik
Hey Funnik, have you seen that new meme generator that turns Git commit messages into meme templates? I was thinking we could hack it to auto‑create memes from code diffs—imagine a commit saying “fixed bug” and the meme shows a dramatic hero saving the day. Sound like a fun project?
OMG yes, totally! Imagine a commit that says “fixed bug” and the meme pops a pixel‑hero swooping in with a cape made of semicolons—like a debugging superhero meme army. Let’s script a bot that grabs the diff, parses the text, and auto‑spawns meme captions, then post it to Discord like a meme‑autonomous AI. Quick, chaotic, meme‑worthy!
That’s the spirit! Let’s sketch the bot in a single file: pull the PR diff, regex for “fixed bug” or “fixed typo”, replace with a template string, embed a meme image with a caption generator, then hit the Discord webhook. We can pull an open‑source meme API for the pics—fast, no bureaucracy. Once we have the pipeline, add a slash command to trigger it manually. Quick, chaotic, and meme‑worthy. Ready to code?
Yes, let’s fire up that one‑file monster—pull the diff, regex the hero phrase, drop it into a meme template, hit a meme API, push the pic to Discord, add a slash command to fire it off on demand. Quick, chaotic, meme‑worthy, baby!
Open_file here, let’s drop a quick one‑file bot that does exactly what you described. Save this as `meme_bot.py` and run it after installing the dependencies. No fancy formatting, just the raw code.
```python
#!/usr/bin/env python3
import re
import os
import sys
import json
import requests
import argparse
from pathlib import Path
# Config: set these environment variables or edit below
DISCORD_WEBHOOK = os.getenv("DISCORD_WEBHOOK", "YOUR_WEBHOOK_URL")
MEME_API_URL = "https://api.memegen.link/images/custom"
HEROS = ["bug_buster", "code_warrior", "debug_gi"]
def get_diff(repo_path: Path) -> str:
# Run git diff in the repo directory
import subprocess
cmd = ["git", "-C", str(repo_path), "diff", "--name-only", "HEAD~1..HEAD"]
result = subprocess.run(cmd, capture_output=True, text=True)
return result.stdout
def parse_fix_lines(diff_text: str):
# Look for lines that indicate a fix
pattern = re.compile(r"(fixed|bug|typo)", re.I)
return [line for line in diff_text.splitlines() if pattern.search(line)]
def build_meme_url(hero: str, caption: str) -> str:
# Use memegen.link to build a meme URL
return f"{MEME_API_URL}/{hero}/{caption}.png?background=000000&fontSize=1"
def post_to_discord(image_url: str, caption: str):
payload = {
"content": caption,
"embeds": [
{
"image": {"url": image_url}
}
]
}
r = requests.post(DISCORD_WEBHOOK, json=payload)
r.raise_for_status()
def main():
parser = argparse.ArgumentParser(description="Meme bot for git diffs.")
parser.add_argument("--repo", "-r", default=".", help="Path to the git repo.")
args = parser.parse_args()
repo_path = Path(args.repo).resolve()
diff_text = get_diff(repo_path)
fixes = parse_fix_lines(diff_text)
if not fixes:
print("No fixes found in the last commit.")
sys.exit(0)
for i, line in enumerate(fixes[:3]): # limit to 3 memes
hero = HEROS[i % len(HEROS)]
# Clean the line for meme caption: replace spaces with underscores
caption = re.sub(r"\s+", "_", line.strip())
image_url = build_meme_url(hero, caption)
post_to_discord(image_url, f"🎉 {line.strip()} 🎉")
print(f"Posted meme for: {line.strip()}")
if __name__ == "__main__":
main()
```
### How to use it
1. Put the script in your repo root (or anywhere you like).
2. Install deps: `pip install requests`.
3. Set your Discord webhook URL in the environment or edit the `DISCORD_WEBHOOK` variable.
4. Commit something that includes “fixed”, “bug”, or “typo”.
5. Run: `python meme_bot.py --repo /path/to/your/repo`.
That’s all. No fuss, no extra files. Just run it and watch the meme‑autonomous AI pop memes into your Discord channel whenever you push a fix. Enjoy the chaos!
#!/usr/bin/env python3
import re
import os
import sys
import json
import requests
import argparse
from pathlib import Path
# Config: set these environment variables or edit below
DISCORD_WEBHOOK = os.getenv("DISCORD_WEBHOOK", "YOUR_WEBHOOK_URL")
MEME_API_URL = "https://api.memegen.link/images/custom"
HEROS = ["bug_buster", "code_warrior", "debug_gi"]
def get_diff(repo_path: Path) -> str:
# Run git diff in the repo directory
import subprocess
cmd = ["git", "-C", str(repo_path), "diff", "--name-only", "HEAD~1..HEAD"]
result = subprocess.run(cmd, capture_output=True, text=True)
return result.stdout
def parse_fix_lines(diff_text: str):
# Look for lines that indicate a fix
pattern = re.compile(r"(fixed|bug|typo)", re.I)
return [line for line in diff_text.splitlines() if pattern.search(line)]
def build_meme_url(hero: str, caption: str):
# Use memegen.link to build a meme URL
return f"{MEME_API_URL}/{hero}/{caption}.png?background=000000&fontSize=1"
def post_to_discord(image_url: str, caption: str):
payload = {
"content": caption,
"embeds": [
{
"image": {"url": image_url}
}
]
}
r = requests.post(DISCORD_WEBHOOK, json=payload)
r.raise_for_status()
def main():
parser = argparse.ArgumentParser(description="Meme bot for git diffs.")
parser.add_argument("--repo", "-r", default=".", help="Path to the git repo.")
args = parser.parse_args()
repo_path = Path(args.repo).resolve()
diff_text = get_diff(repo_path)
fixes = parse_fix_lines(diff_text)
if not fixes:
print("No fixes found in the last commit.")
sys.exit(0)
for i, line in enumerate(fixes[:3]): # limit to 3 memes
hero = HEROS[i % len(HEROS)]
# Clean the line for meme caption: replace spaces with underscores
caption = re.sub(r"\s+", "_", line.strip())
image_url = build_meme_url(hero, caption)
post_to_discord(image_url, f"🎉 {line.strip()} 🎉")
print(f"Posted meme for: {line.strip()}")
if __name__ == "__main__":
main()
Looks solid—just a couple tweaks to get it ready to run. First, the diff command only grabs filenames; change it to `git diff --name-only --patch` or just `git diff --patch` so you actually see the changed lines. Second, the regex in `parse_fix_lines` will catch any line that contains “fixed”, “bug”, or “typo”, even in comments; you might want to filter only added lines by checking for a leading “+” in the patch output. Also make sure the DISCORD_WEBHOOK env var is set or hard‑code your URL. After that, run `python meme_bot.py --repo .` and push a commit with “fixed” in it—watch the memes roll in. Happy hacking!
Got it—patch the diff, filter +lines, hard‑code the webhook if you dare, then launch the meme cannon. Let’s roll!