|
| 1 | +# Defining Help Pages in Botkit |
| 2 | + |
| 3 | +This guide will walk you through the process of defining help pages for your Botkit |
| 4 | +extensions. Help pages provide users with information about your bot's commands, |
| 5 | +features, and usage examples. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +Before you begin, ensure you have: |
| 10 | + |
| 11 | +1. A basic understanding of YAML syntax |
| 12 | +2. Familiarity with the Botkit extension system |
| 13 | +3. An existing Botkit extension that you want to document |
| 14 | + |
| 15 | +## Understanding the Help System |
| 16 | + |
| 17 | +The Botkit help system organizes documentation into categories and pages. Each category |
| 18 | +contains multiple pages, and each page documents a specific command or feature. |
| 19 | + |
| 20 | +### Key Components |
| 21 | + |
| 22 | +The help system consists of several key components: |
| 23 | + |
| 24 | +1. **Categories**: Groups of related help pages (e.g., "Moderation", "Fun", "Utility") |
| 25 | +2. **Pages**: Individual documentation pages for specific commands or features |
| 26 | +3. **Translations**: Multi-language support for help content |
| 27 | + |
| 28 | +## Help Page Structure |
| 29 | + |
| 30 | +Help pages are defined using YAML files. Each YAML file represents a category and |
| 31 | +contains definitions for all pages within that category. |
| 32 | + |
| 33 | +### Class Structure |
| 34 | + |
| 35 | +The help system uses the following classes to represent help content: |
| 36 | + |
| 37 | +- `HelpTranslation`: The root class containing all categories |
| 38 | +- `HelpCategoryTranslation`: Represents a category of help pages |
| 39 | +- `HelpPageTranslation`: Represents an individual help page |
| 40 | + |
| 41 | +## Creating Help Pages |
| 42 | + |
| 43 | +### Step 1: Create a YAML File |
| 44 | + |
| 45 | +Create a YAML file for your help category in the `src/extensions/help/pages/` directory. |
| 46 | +For example, if you're documenting moderation commands, you might create |
| 47 | +`moderation.yml`: |
| 48 | + |
| 49 | +```bash |
| 50 | +touch src/extensions/help/pages/moderation.yml |
| 51 | +``` |
| 52 | + |
| 53 | +### Step 2: Define the Category |
| 54 | + |
| 55 | +Open the YAML file and define the category structure: |
| 56 | + |
| 57 | +```yaml |
| 58 | +name: |
| 59 | + en-US: Moderation |
| 60 | + es-ES: Moderación |
| 61 | +description: |
| 62 | + en-US: Commands for server moderation |
| 63 | + es-ES: Comandos para moderación del servidor |
| 64 | +order: 1 # Lower numbers appear first in the category list |
| 65 | +pages: |
| 66 | + # Pages will be defined here |
| 67 | +``` |
| 68 | + |
| 69 | +The `name` and `description` fields support multiple languages, and the `order` field |
| 70 | +determines the position of this category in the list. |
| 71 | + |
| 72 | +### Step 3: Define Pages |
| 73 | + |
| 74 | +Within the `pages` section, define each help page: |
| 75 | + |
| 76 | +```yaml |
| 77 | +pages: |
| 78 | + ban: |
| 79 | + title: |
| 80 | + en-US: Ban Command |
| 81 | + es-ES: Comando de Prohibición |
| 82 | + description: |
| 83 | + en-US: Bans a user from the server |
| 84 | + es-ES: Prohíbe a un usuario del servidor |
| 85 | + category: |
| 86 | + en-US: Moderation |
| 87 | + es-ES: Moderación |
| 88 | + quick_tips: |
| 89 | + - en-US: You can specify a reason for the ban |
| 90 | + es-ES: Puedes especificar una razón para la prohibición |
| 91 | + - en-US: Banned users can be unbanned later |
| 92 | + es-ES: Los usuarios prohibidos pueden ser readmitidos más tarde |
| 93 | + examples: |
| 94 | + - en-US: "/ban @user Spamming" |
| 95 | + es-ES: "/ban @usuario Spam" |
| 96 | + - en-US: "/ban @user" |
| 97 | + es-ES: "/ban @usuario" |
| 98 | + related_commands: |
| 99 | + - ban |
| 100 | +``` |
| 101 | +
|
| 102 | +Each page includes: |
| 103 | +
|
| 104 | +- `title`: The name of the command or feature |
| 105 | +- `description`: A brief description of what it does |
| 106 | +- `category`: The category this page belongs to (should match the category name) |
| 107 | +- `quick_tips` (optional): A list of helpful tips for using the command |
| 108 | +- `examples` (optional): Example usages of the command |
| 109 | +- `related_commands` (optional): List of commands that will be linked to this page using |
| 110 | + discord slash command mentions |
| 111 | + |
| 112 | +<!-- prettier-ignore --> |
| 113 | +> [!NOTE] |
| 114 | +> All text fields support multiple languages using language codes as keys. |
| 115 | + |
| 116 | +### Step 4: Make Your YAML File Available |
| 117 | + |
| 118 | +The help system automatically loads all `.yml` files from the |
| 119 | +`src/extensions/help/pages` directory. Make sure your file is properly formatted and |
| 120 | +placed in this directory. |
| 121 | + |
| 122 | +<!-- prettier-ignore --> |
| 123 | +> [!NOTE] |
| 124 | +> All help files should be placed in the `src/extensions/help/pages` directory, not inside individual extension directories. |
| 125 | + |
| 126 | +## Example: Complete Help Category |
| 127 | + |
| 128 | +Here's a complete example of a help category for moderation commands: |
| 129 | + |
| 130 | +```yaml |
| 131 | +name: |
| 132 | + en-US: Moderation |
| 133 | + es-ES: Moderación |
| 134 | +description: |
| 135 | + en-US: Commands for server moderation |
| 136 | + es-ES: Comandos para moderación del servidor |
| 137 | +order: 1 |
| 138 | +pages: |
| 139 | + ban: |
| 140 | + title: |
| 141 | + en-US: Ban Command |
| 142 | + es-ES: Comando de Prohibición |
| 143 | + description: |
| 144 | + en-US: Bans a user from the server |
| 145 | + es-ES: Prohíbe a un usuario del servidor |
| 146 | + category: |
| 147 | + en-US: Moderation |
| 148 | + es-ES: Moderación |
| 149 | + quick_tips: |
| 150 | + - en-US: You can specify a reason for the ban |
| 151 | + es-ES: Puedes especificar una razón para la prohibición |
| 152 | + - en-US: Banned users can be unbanned later |
| 153 | + es-ES: Los usuarios prohibidos pueden ser readmitidos más tarde |
| 154 | + examples: |
| 155 | + - en-US: "/ban @user Spamming" |
| 156 | + es-ES: "/ban @usuario Spam" |
| 157 | + - en-US: "/ban @user" |
| 158 | + es-ES: "/ban @usuario" |
| 159 | + related_commands: |
| 160 | + - kick |
| 161 | + - unban |
| 162 | +
|
| 163 | + kick: |
| 164 | + title: |
| 165 | + en-US: Kick Command |
| 166 | + es-ES: Comando de Expulsión |
| 167 | + description: |
| 168 | + en-US: Kicks a user from the server |
| 169 | + es-ES: Expulsa a un usuario del servidor |
| 170 | + category: |
| 171 | + en-US: Moderation |
| 172 | + es-ES: Moderación |
| 173 | + quick_tips: |
| 174 | + - en-US: Kicked users can rejoin with a new invite |
| 175 | + es-ES: Los usuarios expulsados pueden volver a unirse con una nueva invitación |
| 176 | + examples: |
| 177 | + - en-US: "/kick @user Disruptive behavior" |
| 178 | + es-ES: "/kick @usuario Comportamiento disruptivo" |
| 179 | + related_commands: |
| 180 | + - ban |
| 181 | +``` |
| 182 | + |
| 183 | +## How the Help System Works |
| 184 | + |
| 185 | +When a user requests help using the `/help` command, the help system: |
| 186 | + |
| 187 | +1. Loads all help categories and pages from YAML files |
| 188 | +2. Organizes them by category |
| 189 | +3. Displays a paginated view with categories in a dropdown menu |
| 190 | +4. Shows pages within the selected category |
| 191 | + |
| 192 | +The system automatically handles pagination, localization, and UI elements like "Tips & |
| 193 | +Tricks" and "Usage Examples" sections. |
| 194 | + |
| 195 | +## Advanced: Understanding How Help Pages Are Loaded |
| 196 | + |
| 197 | +The help system automatically loads all help pages from the `src/extensions/help/pages` |
| 198 | +directory when the bot starts. This is handled by the following code in |
| 199 | +`src/extensions/help/pages/__init__.py`: |
| 200 | + |
| 201 | +```python |
| 202 | +# iterate over .y[a]ml files in the same directory as this file |
| 203 | +categories: list[HelpCategoryTranslation] = [] |
| 204 | +
|
| 205 | +for file in chain(Path(__file__).parent.glob("*.yaml"), Path(__file__).parent.glob("*.yml")): |
| 206 | + with open(file, encoding="utf-8") as f: |
| 207 | + data = yaml.safe_load(f) |
| 208 | + categories.append(HelpCategoryTranslation(**data)) |
| 209 | +
|
| 210 | +categories.sort(key=lambda item: item.order) |
| 211 | +
|
| 212 | +help_translation = HelpTranslation(categories=categories) |
| 213 | +``` |
| 214 | + |
| 215 | +This code: |
| 216 | + |
| 217 | +1. Finds all `.yml` and `.yaml` files in the `src/extensions/help/pages` directory |
| 218 | +2. Loads each file as a YAML document |
| 219 | +3. Creates a `HelpCategoryTranslation` object for each file |
| 220 | +4. Sorts the categories by their `order` value |
| 221 | +5. Creates a `HelpTranslation` object containing all categories |
| 222 | + |
| 223 | +<!-- prettier-ignore --> |
| 224 | +> [!IMPORTANT] |
| 225 | +> Remember that all help pages must be placed in the `src/extensions/help/pages` directory, not within individual extension directories. |
| 226 | + |
| 227 | +## Conclusion |
| 228 | + |
| 229 | +By following this guide, you've learned how to create help pages for your Botkit |
| 230 | +extensions. Well-documented commands improve user experience and make your bot more |
| 231 | +accessible to new users. |
| 232 | + |
| 233 | +<!-- prettier-ignore --> |
| 234 | +> [!TIP] |
| 235 | +> Keep your help pages concise, clear, and up-to-date with your bot's functionality. |
| 236 | + |
| 237 | +<!-- prettier-ignore --> |
| 238 | +> [!IMPORTANT] |
| 239 | +> Always provide examples for complex commands to help users understand how to use them correctly. |
0 commit comments