howlongtobeat

package
v2.42.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	CmdCategory:         commands.CategoryFun,
	Name:                "HowLongToBeat",
	Aliases:             []string{"hltb"},
	RequiredArgs:        1,
	Description:         "Game information based on query from howlongtobeat.com.\nResults are sorted by popularity, it's their default. Without -p returns the first result.\nSwitch -p gives paginated output using the Jaro-Winkler similarity metric sorting max 20 results.",
	DefaultEnabled:      true,
	SlashCommandEnabled: true,
	Arguments: []*dcmd.ArgDef{
		{Name: "Game-Title", Type: dcmd.String},
	},
	ArgSwitches: []*dcmd.ArgDef{
		{Name: "c", Help: "Compact output"},
		{Name: "p", Help: "Paginated output"},
	},
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		var compactView, paginatedView bool
		gameName := data.Args[0].Str()

		if data.Switches["c"].Value != nil && data.Switches["c"].Value.(bool) {
			compactView = true
		}

		if data.Switches["p"].Value != nil && data.Switches["p"].Value.(bool) {
			compactView = false
			paginatedView = true
		}

		games, err := getGameData(gameName)
		if err != nil {
			return nil, err
		}

		if len(games) == 0 {
			return "No results", nil
		}

		games = parseGameData(gameName, games)
		if compactView {
			compactData := fmt.Sprintf("%s: %s | %s | %s | <%s>",
				normaliseTitle(games[0].GameTitle),
				games[0].MainStoryTimeHours,
				games[0].MainStoryExtraTimeHours,
				games[0].CompletionistTimeHours,
				games[0].GameURL,
			)
			return compactData, nil
		}

		hltbEmbed := embedCreator(games, 0, paginatedView)

		if paginatedView {
			return paginatedmessages.NewPaginatedResponse(
				data.GuildData.GS.ID, data.ChannelID, 1, len(games), func(p *paginatedmessages.PaginatedMessage, page int) (*discordgo.MessageEmbed, error) {
					i := page - 1
					sort.SliceStable(games, func(i, j int) bool {
						return games[i].JaroWinklerSimilarity > games[j].JaroWinklerSimilarity
					})
					paginatedEmbed := embedCreator(games, i, paginatedView)
					return paginatedEmbed, nil
				}), nil
		}

		return hltbEmbed, nil
	},
}

Command var needs a comment for lint :)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL