Documentation
¶
Overview ¶
Package pgo provides a set of commands that access the Politics And War API for information. All commands take a slice of strings as arguments and returns a string as an output
This package is not meant to be used directly, but is instead meant to be used as a command line interface, which is located in pgo/cmd/pgo. A version that can be run as a discord bot is also availible in pgo/cmd/pgo-discord.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var API = "https://api.politicsandwar.com/graphql"
API is the API URL
var ErrorHandler func(error) string = func(err error) string {
return err.Error()
}
ErrorHandler is the function for handling errors. It should take an error and output a string in the desired format.
var HelpTemplate = template.Must(template.New("help").Funcs(template.FuncMap{"usages": func(fs *flag.FlagSet) string { return fs.FlagUsages() }}).Parse(`{{ .Name }} - {{ .Description }}
ALIASES{{ range .Aliases }}
{{ . }}{{end}}
ARGUMENTS
{{ .FlagSet.FlagUsages }}`))
HelpTemplate is the template for help messages.
var Key string
Key is the API key
var NoCommandHandler func(string) string = func(command string) string { return fmt.Sprintf("Command %s does not exist.", command) }
NoCommandHandler is the function for handling commands that were requested but do not exist. It should take the requested command name as a string and output a string.
var WhoAllianceTemplate = template.Must(template.New("whoAlliance").Parse(`# __{{.Data.Name}}__ ({{.Data.Acronym}})
*https://politicsandwar.com/alliance/id={{.Data.ID}}*
## General Information
- Total score: *{{.Data.Score}}*
- *{{.Cities}}* cities in total.
- *{{.Members}}* members and *{{.Applicants}}* applicants.
- Color: **{{.Data.Color}}**
## Wars
- Involved in a total of *{{.TotalWars}}* wars.
- *{{.OffensiveWars}}* are offensive and *{{.DefensiveWars}}* are defensive.
- Raiding in *{{.OffensiveRaids}}* wars and are being raided in *{{.DefensiveRaids}}*.
- Winning roughly {{.WinningWarPercent}}% of their wars.
## Treaties{{with .Data.Treaties}}{{range .}}
- **{{printf "%-12s" .TreatyType}}**: {{$oneIsAlliance := eq .Alliance1.Name $.Data.Name}}{{if $oneIsAlliance}}*{{end}}*{{printf "%24s" .Alliance1.Name}}*{{if $oneIsAlliance}}*{{end}} --=#=-- {{if not $oneIsAlliance}}*{{end}}*{{.Alliance2.Name}}*{{if not $oneIsAlliance}}*{{end}}
{{end}}{{else}}
**NONE**{{end}}`))
Functions ¶
func AddCommand ¶
func AddCommand(command *Command)
AddCommand registers the given command, along with its aliases.
func DeleteCommand ¶
func DeleteCommand(name string)
DeleteCommand deletes a command by name, and removes all aliases. Aliases do not work for the name.
func HelpSubCommand ¶
HelpSubCommand provides help for the provided subcommand using HelpTemplate.
Types ¶
type Command ¶
type Command struct { // Name is the name of the subcommand. Name string // Action is the body of the subcommand. // It takes the provided arguments (excluding the subcommand name) and outputs the output string, // along with any error that may happen. Action func([]string) (string, error) // The subcommand's description, for use in help messages. Description string // Aliases for the subcommand. These should also work when running the command. Aliases []string flags.Flags }
Command is a type for pgo's subcommands.
func GetCommand ¶
GetCommand gets a command by provided name. If the command does not exist, ok is false. Aliases are also searchable.