Spaces:
Running
Running
File size: 3,471 Bytes
33f6cd4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# Discord Flashcard Bot API
A Discord bot that provides REST API endpoints for managing flashcards stored in Discord channels.
## Features
- **Flashcard Management**: Organize flashcards in Discord channels within a "flashcard" category
- **REST API**: Access flashcards through HTTP endpoints
- **Challenge Tracking**: Track completed challenges in a dedicated channel
## Setup Instructions
### Discord Setup
1. **Create a Discord Bot**:
- Go to [Discord Developer Portal](https://discord.com/developers/applications)
- Create a new application and bot
- Copy the bot token
- Enable the following bot permissions:
- Read Messages/View Channels
- Send Messages
- Read Message History
- Manage Messages
2. **Server Setup**:
- Create a category named "flashcard" (or similar)
- Create channels within this category for different subjects (e.g., "math", "physics")
- Create a channel named "challengehistory" for tracking completed challenges
- Add flashcards as messages (questions) with replies as answers
### Environment Variables
Set the following environment variable:
- `DISCORD_BOT_TOKEN`: Your Discord bot token
### Deployment on Hugging Face Spaces
1. Create a new Space on Hugging Face
2. Choose "Docker" as the SDK
3. Upload all the files from this project
4. Set the `DISCORD_BOT_TOKEN` as a secret in your Space settings
5. Your API will be available at `https://[your-space-name].hf.space`
## API Endpoints
### GET `/flashcard-lists`
Returns a list of all flashcard folders with their IDs, names, and total flashcard counts.
**Response:**
```json
[
{
"folder_id": "123456789",
"folder_name": "math",
"total_flashcards": 15
}
]
```
### GET `/flashcard-folder/{folder_id}`
Returns all flashcards from a specific folder.
**Response:**
```json
[
{
"question_id": "987654321",
"question": {
"text": "What is 2+2?",
"image_url": null
},
"answers": [
{
"text": "4",
"image_url": null
}
]
}
]
```
### GET `/challenge-history`
Returns the list of completed challenges in order (most recent first).
**Response:**
```json
{
"challenge_history": ["3", "0", "1"],
"total_challenges": 3
}
```
### POST `/done-challenge/{folder_id}`
Marks a challenge as completed and updates the challenge history.
**Response:**
```json
{
"message": "Challenge history updated successfully"
}
```
### GET `/health`
Health check endpoint to verify bot and API status.
**Response:**
```json
{
"status": "healthy",
"bot_status": "connected"
}
```
## Discord Structure
```
Server
βββ Category: "flashcard"
β βββ Channel: "math" (math flashcards)
β βββ Channel: "physics" (physics flashcards)
β βββ ... (other subject channels)
βββ Channel: "challengehistory" (completed challenges)
```
### Flashcard Format
- **Question**: A message without a reply (can contain text and/or images)
- **Answer**: A reply to the question message (can contain text and/or images)
### Challenge History Format
The challenge history channel contains a single message with completed challenge IDs:
```
3
0
1
```
This indicates challenge 3 was completed most recently, then 0, then 1.
## Local Development
1. Install dependencies: `pip install -r requirements.txt`
2. Set environment variable: `export DISCORD_BOT_TOKEN=your_token_here`
3. Run: `python main.py`
4. API will be available at `http://localhost:7860`
|