Skip to content

Commit

Permalink
Implement automatic command documentation (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuswillner authored and Dougley committed Jun 18, 2018
1 parent 9b0a771 commit c38fece
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 113 deletions.
13 changes: 8 additions & 5 deletions .circleci/config.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
docker:
- image: docker:latest
steps:
- run:
- run:
name: Git
command: apk add --update git
- checkout
Expand Down Expand Up @@ -80,8 +80,8 @@ jobs:
. venv/bin/activate
mkdocs build
docs-deploy:
docker:
- image: python:3.5
machine:
image: circleci/classic:latest
steps:
- checkout
- restore_cache:
Expand All @@ -96,7 +96,10 @@ jobs:
paths:
- "venv"
- run:
name: Compile
name: Build JS
command: npm run build
- run:
name: Build docs
command: |
. venv/bin/activate
mkdocs build
Expand Down Expand Up @@ -136,4 +139,4 @@ workflows:
branches:
ignore: /.*/
tags:
only: /v.+/
only: /v.+/
3 changes: 2 additions & 1 deletion .eslintignore
@@ -1 +1,2 @@
node_modules/**
node_modules/**
docs/js/dist/*
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -65,3 +65,7 @@ typings/

# Docs build
site

# Command info dump
commandInfo.json
docs/js/dist/commands.js*
124 changes: 31 additions & 93 deletions docs/commands.md
Expand Up @@ -8,101 +8,53 @@ This is the command reference for WildBeast. You can find more elaborative infor
!!! tip
Send the message **++help <command\>** (Prefix may vary) to the bot to get further information on any given command.

Some commands on this page will have an empty **Usage** field. This means that the command takes no arguments and is accepted as such.
## Gotchas

Parameters marked with **<placeholders\>** are supposed to be replaced by other values. Do not incude the actual braces in the command. Similarly, **@user** placeholders refer to mentions. Parameters surrounded by **[brackets]** signify parameters that may be omitted.
1. Some commands on this page will have an empty **Usage** field. This means that the command takes no arguments and is accepted as such.

2. Parameters marked with **<placeholders\>** are supposed to be replaced by other values. Do not incude the actual braces in the command. Similarly, **@user** placeholders refer to mentions. Parameters surrounded by **[brackets]** signify parameters that may be omitted.

3. Commands in the **NSFW** category have been labeled as not safe for work and can only be used in a channel that has been marked as NSFW in the channel settings.

Additional command information:

[Addendums](#addendums)<br>
[Tag subcommands](#tag-subcommands)<br>
[Settings subcommands](#settings-subcommands)<br>
[Available meme types](#available-meme-types)

## Commands

### Admin

| Name | Description | Usage | Level/Required permission |
| ---- | ----------- | ----- | ------------------------- |
| addrole | Give a role to user or users. | addrole @user @user2 **<role name\>** | Manage Roles |
| takerole | Take a role from a user or users. | takerole @user @user2 **<role name\>** | Manage Roles |
| colorrole | Change the color of a role. | colorrole **<role name\>** **<hex value\>**[^1] | Manage Roles |
| kick | Kick a user. | kick @user **[reason]** | Kick Members |
| ban | Ban a user. | ban @user **[reason]** | Ban Members |
| softban | Softban[^2] a user. | softban @user **[reason]** | Ban Members |
| hackban | Ban a user by ID. | hackban **<userid\>** **[reason]** | Ban Members |
| purge | Delete multiple messages at once. | purge **[author]** @user **<number\>** | Manage Messages |
| leaveserver | Make the bot leave the current server. | | 10 |

### Fun

| Name | Description | Usage | Level/Required permission |
| ---- | ----------- | ----- | ------------------------- |
| advice | Get some clever advice. | | 0 |
| catfact | Get a cat fact. | | 0 |
| dice | Roll the dice. | | 0 |
| dogfact | Get a dog fact. | | 0 |
| fact | Get a random fact. | | 0 |
| fancyinsult | Insult someone in a fancy manner. | | 0 |
| gif | Search Giphy for a gif. | gif **<query\>** | 0 |
| leetspeak | Encode a message into l337sp3@K. | leetspeak **<message to encode\>** | 0 |
| magic8ball | Ask the magic 8-ball for advice. | magic8ball **<question\>** | 0 |
| meme | Create a meme. | meme **<meme type\>** "upper text" "lower text"[^3] | 0 |
| randomcat | Get a random cat picture. | | 0 |
| randomdog | Get a random dog picture. | | 0 |
| randomcat | Get a random meme from Imgur. | | 0 |
| stroke | Stroke someone's ego. | stroke **<name\>** | 0 |
| twitch | Check if a streamer is live on Twitch. | twitch **<username\>** | 0 |
| urbandictionary | Get the definition of a word from the Urban Dictionary. | urbandictionary **<word\>** | 0 |
| xkcd | Get a random XKCD comic, or supply a number to get that particular comic. | xkcd **[comic number]** | 0 |
| yesno | Get a GIF saying yes or no. | | 0 |
| yomomma | Get a random yo momma joke. | | 0 |

### Music

| Name | Description | Usage | Level/Required permission |
| ---- | ----------- | ----- | ------------------------- |
| join-voice | Make the bot join a voice channel. Optionally supply a track to play on join. | join-voice **[track link]** | 1 |
| leave-voice | Make the boit leave the current voice channel. | | 1 |
| nowplaying | Show the currently playing track. | | 1 |
| pause | Pause the playback of the current track. | | 1 |
| queue | Show the playback queue. | | 1 |
| request | Add a track to the playback queue. | request **<track link\>**[^4] | 1 |
| resume | Resume the playback of the current track. | | 1 |
| shuffle | Shuffle the playback queue. | | 1 |
| skip | Skip the current song. | | 1 |
| volume | Change the playback volume. | volume **<0-100\>** | 1 |

### NSFW

!!! warning "NSFW content"
These commands are labeled as not safe for work and can only be used within a channel that is marked as NSFW via the channel settings.

| Name | Description | Usage | Level/Required permission |
| ---- | ----------- | ----- | ------------------------- |
| booru | Query various booru sites for images. | booru **<gelbooru/rule34/e621\>** **<search query\>** | 0 |
| e621 | Query e621 for an image. | e621 **<search query\>** | 0 |
| rule34 | Query rule34 for an image. | rule34 **<search query\>** | 0 |

### Tags
<div id="commands-table"></div>

## Addendums

1. For the **colorrole** command, a hexadecimal value can be submitted in either **#FFFFFF** or **FFFFFF** format.
2. The **softban** command bans a user and then immediately unbans them, deleting their messages without barring future access to the server.
3. The **request** command supports playing from the following resources: YouTube, SoundCloud, Bandcamp, Twitch, Vimeo, Mixer and raw HTML audio.

## Tag subcommands

The tag command has the following subcommands. All subcommands inherit the permission level of the main command.

!!! tip
You can use JagTag formatting with the **tag create** command. See [the JagTag-JS documentation](https://thesharks.github.io/JagTag-JS/users/intro) for more information on how.

| Name | Description | Usage | Level/Required permission |
| ---- | ----------- | ----- | ------------------------- |
| tag | Base command for tags. Returns a tag if specified. | tag **<subcommand/name\>** | 0 (Applies to all subcommands) |
| Name | Description | Usage |
| ---- | ----------- | ----- |
| tag create | Create a tag. | tag create **<name\>** **<content\>** |
| tag delete | Delete a tag. | tag delete **<name\>** |
| tag edit | Edit an existing tag. | tag edit **<name\>** **<newcontent\>** |
| tag owner | Return the owner of a tag. | tag owner **<name\>** |
| tag random | Retrieve a random tag from the database. | tag random |
| tag raw | Return the raw data of a tag. | tag raw **<name\>** |

### Settings
## Settings subcommands

| Name | Description | Usage | Level/Required permission |
| ---- | ----------- | ----- | ------------------------- |
| settings | Base command for settings. Returns current settings if no setting is specified. | settings **<setting\>** **<parameter\>** | 5 |
| setlevel | Change someone's permission level. | setlevel @user/@role @user2/@role2 **<0-10\>** | 7 |

The following settings can be customised. All settings are server-specific.
The following settings can be edited with this command. All settings are server-specific and all subcommands inherit the permission level of the main command.

**Note:** Languages are still WIP. Only the "en" language is supported at the moment.
!!! note
Languages are still WIP. Only the "en" language is supported at the moment.

| Name | Description | Usage |
| ---- | ----------- | ----- |
Expand All @@ -112,16 +64,7 @@ The following settings can be customised. All settings are server-specific.
| welcomeMessage | Change the welcome message that is sent when a new member joins. | settings welcomeMessage **<message\>** |
| reset | Reset a setting to its default value. | settings reset **<setting\>** |

### Utility

| Name | Description | Usage | Level/Required permission |
| ---- | ----------- | ----- | ------------------------- |
| info | Return information about the bot. | | 0 |
| ping | Return the bot's pseudo-ping. | | 0 |
| say | Make the bot send a message of your choice. | say **<message\>** | 0 |
| userinfo | Return information about a user ID, mention or name. Omit parameters to return information about yourself. | userinfo **<userid/mention/username\>** | 0 |

### Available meme types
## Available meme types

The values in the **Name** column of the table below correspond to the relevant meme ID on https://api.imgflip.com/popular_meme_ids.

Expand Down Expand Up @@ -165,8 +108,3 @@ The values in the **Name** column of the table below correspond to the relevant
| philosoraptor | 61516 |
| 3rdworldsuccess | 101287 |
| ancientaliens | 101470 |

[^1]: A hexadecimal value can be submitted in either **#FFFFFF** or **FFFFFF** format.
[^2]: Softbanning includes banning a user and immediately unbanning them, removing their messages without barring their access in future.
[^3]: Including the quotes in the text values is important.
[^4]: Supported resources: YouTube, SoundCloud, Bandcamp, Twitch, Vimeo, Mixer and raw HTML audio.
1 change: 1 addition & 0 deletions docs/js/dist/.gitempty
@@ -0,0 +1 @@
Dist versions of JavaScript files in the 'src' directory will go here. It's generally a bad idea to modify the files in this directory.
127 changes: 127 additions & 0 deletions docs/js/src/commands.js
@@ -0,0 +1,127 @@
// Tool to dynamically generate command documentation

function generateCommandDocs (commandInfo) {
if (commandInfo) { // Only run if commandInfo is defined to prevent unexpected results
if (window.location.pathname === '/commands/') { // Only run if in the commands doc
const commandCategories = extractCategories(commandInfo)
const globalContainer = document.getElementById('commands-table')

commandCategories.forEach(cmdCat => {
// Create header
const h3 = document.createElement('h3')
h3.setAttribute('id', cmdCat.toLowerCase())
h3.innerHTML = cmdCat

// Create table
const commandsInCategory = extractCommandsFromCategory(commandInfo, cmdCat)

// Only proceed if there are commands in the category (Avoids "ghost tables")
if (commandsInCategory && commandsInCategory.length > 0) {
const table = generateHTMLTable(commandsInCategory)

globalContainer.appendChild(h3)
globalContainer.appendChild(table)
}
})
}
}
}

// Extract categories from all commands
function extractCategories (commandInfo) {
const categories = []

for (const command in commandInfo) {
const category = commandInfo[command].module || 'Uncategorised'
if (!categories.includes(category)) categories.push(category)
}

return categories
}

function extractCommandsFromCategory (commandInfo, categoryToExtract) {
const commandsInCategory = []

for (const cmd in commandInfo) {
if (!commandInfo[cmd].doNotDocument) { // Ignore commands marked as non-documented
commandInfo[cmd].name = cmd // Allows later tracking of command name
const categoryOfCommand = commandInfo[cmd].module || 'Uncategorised'
if (categoryOfCommand === categoryToExtract) commandsInCategory.push(commandInfo[cmd])
}
}

return commandsInCategory
}

// Generate a table for a category
function generateHTMLTable (commandsInCategory) {
const table = document.createElement('table')

const header = constructHeader()
const body = constructBody(commandsInCategory)

table.insertAdjacentElement('afterbegin', header)
table.insertAdjacentElement('beforeend', body)

return table
}

// Construct the table header
function constructHeader () {
const thead = document.createElement('thead')
const headerRow = document.createElement('tr')

const headers = [
'Name',
'Description',
'Usage',
'Level',
'Required permissions'
]

// Construct header row
headers.forEach(header => {
const th = document.createElement('th')
th.innerHTML = header
headerRow.insertAdjacentElement('beforeend', th)
})

thead.appendChild(headerRow)

// Append
return thead
}

// Construct the table body
function constructBody (commands) {
const tbody = document.createElement('tbody')

// Construct a row per command
commands.forEach(cmdObj => {
const tr = document.createElement('tr')

const usage = cmdObj.usage ? `${cmdObj.name} ${sanitiseUsage(cmdObj.usage)}` : ' '
const rowContent = `<td><b>${cmdObj.name}</b></td><td>${cmdObj.help}</td><td>${usage}</td><td>${cmdObj.level || '0'}</td><td>${cmdObj.permAddons || ' '}</td>`
tr.innerHTML = rowContent

// Append
tbody.insertAdjacentElement('beforeend', tr)
return tbody
})

return tbody
}

function sanitiseUsage (usageString) {
if (!usageString) return ' '

// Escape tags
usageString = usageString.replace('<', '&lt;').replace('>', '&gt;')

return usageString
}

// Run
generateCommandDocs()

// DO NOT TOUCH ANYTHING BELOW THIS - MANAGED BY CI
3 changes: 3 additions & 0 deletions mkdocs.yml
Expand Up @@ -39,6 +39,9 @@ extra:
- type: 'github'
link: 'https://github.com/TheSharks'

extra_javascript:
- js/dist/commands.js

extra_css:
- css/style.css

Expand Down

0 comments on commit c38fece

Please sign in to comment.