validation

package module
v0.0.0-...-8c5a239 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRunesAllowedInACharacterName     = 29 // Larggest character name length possible
	MinRunesAllowedInACharacterName     = 2  // Smallest character name length possible
	MaxRunesAllowedInACharacterNameWord = 20 // Larggest character name word length possible (new names only 14, but older ones are longer)
	MinRunesAllowedInACharacterNameWord = 1  // Smallest character name word length possible

	MaxRunesAllowedInAGuildName     = 29 // Larggest guild name length possible
	MinRunesAllowedInAGuildName     = 3  // Smallest guild name length possible
	MaxRunesAllowedInAGuildNameWord = 14 // Larggest guild name word length possible
	MinRunesAllowedInAGuildNameWord = 2  // Smallest character name word length possible

	// AmountOfBoostableBosses is the amount of boostable bosses.
	// Last updated: Oct 08 2023
	AmountOfBoostableBosses = 95
)
View Source
const (
	TIBIADATA_API_TESTING = "TibiaData-API-Testing"
	TIBIADATA_JSON_ERROR  = "Wanted json error: %s, got %s instead"
)

Variables

View Source
var (

	// ErrorAlreadyRunning will be sent when InitiateValidator() is called but the validator is already running
	// Code: 10
	ErrorAlreadyRunning = Error{errors.New("validator has already been initiated on this session")}

	// ErrorValidatorNotInitiated will be sent when a validation func is called but the validator has not been initiated
	// Code: 11
	ErrorValidatorNotInitiated = Error{errors.New("validator func called but the validator has not been initiated")}

	// ErrorStringCanNotBeConvertedToInt will be sent if the request needs to be converted to an int but can't
	// Code: 9001
	ErrorStringCanNotBeConvertedToInt = Error{errors.New("the provided string can not be converted to an integer")}

	// ErrorRestrictionMode will be sent if the request contains a page that is not available due to restriction mode
	// Code: 9002
	ErrorRestrictionMode = Error{errors.New("the provided page is not available due to restriction mode")}

	// ErrorCharacterNameEmpty will be sent if the request contains an empty character name
	// Code: 10001
	ErrorCharacterNameEmpty = Error{errors.New("the provided character name is an empty string")}

	// ErrorCharacterNameTooSmall will be sent if the request contains a character name of length < MinRunesAllowedInACharacterName
	// Code: 10002
	ErrorCharacterNameTooSmall = Error{errors.New("the provided character name is too small")}

	// ErrorCharacterNameInvalid will be sent if the request contains an invalid character name
	// Code: 10003
	ErrorCharacterNameInvalid = Error{errors.New("the provided character name is invalid")}

	// ErrorCharacterNameIsOnlyWhiteSpace will be sent if the request contains a name that consists of only whitespaces
	// Code: 10004
	ErrorCharacterNameIsOnlyWhiteSpace = Error{errors.New("the provided character name consists only of whitespaces")}

	// ErrorCharacterNameTooBig will be sent if the request contains a character name of length > MaxRunesAllowedInACharacterName
	// Code: 10005
	ErrorCharacterNameTooBig = Error{errors.New("the provided character name is too big")}

	// ErrorCharacterWordTooBig will be sent if the request contains a word with length > MaxRunesAllowedInACharacterNameWord in the character name
	// Code: 10006
	ErrorCharacterWordTooBig = Error{errors.New("the provided character name has a word too big")}

	// ErrorCharacterWordTooSmall will be sent if the request contains a word with length < MinRunesAllowedInACharacterNameWord in the character name
	// Code: 10007
	ErrorCharacterWordTooSmall = Error{errors.New("the provided character name has a word too small")}

	// ErrorInvalidNewsID will be sent if the request contains an invalid news ID
	// Code: 11001
	ErrorInvalidNewsID = Error{errors.New("the provided news id is invalid")}

	// ErrorWorldDoesNotExist will be sent if the request contains a world that does not exist
	// Code: 11002
	ErrorWorldDoesNotExist = Error{errors.New("the provided world does not exist")}

	// ErrorVocationDoesNotExist will be sent if the request contains a vocation that does not exist
	// Code: 11003
	ErrorVocationDoesNotExist = Error{errors.New("the provided vocation does not exist")}

	// ErrorHighscoreCategoryDoesNotExist will be sent if the request contains a highscore catregory that does not exist
	// Code: 11004
	ErrorHighscoreCategoryDoesNotExist = Error{errors.New("the provided highscore category does not exist")}

	// ErrorHouseDoesNotExist will be sent if the request contains a house that does not exist
	// Code: 11005
	ErrorHouseDoesNotExist = Error{errors.New("the provided house does not exist")}

	// ErrorTownDoesNotExist will be sent if the request contains a town that does not exist
	// Code: 11006
	ErrorTownDoesNotExist = Error{errors.New("the provided town does not exist")}

	// ErrorHighscorePageInvalid will be sent if the page is not valid
	// Code: 11007
	ErrorHighscorePageInvalid = Error{errors.New("the provided page does not exist or is invalid")}

	// ErrorHighscorePageTooBig
	// Code: 11008
	ErrorHighscorePageTooBig = Error{errors.New("the provided page is larger than max amount of pages")}

	// ErrorCreatureNameEmpty will be sent if the request contains an empty creature name
	// Code: 12001
	ErrorCreatureNameEmpty = Error{errors.New("the provided creature name is an empty string")}

	// ErrorCreatureNameTooSmall will be sent if the request contains a creature name of length < smallestCreatureName
	// Code: 12002
	ErrorCreatureNameTooSmall = Error{errors.New("the provided creature name is too smal")}

	// ErrorCreatureNameInvalid will be sent if the request contains an invalid creature name
	// Code: 12003
	ErrorCreatureNameInvalid = Error{errors.New("the provided creature name is invalid")}

	// ErrorCreatureNameIsOnlyWhiteSpace will be sent if the request contains a name that consists of only whitespaces
	// Code: 12004
	ErrorCreatureNameIsOnlyWhiteSpace = Error{errors.New("the provided creature name consists only of whitespaces")}

	// ErrorCreatureNameTooBig will be sent if the request contains a creature name of length > biggestCreatureNameRuneCount
	// Code: 12005
	ErrorCreatureNameTooBig = Error{errors.New("the provided creature name is too big")}

	// ErrorCreatureWordTooBig will be sent if the request contains a word with length > biggestCreatureWordRuneCount in the creature name
	// Code: 12006
	ErrorCreatureWordTooBig = Error{errors.New("the provided creature name has a word too big")}

	// ErrorCreatureWordTooSmall will be sent if the request contains a word with length < smallestCreatureWordRuneCount in the creature name
	// Code: 12007
	ErrorCreatureWordTooSmall = Error{errors.New("the provided creature name has a word too small")}

	// ErrorSpellNameEmpty will be sent if the request contains an empty spell name
	// Code: 13001
	ErrorSpellNameEmpty = Error{errors.New("the provided spell name is an empty string")}

	// ErrorSpellNameTooSmall will be sent if the request contains a spell name of length < smallestSpellNameOrFormulaRuneCount
	// Code: 13002
	ErrorSpellNameTooSmall = Error{errors.New("the provided spell name is too smal")}

	// ErrorSpellNameInvalid will be sent if the request contains an invalid spell name
	// Code: 13003
	ErrorSpellNameInvalid = Error{errors.New("the provided spell name is invalid")}

	// ErrorSpellNameIsOnlyWhiteSpace will be sent if the request contains a name that consists of only whitespaces
	// Code: 13004
	ErrorSpellNameIsOnlyWhiteSpace = Error{errors.New("the provided spell name consists only of whitespaces")}

	// ErrorSpellNameTooBig will be sent if the request contains a spell name of length > biggestSpellNameOrFormulaRuneCount
	// Code: 13005
	ErrorSpellNameTooBig = Error{errors.New("the provided spell name is too big")}

	// ErrorSpellWordTooBig will be sent if the request contains a word with length > biggestSpellWordRuneCount in the spell name
	// Code: 13006
	ErrorSpellWordTooBig = Error{errors.New("the provided spell name has a word too big")}

	// ErrorSpellWordTooSmall will be sent if the request contains a word with length < smallestSpellWordRuneCount in the creature name
	// Code: 13007
	ErrorSpellWordTooSmall = Error{errors.New("the provided spell name has a word too small")}

	// ErrorGuildNameEmpty will be sent if the request contains an empty guild name
	// Code: 14001
	ErrorGuildNameEmpty = Error{errors.New("the provided guild name is an empty string")}

	// ErrorGuildNameTooSmall will be sent if the request contains a Guild name of length < MinRunesAllowedInAGuildName
	// Code: 14002
	ErrorGuildNameTooSmall = Error{errors.New("the provided guild name is too small")}

	// ErrorGuildNameInvalid will be sent if the request contains an invalid guild name
	// Code: 14003
	ErrorGuildNameInvalid = Error{errors.New("the provided guild name is invalid")}

	// ErrorGuildNameIsOnlyWhiteSpace will be sent if the request contains a name that consists of only whitespaces
	// Code: 14004
	ErrorGuildNameIsOnlyWhiteSpace = Error{errors.New("the provided guild name consists only of whitespaces")}

	// ErrorGuildNameTooBig will be sent if the request contains a guild name of length > MaxRunesAllowedInAGuildName
	// Code: 14005
	ErrorGuildNameTooBig = Error{errors.New("the provided guild name is too big")}

	// ErrorGuildWordTooBig will be sent if the request contains a word with length > MaxRunesAllowedInAGuildNameWord in the guild name
	// Code: 14006
	ErrorGuildWordTooBig = Error{errors.New("the provided guild name has a word too big")}

	// ErrorGuildWordTooSmall will be sent if the request contains a word with length < MinRunesAllowedInAGuildNameWord in the guild name
	// Code: 14007
	ErrorGuildWordTooSmall = Error{errors.New("the provided guild name has a word too smal")}

	// ErrorCharacterNotFound will be sent if the requested character does not exist
	// Code: 20001
	ErrorCharacterNotFound = Error{errors.New("could not find character")}

	// ErrorCreatureNotFound will be sent if the requested creature does not exist
	// Code: 20002
	ErrorCreatureNotFound = Error{errors.New("could not find creature")}

	// ErrorSpellNotFound will be sent if the requested spell does not exist
	// Code: 20003
	ErrorSpellNotFound = Error{errors.New("could not find spell")}

	// ErrorGuildNotFound will be sent if the requested guild does not exist
	// Code: 20004
	ErrorGuildNotFound = Error{errors.New("could not find guild")}

	// ErrorMaintenanceMode will be sent if there is ongoing maintenance
	// Code: 20005
	ErrorMaintenanceMode = Error{errors.New("maintenance mode active")}

	// ErrStatusForbidden will be sent if tibia sent us a 403 response.
	// This usually happens when we are rate limited.
	// Code: 20006
	ErrStatusForbidden = Error{errors.New("got status forbidden from tibia.com")}

	// ErrStatusForbidden will be sent if tibia sent us a 302 response, but it
	// is not in MaintenanceMode. Because if it were, we would throw a
	// ErrorMaintenanceMode.
	// Code: 20007
	ErrStatusFound = Error{errors.New("got status found from tibia.com")}

	// ErrStatusUnknown will be sent a HTTP request we are not expecting.
	// Code: 20008
	ErrStatusUnknown = Error{errors.New("got unknown status from tibia.com")}
)

