func cmd_roll(i *Instance, m *Message, args []string) error { if len(args) < 1 { return fmt.Errorf("Missing argument.") } ret, res, e := dice.Roll(args[0]) if e != nil { return fmt.Errorf("Bad dice format.") } i.ChannelMsg(m.Channel, fmt.Sprintf("@%s has rolled: %v, %v\n", i.Users[m.User].Name, ret, res)) return nil }
func main() { rand.Seed(time.Now().UnixNano()) rollDesc := strings.Join(os.Args[1:], " ") res, reason, err := dice.Roll(rollDesc) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v", err) } else { if reason != "" { fmt.Printf("%s: ", reason) } fmt.Println(res) fmt.Println(res.Description()) } }