Command: !catfact¶
Zufälliger Cat-Fact via catfact.ninja API.
API: https://catfact.ninja/fact
Patterns: Fetch URL + JSON Parse + Send Message
Sub-Actions: 3
Action: [Cmd] !catfact¶
Sub-Action 1: Fetch URL¶
| Feld | Wert |
|---|---|
| URL | https://catfact.ninja/fact |
| Variable Name | cat |
| Parse result as JSON | ✅ aktiv |
Response:
Parse-Output:
- %cat.fact% = A cat's normal pulse is 140-240 beats per minute.
- %cat.length% = 51
Sub-Action 2: If/Else — API down¶
2. If/Else: %fetchUrlStatusCode% Greater Than 299
├── Send Message: "@%user% Cat-Fact-API nicht erreichbar."
└── Break
Sub-Action 3: Send Message¶
| Feld | Wert |
|---|---|
| Message | 🐱 Cat-Fact: %cat.fact% |
| Send using bot account | aktiv |
Action-Tree¶
[Cmd] !catfact
├── 1. Fetch URL: https://catfact.ninja/fact → cat (JSON)
├── 2. If/Else: %fetchUrlStatusCode% Greater Than 299
│ ├── Send Message: "@%user% Cat-Fact-API nicht erreichbar."
│ └── Break
└── 3. Send Message: "🐱 Cat-Fact: %cat.fact%"
Command-Einstellungen¶
| Feld | Wert |
|---|---|
| Name | !catfact |
| Group | AzaCraft API |
| Commands | !catfact!cat!katze |
| Sources | Twitch Message |
| Global Cooldown | 5 |
| User Cooldown | 30 |
Verwendungsbeispiele¶
| Chat | Resultat |
|---|---|
!catfact |
"🐱 Cat-Fact: A cat's normal pulse is 140-240 beats per minute." |
!cat |
gleich |
!katze |
gleich |
Variante: Mit Max-Length-Filter¶
catfact.ninja unterstützt ?max_length=150:
Damit nur Facts ≤ 150 Zeichen. Gut wenn format=4 der !weather Variante eh schon lange Outputs hat.
Variante: Mehrere Facts¶
https://catfact.ninja/facts?limit=3 liefert Array von 3 Facts:
{
"data": [
{"fact": "...", "length": 80},
{"fact": "...", "length": 60},
{"fact": "...", "length": 90}
]
}
Da Array — pragmatisch: nur den ersten nehmen: %cat.data[0].fact%. Oder bei einem einzelnen bleiben (default).
Andere ähnliche APIs¶
| API | URL | Was es liefert |
|---|---|---|
| Dog Facts | https://dogapi.dog/api/v2/facts |
Hunde-Facts (etwas anderes Schema) |
| Random Fact | https://uselessfacts.jsph.pl/api/v2/facts/random?language=de |
Zufällige nutzlose Facts |
| Chuck Norris | https://api.chucknorris.io/jokes/random |
Chuck-Norris-Witze |
| Quotable | https://api.quotable.io/random |
Berühmte Zitate |
Alle gleichen Pattern: GET → JSON Parse → Send Message.
Erweiterung: Multi-Animal !animalfact¶
[Cmd] !animalfact
├── 1. Get Random Number (1, 3)
├── 2. If/Else: %randomNumber% Equals 1
│ ├── Fetch URL: https://catfact.ninja/fact → animal (JSON)
│ ├── Send Message: "🐱 %animal.fact%"
│ └── Break
├── 3. If/Else: %randomNumber% Equals 2
│ ├── Fetch URL: https://dogapi.dog/api/v2/facts → animal (JSON)
│ ├── Send Message: "🐶 %animal.data.0.attributes.body%"
│ └── Break
└── 4. (Fox/Bird/...)
Zufällig Cat/Dog/etc.
Häufige Fallen¶
- API blockt nach zu vielen Requests — kostenlose APIs haben Rate-Limits. Bei Spam → 429-Status, dann mit Cooldown im Command bremsen
- JSON-Schema ändert sich — heute
{fact, length}, morgen vielleicht{text, len}. Bei Bedarf API-Doku checken - Network-Latency — wenn du in Asia hosted und API in USA, kann Fetch URL 1-2s dauern. Twitch-User merken's
Quellen¶
- catfact.ninja: https://catfact.ninja/
- Fetch URL Setup: setup.md