Functions

func DoesStringContainDigits

func DoesStringContainDigits(str string) bool

DoesStringContainDigits returns whether there is a digit rune in the string

func DoesStringContainsNumbers

func DoesStringContainsNumbers(str string) bool

DoesStringContainsNumbers returns whether there is a number rune in the string

func GetBiggestCreatureName

func GetBiggestCreatureName() (string, error)

GetBiggestCreatureName returns the name of the creature with the biggest name

func GetBiggestCreatureNameRuneCount

func GetBiggestCreatureNameRuneCount() (int, error)

GetBiggestCreatureNameRuneCount returns the length of the biggest creature name

func GetBiggestCreatureWord

func GetBiggestCreatureWord() (string, error)

GetBiggestCreatureWord returns the biggest word in a creature name

func GetBiggestCreatureWordRuneCount

func GetBiggestCreatureWordRuneCount() (int, error)

GetBiggestCreatureWordRuneCount returns the length of the biggest creature word

func GetBiggestSpellNameOrFormula

func GetBiggestSpellNameOrFormula() (string, error)

GetBiggestSpellNameOrFormula returns the name of the spell with the biggest name or formula

func GetBiggestSpellNameOrFormulaRuneCount

func GetBiggestSpellNameOrFormulaRuneCount() (int, error)

