Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &commands.YAGCommand{ CmdCategory: commands.CategoryFun, Cooldown: 5, Name: "Forex", Aliases: []string{"Money"}, Description: "💱 convert value from one currency to another.", RunInDM: true, DefaultEnabled: true, SlashCommandEnabled: true, RequiredArgs: 3, Arguments: []*dcmd.ArgDef{ {Name: "Amount", Type: dcmd.Float}, {Name: "From", Type: dcmd.String}, {Name: "To", Type: dcmd.String}, }, RunFunc: func(data *dcmd.Data) (interface{}, error) { amount := data.Args[0].Float64() var currenciesResult Currencies var exchangeRateResult ExchangeRate err := requestAPI(currenciesAPIURL, ¤ciesResult) if err != nil { return nil, err } from := strings.ToUpper(data.Args[1].Str()) to := strings.ToUpper(data.Args[2].Str()) _, fromExist := currenciesResult[from] _, toExist := currenciesResult[to] maxPages := int(math.Ceil(float64(len(currenciesResult)) / float64(currencyPerPage))) if !toExist || !fromExist { _, err = paginatedmessages.CreatePaginatedMessage( data.GuildData.GS.ID, data.ChannelID, 1, maxPages, func(p *paginatedmessages.PaginatedMessage, page int) (*discordgo.MessageEmbed, error) { embed, err := errEmbed(currenciesResult, page) if err != nil { return nil, err } return embed, nil }) if err != nil { return nil, err } return nil, nil } err = requestAPI(fmt.Sprintf("https://api.frankfurter.app/latest?amount=%.3f&from=%s&to=%s", amount, from, to), &exchangeRateResult) if err != nil { return nil, err } p := message.NewPrinter(language.English) embed := &discordgo.MessageEmbed{ Title: "💱Currency Exchange Rate", Description: p.Sprintf("\n%.2f **%s** (%s) is %.3f **%s** (%s).", amount, currenciesResult[from], from, exchangeRateResult.Rates[to], currenciesResult[to], to), Color: 0xAE27FF, Timestamp: time.Now().UTC().Format(time.RFC3339), } return embed, nil }, }
Functions ¶
This section is empty.
Types ¶
type Currencies ¶ added in v2.30.0
Click to show internal directories.
Click to hide internal directories.