getiplocation

package
v1.31.10 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	CmdCategory:  commands.CategoryTool,
	Name:         "GetIPLocation",
	Aliases:      []string{"geoloc", "getiploc", "iploc"},
	Description:  "Queries IP Geolocation API on given IP-address or domain",
	RunInDM:      true,
	RequiredArgs: 1,
	Arguments: []*dcmd.ArgDef{
		{Name: "IP-address-domain", Type: dcmd.String},
	},

	RunFunc: func(data *dcmd.Data) (interface{}, error) {

		var ipAPIHost = "ip-api.com" //has 45 requests per minute for free account and no HTTPS
		var queryType = "json"
		var ipJSON ipAPIJSON

		ipArg := data.Args[0].Str()
		queryURL := fmt.Sprintf("http://%s/%s/%s", ipAPIHost, queryType, ipArg)

		body, err := getData(queryURL)
		if err != nil {
			return nil, err
		}

		queryErr := json.Unmarshal([]byte(body), &ipJSON)
		if queryErr != nil {
			return nil, queryErr
		}

		if ipJSON.Status == "fail" {
			return nil, commands.NewPublicError("Cannot fetch IP-location from given data: ", ipArg)
		}
		if ipJSON.Org == "" {
			ipJSON.Org = "-"
		}
		embed := &discordgo.MessageEmbed{
			Title:       fmt.Sprintf("Query: %s", ipJSON.Query),
			URL:         fmt.Sprintf("https://%s/%s", ipAPIHost, ipJSON.Query),
			Description: fmt.Sprintf("**Country:**\n%s (%s)\n\n**City/Region:**\n%s, %s\n\n**ISP/ORG:**\n%s; %s", ipJSON.Country, ipJSON.CountryCode, ipJSON.City, ipJSON.RegionName, ipJSON.Isp, ipJSON.Org),
			Color:       int(rand.Int63n(16777215)),
			Thumbnail: &discordgo.MessageEmbedThumbnail{
				URL: "https://ip-api.com/docs/static/logo.png",
			},
		}
		return embed, nil
	},
}

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