45 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() {
2017-11-01 19:11:05 +00:00
defer arn.Node.Close()
2017-10-06 11:03:36 +00:00
if nick == "" || itemID == "" {
color.Red("Missing parameters")
return
}
user, err := arn.GetUserByNick(nick)
arn.PanicOnError(err)
2018-03-27 23:59:14 +00:00
item, err := arn.GetShopItem(itemID)
2017-10-06 11:03:36 +00:00
arn.PanicOnError(err)
if item == nil {
color.Red("Unknown item")
return
}
// Add to user inventory
inventory := user.Inventory()
inventory.AddItem(itemID, uint(quantity))
2017-11-01 19:11:05 +00:00
inventory.Save()
2017-10-06 11:03:36 +00:00
}