GetBiggestSpellNameOrFormulaRuneCount returns the length of the biggest spell name

func GetBiggestSpellWord

func GetBiggestSpellWord() (string, error)

GetBiggestSpellWord returns the biggest word in a spell name or formula

func GetBiggestSpellWordRuneCount

func GetBiggestSpellWordRuneCount() (int, error)

GetBiggestSpellWordRuneCount returns the length of the biggest spell word

func GetSha256Sum

func GetSha256Sum() (string, error)

GetSha256Sum returns the sha256sum of the data.min.json file being used

func GetSha512Sum

func GetSha512Sum() (string, error)

GetSha512Sum returns the sha512sum of the data.min.json file being used

func GetSmallestCreatureName

func GetSmallestCreatureName() (string, error)

GetSmallestCreatureName returns the name of the creature with the smallest name

func GetSmallestCreatureNameRuneCount

func GetSmallestCreatureNameRuneCount() (int, error)

GetSmallestCreatureNameRuneCount returns the length of the smallest creature name

func GetSmallestCreatureWord

func GetSmallestCreatureWord() (string, error)

GetSmallestCreatureWord returns the smallest word in a creature name

func GetSmallestCreatureWordRuneCount

func GetSmallestCreatureWordRuneCount() (int, error)

GetSmallestCreatureWordRuneCount returns the length of the smallest creature word

