Skip to content

Commit

Permalink
Add documentation for each command
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnoStrife committed Aug 8, 2020
1 parent a2df7eb commit a47cbc3
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 51 deletions.
11 changes: 7 additions & 4 deletions commands/admin/ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ import (
"github.com/maxsupermanhd/FactoCord-3.0/support"
)

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

// BanPlayer bans a player on the server.
func BanPlayer(s *discordgo.Session, args string) {
if len(args) == 0 {
support.SendFormat(s, BanPlayerUsage)
support.SendFormat(s, "Usage: "+BanPlayerDoc.Usage)
return
}
args2 := strings.SplitN(args+" ", " ", 2)
player := strings.TrimSpace(args2[0])
reason := strings.TrimSpace(args2[1])

if len(player) == 0 || len(reason) == 0 {
support.SendFormat(s, BanPlayerUsage)
support.SendFormat(s, "Usage: "+BanPlayerDoc.Usage)
return
}

Expand Down
55 changes: 51 additions & 4 deletions commands/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,66 @@ import (
"github.com/maxsupermanhd/FactoCord-3.0/support"
)

// ModCommandUsage ...
var ConfigCommandUsage = "Usage: $config save | load | get <path> | set <path> <value>"
var ConfigCommandDoc = support.CommandDoc{
Name: "config",
Usage: "$config save | load | get <path> | set <path> <value>?",
Doc: "command manages FactoCord's config",
Subcommands: []support.CommandDoc{
{Name: "save", Doc: "command saves FactoCord's config from memory to `config.json`"},
{
Name: "load",
Doc: "command loads the config from `config.json`.\n" +
"Any unsaved changes after the last `$config save` command will be lost.",
},
{
Name: "get",
Usage: "$config get <path>?",
Doc: "command outputs the value of a config setting specified by <path>.\n" +
"All path members are separated by a dot '.'\n" +
"If the path is empty, it outputs the whole config.\n" +
"Examples:\n" +
"```\n" +
"$config get\n" +
"$config get admin_ids\n" +
"$config get admin_ids.0\n" +
"$config get command_roles\n" +
"$config get command_roles.mod\n" +
"$config get messages\n" +
"```",
},
{
Name: "set",
Usage: "$config set <path>\n" +
"$config set <path> <value>",
Doc: "command sets the value of a config setting specified by <path>.\n" +
"This command can set only simple types such as strings, numbers, and booleans.\n" +
"If no value is specified, this command deletes the value if possible, otherwise it sets it to a zero-value (0, \"\", false).\n" +
"To add a value to an array or an object specify it's index as '*' (e.g. `$config set admin_ids.* 1234`).\n" +
"Changes made by this command are not automatically saved. Use `$config save` to do it.\n" +
"Examples:" +
"```\n" +
"$config set prefix !\n" +
"$config set game_name \"Factorio 1.0\"\n" +
"$config set ingame_discord_user_colors true\n" +
"$config set admin_ids.0 123456789\n" +
"$config set admin_ids.* 987654321\n" +
"$config set command_roles.mod 55555555\n" +
"$config set messages.server_save **:mango: Game saved!**\n" +
"```",
},
},
}

// ModCommand returns the list of mods running on the server.
func ConfigCommand(s *discordgo.Session, args string) {
if args == "" {
support.SendFormat(s, ConfigCommandUsage)
support.SendFormat(s, "Usage: "+ConfigCommandDoc.Usage)
return
}
action, args := support.SplitDivide(args, " ")
args = strings.TrimSpace(args)
if _, ok := commands[action]; !ok {
support.SendFormat(s, ConfigCommandUsage)
support.SendFormat(s, "Usage: "+ConfigCommandDoc.Usage)
return
}
res := commands[action](args)
Expand Down
11 changes: 8 additions & 3 deletions commands/admin/kick.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ import (
)

// KickPlayerUsage comment...
var KickPlayerUsage = "Usage: $kick <player> <reason>"

var KickPlayerDoc = support.CommandDoc{
Name: "kick",
Usage: "$kick <player> <reason>",
Doc: `command kicks the player out from the server with a specified reason`,
}

// KickPlayer kicks a player from the server.
func KickPlayer(s *discordgo.Session, args string) {
if len(args) == 0 {
support.SendFormat(s, KickPlayerUsage)
support.SendFormat(s, "Usage: "+KickPlayerDoc.Usage)
return
}
args2 := strings.SplitN(args+" ", " ", 2)
player := strings.TrimSpace(args2[0])
reason := strings.TrimSpace(args2[1])

if len(player) == 0 || len(reason) == 0 {
support.SendFormat(s, KickPlayerUsage)
support.SendFormat(s, "Usage: "+KickPlayerDoc.Usage)
return
}
command := "/kick " + player + " " + reason
Expand Down
48 changes: 44 additions & 4 deletions commands/admin/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,54 @@ type modPortalResponse struct {
Releases []modRelease
}

// ModCommandUsage ...
var ModCommandUsage = "Usage: $mod (add|remove|enable|disable) <modnames>+ | update <modnames>*"
var ModCommandDoc = support.CommandDoc{
Name: "mod",
Usage: "$mod (add|remove|enable|disable) <modnames>+ | update <modnames>*",
Doc: "command downloads, removes, enables and disables several mods.\n" +
"If mod's name contains a whitespace ' ', it's name should be quoted using double quotes (e.g. `\"Squeak Through\"`).\n" +
"All subcommands can process several mods at once. Mods' names should be separated by a whitespace.",
Subcommands: []support.CommandDoc{
{
Name: "add",
Usage: "$mod add <modname>+",
Doc: "command adds mods to mod-list.json and downloads the latest version or a specified version.\n" +
"To download the latest version of a mod type a mod name.\n" +
"To specify a version for a mod add '==' and a version (e.g. `$mod add FNEI==0.3.4`).\n" +
"This command ensures that factorio version is the same as mod's factorio version.",
},
{
Name: "update",
Usage: "$mod update\n" +
"$mod update <modname>+",
Doc: "command updates either the specified mods or all mods.\n" +
"To update a mod to the latest version specify mod name.\n" +
"To update a mod to a specific version type mod name, '==', and mod version (e.g. `$mod update FNEI==0.3.4`).\n" +
"To update all mods to the latest version use `$mod update`.\n" +
"This command ensures that factorio version is the same as mod's factorio version.",
},
{
Name: "remove",
Usage: "$mod remove <modname>+",
Doc: "command removes mods from mod-list.json and deletes mods' files",
},
{
Name: "enable",
Usage: "$mod enable <modname>+",
Doc: "command enables mods in mod-list.json",
},
{
Name: "disable",
Usage: "$mod disable <modname>+",
Doc: "command disables mods in mod-list.json",
},
},
}

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

Expand All @@ -154,7 +194,7 @@ func ModCommand(s *discordgo.Session, args string) {
return
}
default:
support.SendFormat(s, ModCommandUsage)
support.SendFormat(s, "Usage: "+ModCommandDoc.Usage)
return
}

Expand Down
5 changes: 5 additions & 0 deletions commands/admin/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"github.com/maxsupermanhd/FactoCord-3.0/support"
)

var SaveServerDoc = support.CommandDoc{
Name: "save",
Doc: `command sends a command to save the game to the server`,
}

// SaveServer executes the save command on the server.
func SaveServer(s *discordgo.Session, args string) {
if len(args) != 0 {
Expand Down
19 changes: 17 additions & 2 deletions commands/admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ import (
"path/filepath"
)

var ServerCommandUsage = "Usage: $server [stop|start|restart|update <version>?]"
var ServerCommandDoc = support.CommandDoc{
Name: "server",
Usage: "$server [stop|start|restart|update <version>?]",
Doc: `command manages factorio server`,
Subcommands: []support.CommandDoc{
{Name: "stop", Doc: `command stops the server`},
{Name: "start", Doc: `command starts the server`},
{Name: "restart", Doc: `command restarts the server`},
{
Name: "update",
Doc: `command updates to server to the newest version or to the specified version`,
Usage: "$server update\n" +
"$server update <version>",
},
},
}

func ServerCommand(s *discordgo.Session, args string) {
action, arg := support.SplitDivide(args, " ")
Expand All @@ -34,7 +49,7 @@ func ServerCommand(s *discordgo.Session, args string) {
case "update":
serverUpdate(s, arg)
default:
support.SendFormat(s, ServerCommandUsage)
support.SendFormat(s, "Usage: "+ServerCommandDoc.Usage)
}
}

Expand Down
9 changes: 6 additions & 3 deletions commands/admin/unban.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (
"github.com/maxsupermanhd/FactoCord-3.0/support"
)

// UnbanPlayerUsage comment...
var UnbanPlayerUsage = "Usage $unban <player>"
var UnbanPlayerDoc = support.CommandDoc{
Name: "unban",
Usage: "$unban <player>",
Doc: `command removes the player from the banlist on the server`,
}

// UnbanPlayer unbans a player on the server.
func UnbanPlayer(s *discordgo.Session, args string) {
if strings.ContainsAny(args, " \n\t") {
support.SendFormat(s, UnbanPlayerUsage)
support.SendFormat(s, "Usage: "+UnbanPlayerDoc.Usage)
return
}
command := "/unban " + args
Expand Down
Loading

0 comments on commit a47cbc3

Please sign in to comment.