Beispiel #1
0
func main() {
	conn := ts3.Dial(":10011")
	defer conn.Close()

	// repl thingy
	in := bufio.NewReader(os.Stdin)
	for {
		line, err := in.ReadString('\n')
		if err != nil {
			defer conn.Cmd("quit")
			return
		}

		// Ignore empty lines
		if line != "\n" {
			fmt.Print(conn.Cmd(line))

			if strings.HasPrefix(line, "quit") {
				return
			}
		}
	}
}
Beispiel #2
0
func main() {
	conn, _ := ts3.Dial(":10011", false)
	defer conn.Close()

	bot(conn)
}
Beispiel #3
0
func main() {
	if _, err := toml.DecodeFile("config.toml", &config); err != nil {
		fmt.Println(err)
		return
	}
	tgBot, err := tgbotapi.NewBotAPI(config.Telegrammapikey)
	if err != nil {
		log.Panic(err)
	}
	tgBot.Debug = true
	log.Printf("Telegramm Bot authorized on account %s", tgBot.Self.UserName)
	log.Printf("Connecting to TS3 Server at: %s \n", config.Tsurl)
	tsConn, err := ts3.Dial(config.Tsurl, true)
	if err != nil {
		panic(err)
	}
	//logins := make(map[string]time.Time)

	defer tsConn.Cmd("quit")
	defer tsConn.Close()
	//var oldState []string
	var state []string
	status := tsstatus.NewStatus(config.Tsurl, config.Tsuser, config.Tspasswd)
	c := status.GetChan()
	for event := range c {
		log.Println("Event-Typ:", event.Typ)
		if strings.Compare("notifycliententerview", event.Typ) == 0 {
			log.Println("Player joined")
			parts := strings.Split(event.User, " ")
			for _, part := range parts {
				if strings.Contains(part, "client_nickname=") {
					log.Println("Part:" + part)
					user := strings.Split(part, "=")[1]
					log.Println("Found a user ", user)
					state = append(state, user)
				}
			}
		}
		if strings.Compare("notifyclientleftview", event.Typ) == 0 {
			log.Println("Player joined")
			parts := strings.Split(event.User, " ")
			for _, part := range parts {
				if strings.Contains(part, "client_nickname=") {
					log.Println("Part:" + part)
					user := strings.Split(part, "=")[1]
					log.Println("Found a user ", user)
					//remove player!
				}
			}
		}
		log.Println("Online currently: ", state)
	}
	// for {
	// 	onlineUsers := tsBot(tsConn, config.Tsuser, config.Tspasswd)
	// 	for _, onlineUser := range onlineUsers {
	// 		if !contains(oldState, onlineUser) {
	// 			msg := tgbotapi.NewMessage(config.Telegrammchatid, fmt.Sprintf("%v im Teamspeak!", onlineUser))
	// 			logins[onlineUser] = time.Now()
	// 			tgBot.Send(msg)
	// 			time.Sleep(50 * time.Millisecond)
	// 			newState = append(newState, onlineUser)
	// 		}
	// 	}
	// 	for _, onlineUser := range oldState {
	// 		if !contains(onlineUsers, onlineUser) {
	// 			duration := time.Since(logins[onlineUser])
	// 			storeTime(onlineUser, duration)
	// 			msg := tgbotapi.NewMessage(config.Telegrammchatid, fmt.Sprintf("%v hat Teamspeak verlassen nach %v", onlineUser, duration))
	// 			tgBot.Send(msg)
	// 			time.Sleep(50 * time.Millisecond)
	// 		}

	// 	}
	// 	oldState = onlineUsers
	// 	newState = newState[:0]
	// 	time.Sleep(60000 * time.Millisecond)
	// }

}
Beispiel #4
0
func main() {

	var (
		username   string
		password   string
		serverID   string
		webhookURL string
		output     string
		debug      bool
	)

	flag.StringVar(&username, "u", "", "TS3 server query username")
	flag.StringVar(&password, "p", "", "TS3 server query password")
	flag.StringVar(&serverID, "id", "", "Server ID")
	flag.StringVar(&webhookURL, "url", "", "WebHookURL")
	flag.StringVar(&output, "o", "clients.json", "Output file")
	flag.BoolVar(&debug, "d", false, "Debug")
	flag.Parse()

	if username == "" || password == "" || serverID == "" || webhookURL == "" {
		panic(fmt.Errorf("Not enough options"))
	}

	conn, err := ts3.Dial(":10011", true)
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	// Login to the server.
	err = initConn(conn, username, password)
	if err != nil {
		panic(err)
	}

	// Select a server.
	err = connectToServer(conn, serverID)
	if err != nil {
		panic(err)
	}

	// Get client list.
	newState, err := getClients(conn)
	if err != nil {
		panic(err)
	}

	// Get channel information.
	channels := make(map[int]string)
	for i := range newState {
		find := false
		for k, v := range channels {
			if newState[i].CID == k {
				newState[i].ChannelName = v
				find = true
				break
			}
		}
		if !find {
			channelInfo, err := getChannelInfo(conn, newState[i].CID)
			if err != nil {
				panic(err)
			}
			channelName := ts3.Unquote(channelInfo["channel_name"])
			channels[newState[i].CID] = channelName
			newState[i].ChannelName = channelName
		}
	}

	// If output file is not exist, store state and exit.
	if _, err := os.Stat(output); err != nil {
		if err := storeClients(newState, output); err != nil {
			panic(err)
		}
		os.Exit(0)
	}

	// Getting old state from output file.
	oldState, err := loadClients(output)
	if err != nil {
		panic(err)
	}

	// Prepare to notify new clients.
	var newClients []Client
	for i := range newState {
		if isExist, old := findClient(&newState[i], oldState); isExist && !old.IsNotified {
			newClients = append(newClients, newState[i])
			newState[i].IsNotified = true
		} else if isExist && old.CID != newState[i].CID {
			newClients = append(newClients, newState[i])
			newState[i].IsNotified = true
		} else if isExist && old.IsNotified {
			newState[i].IsNotified = true
		}
	}

	// Notify logged in clients.
	if len(newClients) != 0 {
		if debug {
			// Debug
			channelMap := makeChannelMap(newClients)
			text := buildText(channelMap, true)
			fmt.Println(text)
		} else {
			if err := notifyNewClients(webhookURL, newClients); err != nil {
				panic(err)
			}
		}
	}

	// Prepare to notify leaved clients.
	var leavedClients []Client
	for i := range oldState {
		if oldState[i].IsNotified && !matchClient(&oldState[i], newState) {
			leavedClients = append(leavedClients, oldState[i])
		}
	}

	if len(leavedClients) != 0 {
		if debug {
			// Debug
			channelMap := makeChannelMap(leavedClients)
			text := buildText(channelMap, false)
			fmt.Println(text)
		} else {
			// Notify leaved clients.
			if err := notifyLeavedClients(webhookURL, leavedClients); err != nil {
				panic(err)
			}
		}
	}

	// Store new state.
	err = storeClients(newState, output)
	if err != nil {
		panic(err)
	}
}
Beispiel #5
0
func main() {
	conn := ts3.Dial(":10011")
	defer conn.Close()

	bot(conn)
}