44 lines
760 B
Go
Raw Normal View History

2017-10-06 11:03:36 +00:00
package main
import (
"flag"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
var nick string
var itemID string
var quantity int
func init() {
flag.StringVar(&nick, "nick", "", "Name of the user.")
flag.StringVar(&itemID, "item", "", "ID of the item.")
flag.IntVar(&quantity, "q", 1, "Item quantity.")
flag.Parse()
}
func main() {
if nick == "" || itemID == "" {
color.Red("Missing parameters")
return
}
user, err := arn.GetUserByNick(nick)
arn.PanicOnError(err)
item, err := arn.GetItem(itemID)
arn.PanicOnError(err)
if item == nil {
color.Red("Unknown item")
return
}
// Add to user inventory
inventory := user.Inventory()
inventory.AddItem(itemID, uint(quantity))
err = inventory.Save()
arn.PanicOnError(err)
}