50 lines
870 B
Go
Raw Normal View History

2017-10-06 11:03:36 +00:00
package main
import (
"flag"
"github.com/animenotifier/arn"
)
var nick string
var itemID string
var quantity int
func init() {
2018-12-24 06:50:55 +00:00
flag.StringVar(&nick, "nick", "", "Name of the user. Leave it out to target all users.")
2017-10-06 11:03:36 +00:00
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()
2018-12-24 06:50:55 +00:00
if itemID == "" {
2018-12-24 06:57:25 +00:00
flag.Usage()
2017-10-06 11:03:36 +00:00
return
}
2018-12-24 06:50:55 +00:00
// Check that the item exists
_, err := arn.GetShopItem(itemID)
2017-10-06 11:03:36 +00:00
arn.PanicOnError(err)
2018-12-24 06:50:55 +00:00
if nick != "" {
// Single user
user, err := arn.GetUserByNick(nick)
arn.PanicOnError(err)
addItemToUser(user)
} else {
// All users
for user := range arn.StreamUsers() {
addItemToUser(user)
}
2017-10-06 11:03:36 +00:00
}
2018-12-24 06:50:55 +00:00
}
2017-10-06 11:03:36 +00:00
2018-12-24 06:50:55 +00:00
func addItemToUser(user *arn.User) {
2017-10-06 11:03:36 +00:00
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
}