func GetSmallestSpellNameOrFormula

func GetSmallestSpellNameOrFormula() (string, error)

GetSmallestSpellNameOrFormula returns the name of the spell with the smallest name or formula

func GetSmallestSpellNameOrFormulaRuneCount

func GetSmallestSpellNameOrFormulaRuneCount() (int, error)

GetSmallestSpellNameOrFormulaRuneCount returns the length of the smallest spell name

func GetSmallestSpellWord

func GetSmallestSpellWord() (string, error)

GetSmallestSpellWord returns the smallest word in a spell name or formula

func GetSmallestSpellWordRuneCount

func GetSmallestSpellWordRuneCount() (int, error)

GetSmallestSpellWordRuneCount returns the length of the smallest spell word

func GetTowns

func GetTowns() ([]string, error)

GetTowns returns a list of all existing towns

func GetWorlds

func GetWorlds() ([]string, error)

GetWorlds returns a list of all existing worlds

func HouseExistsInTown

func HouseExistsInTown(houseID int, town string) (bool, error)

HouseExistsInTown reports whether a house exits in the specified town This function will return false AND a nil error if the specified ID doesn't exist in the specified town or if the specified town doesn't exist

func HouseExistsRaw

func HouseExistsRaw(houseID int) (bool, error)

HouseExistsRaw reports whether a house exits, independently of what town the house is from

func Initiate

func Initiate(TibiaDataUserAgent string) error

