Example #1
0
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
}
Example #2
0
File: main.go Project: frenata/dice
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())
	}
}