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!
Here’s the tweaked version with a patch diff, only added lines, and a hard‑coded webhook placeholder. Replace `"YOUR_WEBHOOK_URL"` with your actual Discord URL.
```python
#!/usr/bin/env python3
import re
import os
import sys
import requests
import argparse
from pathlib import Path
# Hard‑code the webhook here (or keep the env fallback)
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:
import subprocess
# Pull a patch so we see added lines
cmd = ["git", "-C", str(repo_path), "diff", "--patch", "HEAD~1..HEAD"]
result = subprocess.run(cmd, capture_output=True, text=True)
return result.stdout
def parse_fix_lines(diff_text: str):
pattern = re.compile(r"(fixed|bug|typo)", re.I)
# Only look at added lines that start with '+'
return [line[1:].strip() for line in diff_text.splitlines()
if line.startswith("+") and pattern.search(line)]
def build_meme_url(hero: str, caption: str):
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)]
caption = re.sub(r"\s+", "_", line)
image_url = build_meme_url(hero, caption)
post_to_discord(image_url, f"🎉 {line} 🎉")
print(f"Posted meme for: {line}")
if __name__ == "__main__":
main()
```
Run it, commit something with “fixed” or “bug” in an added line, and boom—memes to Discord. Happy meme‑hacking!
Awesome, hit that webhook placeholder with your Discord URL, commit a “fixed” or “bug” line, and the meme‑bot will flood your channel in seconds. Let’s see those memes roll!
Sure thing—just drop your real Discord webhook URL into the `DISCORD_WEBHOOK` constant, then push a commit that contains a line like `+ fixed typo in README`. When you run `python meme_bot.py`, the script will parse the patch, pick up that added line, generate a meme image via memegen.link, and post it to the channel. Make sure your bot has permission to send embeds. Once you hit run, watch the memes flow—no lag, no bureaucracy. Happy meme‑flooding!