コード例 #1
2
ファイル: sysinput.go プロジェクト: tulir293/ranssibot
func onCommand(bot *telebot.Bot, command string, args []string) {
	if command == "msg" && len(args) > 1 {
		user := config.GetUser(args[0])
		if user.UID == config.NilUser.UID {
			log.Errorf("[Syscmds] Couldn't get an user with the name or UID %s", args[0])
		}

		msg := connect(args[1:])
		bot.SendMessage(user, "*[Sysadmin]* "+msg, util.Markdown)
		log.Infof("[Syscmds] Sent message %[1]s to %[2]s", msg, user.Name)
	} else if command == "broadcast" && len(args) > 0 {
		msg := connect(args)
		for _, user := range config.GetAllUsers() {
			bot.SendMessage(user, "*[Sysadmin Broadcast]* "+msg, util.Markdown)
		}
		log.Infof("[Syscmds] Broadcasted message %[1]s", msg)
	} else if command == "config" && len(args) > 0 {
		if strings.EqualFold(args[0], "save") {
			if !config.IndentConfig && len(args) > 1 && strings.EqualFold(args[0], "pretty") {
				config.IndentConfig = true
				config.Save()
				config.IndentConfig = false
			} else {
				config.Save()
			}
		} else if strings.EqualFold(args[0], "load") {
			config.Load()
		}
	} else if command == "stop" {
		Shutdown("Sysadmin")
	}
}
コード例 #2
0
ファイル: ranssibot.go プロジェクト: tulir293/ranssibot
func init() {
	flag.Parse()

	log.PrintDebug = *debug
	log.Fileformat = func(now string, i int) string { return fmt.Sprintf("logs/%[1]s-%02[2]d.log", now, i) }
	log.Init()
	lang.Load()
	config.IndentConfig = *debug
	config.Load()

	if !*disableSafeShutdown {
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, syscall.SIGTERM)
		go func() {
			<-c
			Shutdown("Interrupt/SIGTERM")
		}()
	}

	data, err := ioutil.ReadFile("/etc/hostname")
	if err != nil {
		log.Fatalln("Failed to read hostname: %s", err)
		return
	}
	hostname = strings.TrimSpace(string(data))
}