Initiate initiates the validator, this should be called on the init() func

func IsCharacterNameValid

func IsCharacterNameValid(name string) error

IsCharacterNameValid reports wheter the provided string represents a valid character name Check if error == nil to see whether the name is valid or not

func IsCreatureNameValid

func IsCreatureNameValid(name string) (string, error)

IsCreatureNameValid reports wheter the provided string represents a valid creature name Check if error == nil to see whether the creature is valid or not It will also return the creature endpoint

func IsGuildNameValid

func IsGuildNameValid(name string) error

IsGuildNameValid reports wheter the provided string represents a valid guild name Check if error == nil to see whether the name is valid or not

func IsHighscoreCategoryValid

func IsHighscoreCategoryValid(hs string) error

IsHighscoreCategoryValid reports wheter the provided string represents a valid highscore category Check if error == nil to see whether the highscore category is valid or not

func IsNewsIDValid

func IsNewsIDValid(ID int) error

IsNewsIDValid reports wheter the provided int represents a valid news ID Check if error == nil to see whether the ID is valid or not

func IsRestrictionMode

func IsRestrictionMode(mode bool) error

IsRestrictionMode reports whether the restriction mode is enabled Check if error == nil to see whether the restriction mode is enabled or not

func IsSpellNameOrFormulaValid

func IsSpellNameOrFormulaValid(name string) (string, error)

IsSpellNameOrFormulaValid reports wheter the provided string represents a valid spell name or formula Check if error == nil to see whether the creature is valid or not It will also return the spell endpoint

func IsVocationValid

func IsVocationValid(vocation string) error

IsVocationValid reports wheter the provided string represents a valid vocation Check if error == nil to see whether the vocation is valid or not

func TownExists

func TownExists(town string) (bool, error)

TowndExists reports whether the specified town exists This function is case insensitive

func WorldExists

func WorldExists(world string) (bool, error)

WorldExists reports whether the specified world exists This function is case insensitive

Types

type Creature

type Creature struct {
	Endpoint   string `json:"endpoint"`
	PluralName string `json:"plural_name"`
	Name       string `json:"name"`
}

func GetCreatures

func GetCreatures() ([]Creature, error)

GetCreatures returns a list of all existing creatures

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents a validation error

func (Error) Code

func (e Error) Code() int

Code will return the code of the error

type HighscoreCategory

type HighscoreCategory int
const (
	HighScoreAchievements HighscoreCategory = iota + 1
	HighScoreAxefighting
	HighScoreCharmpoints
	HighScoreClubfighting
	HighScoreDistancefighting
	HighScoreExperience
	HighScoreFishing
	HighScoreFistfighting
	HighScoreGoshnarstaint
	HighScoreLoyaltypoints
	HighScoreMagiclevel
	HighScoreShielding
	HighScoreSwordfighting
	HighScoreDromescore
	HighScoreBosspoints
)

func HighscoreCategoryFromString

func HighscoreCategoryFromString(input string) HighscoreCategory

func (HighscoreCategory) String

func (hc HighscoreCategory) String() (string, error)

type House

type House struct {
	ID   int    `json:"house_id"`
	Town string `json:"town"`
	Type string `json:"type"`
}

Houses represents a house

func GetHouseInTown

func GetHouseInTown(houseID int, town string) (House, error)

GetHouseInTown returns a house by it's ID and town This function will return a nil house AND a nil error if the specified ID doesn't exist in the specified town or if the specified town doesn't exist

func GetHouseRaw

func GetHouseRaw(houseID int) (House, error)

GetHouseRaw returns a house by it's ID, independently of what town the house is from This function will return a nil house AND a nil error if the specified ID doesn't exist

func GetHouses

func GetHouses() ([]House, error)

GetHouses returns a slice of all houses

type Spell

type Spell struct {
	Name     string `json:"name"`
	Formula  string `json:"formula"`
	Endpoint string `json:"endpoint"`
}

Jump to

Keyboard shortcuts

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