Skip to content

Commit a47cbc3

Browse files
committed
Add documentation for each command
1 parent a2df7eb commit a47cbc3

11 files changed

Lines changed: 280 additions & 51 deletions

File tree

commands/admin/ban.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ import (
88
"github.com/maxsupermanhd/FactoCord-3.0/support"
99
)
1010

11-
// BanPlayerUsage comment...
12-
var BanPlayerUsage = "Usage: $ban <player> <reason>"
11+
var BanPlayerDoc = support.CommandDoc{
12+
Name: "ban",
13+
Usage: "$ban <player> <reason>",
14+
Doc: `command bans the player on the server with a specified reason`,
15+
}
1316

1417
// BanPlayer bans a player on the server.
1518
func BanPlayer(s *discordgo.Session, args string) {
1619
if len(args) == 0 {
17-
support.SendFormat(s, BanPlayerUsage)
20+
support.SendFormat(s, "Usage: "+BanPlayerDoc.Usage)
1821
return
1922
}
2023
args2 := strings.SplitN(args+" ", " ", 2)
2124
player := strings.TrimSpace(args2[0])
2225
reason := strings.TrimSpace(args2[1])
2326

2427
if len(player) == 0 || len(reason) == 0 {
25-
support.SendFormat(s, BanPlayerUsage)
28+
support.SendFormat(s, "Usage: "+BanPlayerDoc.Usage)
2629
return
2730
}
2831

commands/admin/config.go

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,66 @@ import (
1212
"github.com/maxsupermanhd/FactoCord-3.0/support"
1313
)
1414

15-
// ModCommandUsage ...
16-
var ConfigCommandUsage = "Usage: $config save | load | get <path> | set <path> <value>"
15+
var ConfigCommandDoc = support.CommandDoc{
16+
Name: "config",
17+
Usage: "$config save | load | get <path> | set <path> <value>?",
18+
Doc: "command manages FactoCord's config",
19+
Subcommands: []support.CommandDoc{
20+
{Name: "save", Doc: "command saves FactoCord's config from memory to `config.json`"},
21+
{
22+
Name: "load",
23+
Doc: "command loads the config from `config.json`.\n" +
24+
"Any unsaved changes after the last `$config save` command will be lost.",
25+
},
26+
{
27+
Name: "get",
28+
Usage: "$config get <path>?",
29+
Doc: "command outputs the value of a config setting specified by <path>.\n" +
30+
"All path members are separated by a dot '.'\n" +
31+
"If the path is empty, it outputs the whole config.\n" +
32+
"Examples:\n" +
33+
"```\n" +
34+
"$config get\n" +
35+
"$config get admin_ids\n" +
36+
"$config get admin_ids.0\n" +
37+
"$config get command_roles\n" +
38+
"$config get command_roles.mod\n" +
39+
"$config get messages\n" +
40+
"```",
41+
},
42+
{
43+
Name: "set",
44+
Usage: "$config set <path>\n" +
45+
"$config set <path> <value>",
46+
Doc: "command sets the value of a config setting specified by <path>.\n" +
47+
"This command can set only simple types such as strings, numbers, and booleans.\n" +
48+
"If no value is specified, this command deletes the value if possible, otherwise it sets it to a zero-value (0, \"\", false).\n" +
49+
"To add a value to an array or an object specify it's index as '*' (e.g. `$config set admin_ids.* 1234`).\n" +
50+
"Changes made by this command are not automatically saved. Use `$config save` to do it.\n" +
51+
"Examples:" +
52+
"```\n" +
53+
"$config set prefix !\n" +
54+
"$config set game_name \"Factorio 1.0\"\n" +
55+
"$config set ingame_discord_user_colors true\n" +
56+
"$config set admin_ids.0 123456789\n" +
57+
"$config set admin_ids.* 987654321\n" +
58+
"$config set command_roles.mod 55555555\n" +
59+
"$config set messages.server_save **:mango: Game saved!**\n" +
60+
"```",
61+
},
62+
},
63+
}
1764

1865
// ModCommand returns the list of mods running on the server.
1966
func ConfigCommand(s *discordgo.Session, args string) {
2067
if args == "" {
21-
support.SendFormat(s, ConfigCommandUsage)
68+
support.SendFormat(s, "Usage: "+ConfigCommandDoc.Usage)
2269
return
2370
}
2471
action, args := support.SplitDivide(args, " ")
2572
args = strings.TrimSpace(args)
2673
if _, ok := commands[action]; !ok {
27-
support.SendFormat(s, ConfigCommandUsage)
74+
support.SendFormat(s, "Usage: "+ConfigCommandDoc.Usage)
2875
return
2976
}
3077
res := commands[action](args)

commands/admin/kick.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@ import (
99
)
1010

1111
// KickPlayerUsage comment...
12-
var KickPlayerUsage = "Usage: $kick <player> <reason>"
12+
13+
var KickPlayerDoc = support.CommandDoc{
14+
Name: "kick",
15+
Usage: "$kick <player> <reason>",
16+
Doc: `command kicks the player out from the server with a specified reason`,
17+
}
1318

1419
// KickPlayer kicks a player from the server.
1520
func KickPlayer(s *discordgo.Session, args string) {
1621
if len(args) == 0 {
17-
support.SendFormat(s, KickPlayerUsage)
22+
support.SendFormat(s, "Usage: "+KickPlayerDoc.Usage)
1823
return
1924
}
2025
args2 := strings.SplitN(args+" ", " ", 2)
2126
player := strings.TrimSpace(args2[0])
2227
reason := strings.TrimSpace(args2[1])
2328

2429
if len(player) == 0 || len(reason) == 0 {
25-
support.SendFormat(s, KickPlayerUsage)
30+
support.SendFormat(s, "Usage: "+KickPlayerDoc.Usage)
2631
return
2732
}
2833
command := "/kick " + player + " " + reason

commands/admin/mod.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,54 @@ type modPortalResponse struct {
133133
Releases []modRelease
134134
}
135135

136-
// ModCommandUsage ...
137-
var ModCommandUsage = "Usage: $mod (add|remove|enable|disable) <modnames>+ | update <modnames>*"
136+
var ModCommandDoc = support.CommandDoc{
137+
Name: "mod",
138+
Usage: "$mod (add|remove|enable|disable) <modnames>+ | update <modnames>*",
139+
Doc: "command downloads, removes, enables and disables several mods.\n" +
140+
"If mod's name contains a whitespace ' ', it's name should be quoted using double quotes (e.g. `\"Squeak Through\"`).\n" +
141+
"All subcommands can process several mods at once. Mods' names should be separated by a whitespace.",
142+
Subcommands: []support.CommandDoc{
143+
{
144+
Name: "add",
145+
Usage: "$mod add <modname>+",
146+
Doc: "command adds mods to mod-list.json and downloads the latest version or a specified version.\n" +
147+
"To download the latest version of a mod type a mod name.\n" +
148+
"To specify a version for a mod add '==' and a version (e.g. `$mod add FNEI==0.3.4`).\n" +
149+
"This command ensures that factorio version is the same as mod's factorio version.",
150+
},
151+
{
152+
Name: "update",
153+
Usage: "$mod update\n" +
154+
"$mod update <modname>+",
155+
Doc: "command updates either the specified mods or all mods.\n" +
156+
"To update a mod to the latest version specify mod name.\n" +
157+
"To update a mod to a specific version type mod name, '==', and mod version (e.g. `$mod update FNEI==0.3.4`).\n" +
158+
"To update all mods to the latest version use `$mod update`.\n" +
159+
"This command ensures that factorio version is the same as mod's factorio version.",
160+
},
161+
{
162+
Name: "remove",
163+
Usage: "$mod remove <modname>+",
164+
Doc: "command removes mods from mod-list.json and deletes mods' files",
165+
},
166+
{
167+
Name: "enable",
168+
Usage: "$mod enable <modname>+",
169+
Doc: "command enables mods in mod-list.json",
170+
},
171+
{
172+
Name: "disable",
173+
Usage: "$mod disable <modname>+",
174+
Doc: "command disables mods in mod-list.json",
175+
},
176+
},
177+
}
138178

139179
// ModCommand returns the list of mods running on the server.
140180
func ModCommand(s *discordgo.Session, args string) {
141181
argsList := strings.SplitN(args, " ", 2)
142182
if len(argsList) == 0 {
143-
support.SendFormat(s, ModCommandUsage)
183+
support.SendFormat(s, "Usage: "+ModCommandDoc.Usage)
144184
return
145185
}
146186

@@ -154,7 +194,7 @@ func ModCommand(s *discordgo.Session, args string) {
154194
return
155195
}
156196
default:
157-
support.SendFormat(s, ModCommandUsage)
197+
support.SendFormat(s, "Usage: "+ModCommandDoc.Usage)
158198
return
159199
}
160200

commands/admin/save.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import (
66
"github.com/maxsupermanhd/FactoCord-3.0/support"
77
)
88

9+
var SaveServerDoc = support.CommandDoc{
10+
Name: "save",
11+
Doc: `command sends a command to save the game to the server`,
12+
}
13+
914
// SaveServer executes the save command on the server.
1015
func SaveServer(s *discordgo.Session, args string) {
1116
if len(args) != 0 {

commands/admin/server.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@ import (
1313
"path/filepath"
1414
)
1515

16-
var ServerCommandUsage = "Usage: $server [stop|start|restart|update <version>?]"
16+
var ServerCommandDoc = support.CommandDoc{
17+
Name: "server",
18+
Usage: "$server [stop|start|restart|update <version>?]",
19+
Doc: `command manages factorio server`,
20+
Subcommands: []support.CommandDoc{
21+
{Name: "stop", Doc: `command stops the server`},
22+
{Name: "start", Doc: `command starts the server`},
23+
{Name: "restart", Doc: `command restarts the server`},
24+
{
25+
Name: "update",
26+
Doc: `command updates to server to the newest version or to the specified version`,
27+
Usage: "$server update\n" +
28+
"$server update <version>",
29+
},
30+
},
31+
}
1732

1833
func ServerCommand(s *discordgo.Session, args string) {
1934
action, arg := support.SplitDivide(args, " ")
@@ -34,7 +49,7 @@ func ServerCommand(s *discordgo.Session, args string) {
3449
case "update":
3550
serverUpdate(s, arg)
3651
default:
37-
support.SendFormat(s, ServerCommandUsage)
52+
support.SendFormat(s, "Usage: "+ServerCommandDoc.Usage)
3853
}
3954
}
4055

commands/admin/unban.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import (
88
"github.com/maxsupermanhd/FactoCord-3.0/support"
99
)
1010

11-
// UnbanPlayerUsage comment...
12-
var UnbanPlayerUsage = "Usage $unban <player>"
11+
var UnbanPlayerDoc = support.CommandDoc{
12+
Name: "unban",
13+
Usage: "$unban <player>",
14+
Doc: `command removes the player from the banlist on the server`,
15+
}
1316

1417
// UnbanPlayer unbans a player on the server.
1518
func UnbanPlayer(s *discordgo.Session, args string) {
1619
if strings.ContainsAny(args, " \n\t") {
17-
support.SendFormat(s, UnbanPlayerUsage)
20+
support.SendFormat(s, "Usage: "+UnbanPlayerDoc.Usage)
1821
return
1922
}
2023
command := "/unban " + args

0 commit comments

Comments
 (0)