layeh / gumble

gumble is a Mumble client implementation in Go (golang)
https://pkg.go.dev/mod/layeh.com/gumble
Mozilla Public License 2.0
173 stars 53 forks source link

Getting Channels.Find working #36

Closed s3m1s0n1c closed 7 years ago

s3m1s0n1c commented 7 years ago

Hey Guys,

Trying to get this function to work but its not working.

I use this function to see what channel we should be in and then move to that channel using the function below which uses channels.find

func (b *mumble) ChangeChannel(ChannelName string) {

        channel := b.Client.Channels.Find(ChannelName)
 if channel != nil {
                b.Client.Self.Move(channel)
} else {
                fmt.Printf("Unable to find channel: %s\n", ChannelName)
        }
}

So this functions uses Channel.Find to get the channels under above the channel we wanna be in but this function below wont work for me.

func (c *Channel) Find(names ...string) *Channel {

if len(names) == 0 {
                return c
        }
        for _, child := range c.Children {
                if child.Name == names[0] {
                        return child.Find(names[1:]...)
                }
        }
        return nil
}

Any Ideas?

Thanks Sonic

ghost commented 7 years ago

By specifying ChannelName a single string, you are restricting the channels you can find to children of the root channel.

For example, if you have a server like:

Root
  Child 1
  Child 2
    Child 2.1
    Child 2.2
      Child 2.2.1
  Child 3

The only value of ChannelName that would cause b.Client.Channels.Find to succeed are "Child 1", "Child 2", and "Child 3". You would not be able to find any of the other channels, including the root channel.

What you should be doing instead is create a slice of strings which specify a path to the channel. For example:

ChannelName := []string{"Child 2", "Child 2.2", "Child 2.2.1"}
channel := b.Client.Channels.Find(ChannelName...)

That code would return the deeply nested "Child 2.2.1" channel.

How parse and generate the string slice of channel names is up to you.

s3m1s0n1c commented 7 years ago

Thanks.. Will try and work it out.. I'm only new to golang..