Exemple #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)
}
Exemple #2
0
// InitSystem register's dice commands on module load
func InitSystem(mod *modules.Module) {
	owner := &modules.OwnerPermission{}
	mod.AddResponse(quitreg, func(r *modules.Response) {
		r.Respond("okey, " + r.Nick + "! Goodbye everypony!")
		syscall.Kill(syscall.Getpid(), syscall.SIGINT)
	}, owner)
	mod.AddResponse(restartreg, func(r *modules.Response) {
		r.Respond("okey, " + r.Nick + "! Reebooot!")
		syscall.Kill(syscall.Getpid(), syscall.SIGUSR2)
	}, owner)
	mod.AddResponse(joinpartreg, func(r *modules.Response) {
		if r.Matches[1] == "join" {
			if len(r.Matches)-1 >= 3 && r.Matches[3] != "" {
				r.Server.Join("#" + r.Matches[3])
				r.Respond("okey, " + r.Nick + "! let'z join " + "#" + r.Matches[3])
			} else {
				r.Mention("tell me where to join!")
			}
		} else if r.Matches[1] == "part" {
			if len(r.Matches)-1 >= 3 && r.Matches[3] != "" {
				r.Respond("okey, " + r.Nick + "! let'z leave " + "#" + r.Matches[3])
				r.Server.Part("#" + r.Matches[3])
			} else if r.Channel != "" {
				r.Respond("okey, " + r.Nick + " leaving from here!")
				r.Server.Part(r.Channel)
			} else {
				r.Mention("tell me from what to leave!")
			}
		}

	}, owner)
	mod.AddResponse(nickreg, func(r *modules.Response) {
		r.Server.Nick(r.Matches[1])
		r.Respond("okey, " + r.Nick + "! Let'z talk as another pony!")
	}, owner)

	mod.AddResponse(statsreg, func(r *modules.Response) {
		mem := &runtime.MemStats{}
		runtime.ReadMemStats(mem)
		r.Respond("PID: " + strconv.Itoa(syscall.Getpid()) + ", last (re)start: " + human.Time(startTime) + ", sys memory: " + human.Bytes(mem.Sys))
	}, owner)
}
Exemple #3
0
func UpdateInit(mod *modules.Module) {
	owner := &modules.OwnerPermission{}
	mod.AddResponse(updatereg, func(r *modules.Response) {

		r.Respond("okey, " + r.Nick + "!")

		err, errRecover := update.New().FromUrl(mod.GetConfig().UpdateUrl)
		if err != nil {
			r.Respondf("Update failed: %v", err)
			if errRecover != nil {
				log.Errorf("Failed to recover bad update: %v!", errRecover)
				log.Fatalf("Program exectuable may be missing!")
			}
			return
		}

		log.Info("Update done!")
		r.Respond("update done!")

		//restart
		syscall.Kill(syscall.Getpid(), syscall.SIGUSR2)
	}, owner)
}
Exemple #4
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)
}