2017-10-06 11:03:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
|
2019-06-05 06:45:54 +00:00
|
|
|
"github.com/akyoto/color"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2017-10-06 11:03:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2019-06-05 06:45:54 +00:00
|
|
|
err = addItemToUser(user)
|
|
|
|
arn.PanicOnError(err)
|
2018-12-24 06:50:55 +00:00
|
|
|
} else {
|
|
|
|
// All users
|
|
|
|
for user := range arn.StreamUsers() {
|
2019-06-05 06:45:54 +00:00
|
|
|
err = addItemToUser(user)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
color.Red(err.Error())
|
|
|
|
}
|
2018-12-24 06:50:55 +00:00
|
|
|
}
|
2017-10-06 11:03:36 +00:00
|
|
|
}
|
2018-12-24 06:50:55 +00:00
|
|
|
}
|
2017-10-06 11:03:36 +00:00
|
|
|
|
2019-06-05 06:45:54 +00:00
|
|
|
func addItemToUser(user *arn.User) error {
|
2017-10-06 11:03:36 +00:00
|
|
|
inventory := user.Inventory()
|
2019-06-05 06:45:54 +00:00
|
|
|
err := inventory.AddItem(itemID, uint(quantity))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-11-01 19:11:05 +00:00
|
|
|
inventory.Save()
|
2019-06-05 06:45:54 +00:00
|
|
|
return nil
|
2017-10-06 11:03:36 +00:00
|
|
|
}
|