Example #1
0
// InitCoin register's coin command on module load
func InitCoin(mod *modules.Module) {
	mod.AddResponse(coinreg, func(r *modules.Response) {
		throwCoin(r.Message)
	}, nil)
	mod.AddCommand("coin", func(r *modules.Command) {
		throwCoin(r.Message)
	}, nil)
}
Example #2
0
// InitDice register's dice commands on module load
func InitDice(mod *modules.Module) {
	mod.AddResponse(dicereg, func(r *modules.Response) {
		if len(r.Matches)-1 >= 4 && r.Matches[4] != "" {
			dice := strings.Split(r.Matches[4], "d")
			dices, _ := strconv.Atoi(dice[0])
			faces, _ := strconv.Atoi(dice[1])
			throwDice(r.Message, dices, faces)
		} else {
			throwDice(r.Message, 1, 6)
		}
	}, nil)
	mod.AddCommand("dice", func(r *modules.Command) {
		matches := dicesubreg.FindStringSubmatch(r.Text)
		if len(matches)-1 >= 1 && matches[1] != "" {
			dice := strings.Split(matches[1], "d")
			dices, _ := strconv.Atoi(dice[0])
			faces, _ := strconv.Atoi(dice[1])
			throwDice(r.Message, dices, faces)
		} else {
			throwDice(r.Message, 1, 6)
		}
	}, nil)
}