<commit_before>package mumble

import (
	"errors"
	"fmt"
	"log"
	"strconv"
	"strings"

	"github.com/TF2Stadium/fumble/database"
	"github.com/layeh/gumble/gumble"
)

var ErrChanNotFound = errors.New("channel not found")

func printchannels(c gumble.Channels) {
	for _, channel := range c {
		log.Println(channel.Name)
	}
}

func AddLobbyChannel(l *Conn, lobbyID uint, maxplayers int) {
	name := fmt.Sprintf("Lobby #%d", lobbyID)

	l.wait.Add(1)
	l.client.Do(func() { l.client.Channels[0].Add(name, false) })
	l.wait.Wait()

	l.client.Do(func() {
		channel := l.client.Channels[0].Find(name)
		channel.SetDescription("Mumble channel for TF2Stadium " + name)
		channel.SetMaxUsers(uint32(maxplayers))

		l.wait.Add(2)
		channel.Add("RED", false)
		channel.Add("BLU", false)
	})

	l.wait.Wait()
}

//MoveUsersToRoot moves all users from the RED and BLU channels of the given lobbyID channel
//to the lobby's root channel
func MoveUsersToRoot(conn *Conn, lobbyID uint) error {
	var err error

	conn.client.Do(func() {
		name := fmt.Sprintf("Lobby #%d", lobbyID)
		root := conn.client.Channels[0].Find(name) // root lobby channel
		if root == nil {
			err = ErrChanNotFound
			return
		}

		for _, channel := range root.Children {
			for _, user := range channel.Users {
				user.Move(channel.Parent) // move to root lobby channel, but use channel.Parent
			}

			conn.wait.Add(1)
			channel.Remove()
		}
		return
	})

	conn.wait.Wait()
	return err
}

func getLobbyID(channel *gumble.Channel) uint {
	name := channel.Name
	switch name[0] {
	case 'L': // name is "Lobby #<id>"
		id, _ := strconv.ParseUint(name[strings.Index(name, "#")+1:], 10, 32)
		return uint(id)<commit_msg>Rename MoveUsersToRoot to MoveUsersToLobbyRoot<commit_after>package mumble

import (
	"errors"
	"fmt"
	"log"
	"strconv"
	"strings"

	"github.com/TF2Stadium/fumble/database"
	"github.com/layeh/gumble/gumble"
)

var ErrChanNotFound = errors.New("channel not found")

func printchannels(c gumble.Channels) {
	for _, channel := range c {
		log.Println(channel.Name)
	}
}

func AddLobbyChannel(l *Conn, lobbyID uint, maxplayers int) {
	name := fmt.Sprintf("Lobby #%d", lobbyID)

	l.wait.Add(1)
	l.client.Do(func() { l.client.Channels[0].Add(name, false) })
	l.wait.Wait()

	l.client.Do(func() {
		channel := l.client.Channels[0].Find(name)
		channel.SetDescription("Mumble channel for TF2Stadium " + name)
		channel.SetMaxUsers(uint32(maxplayers))

		l.wait.Add(2)
		channel.Add("RED", false)
		channel.Add("BLU", false)
	})

	l.wait.Wait()
}

//MoveUsersToLobbyRoot moves all users from the RED and BLU channels of the given lobbyID channel
//to the lobby's root channel
func MoveUsersToLobbyRoot(conn *Conn, lobbyID uint) error {
	var err error

	conn.client.Do(func() {
		name := fmt.Sprintf("Lobby #%d", lobbyID)
		root := conn.client.Channels[0].Find(name) // root lobby channel
		if root == nil {
			err = ErrChanNotFound
			return
		}

		for _, channel := range root.Children {
			for _, user := range channel.Users {
				user.Move(channel.Parent) // move to root lobby channel, but use channel.Parent
			}

			conn.wait.Add(1)
			channel.Remove()
		}
		return
	})

	conn.wait.Wait()
	return err
}

func getLobbyID(channel *gumble.Channel) uint {
	name := channel.Name
	switch name[0] {
	case 'L': // name is "Lobby #<id>"
		id, _ := strconv.ParseUint(name[strings.Index(name, "#")+1:], 10, 32)
		return uint(id)
{'fraction_non_alphanumeric': 0.1500738552437223, 'fraction_numerical': 0.009453471196454948, 'mean_word_length': 3.878962536023055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2439960', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1241, 'n_words': 288}