Exemplo n.º 1
0
func (suite *HelpCommandTestSuite) TestExecuteWhenPermissionsEnabledAndUserIsAdmin() {
	viper.Set("admins.names", []string{"SuperUser"})
	user := new(gumble.User)
	user.Name = "SuperUser"

	message, isPrivateMessage, err := suite.Command.Execute(user)

	suite.NotEqual("", message, "A message should be returned.")
	suite.True(isPrivateMessage, "This should be a private message.")
	suite.Nil(err, "No error should be returned.")
	suite.Contains(message, "help", "The returned message should contain command descriptions.")
	suite.Contains(message, "add", "The returned message should contain command descriptions.")
	suite.Contains(message, "Admin Commands", "The returned message should contain admin command descriptions.")
}
Exemplo n.º 2
0
func moveUserToLobbyChannel(client *gumble.Client, user *gumble.User, lobbyID uint, team string) {
	name := fmt.Sprintf("Lobby #%d", lobbyID)
	channel := client.Channels[0].Find(name)
	if channel == nil {
		log.Printf("Couldn't find channel %s", name)
		return
	}

	teamChannel := channel.Find(strings.ToUpper(team))
	if teamChannel == nil {
		log.Printf("Couldn't find channel %s in %s", team, name)
		return
	}

	user.Move(teamChannel)
}
Exemplo n.º 3
0
// UserGroups fetches the group names the given user belongs to in the given
// channel. The slice of group names sent via the returned channel. On error,
// the returned channel is closed without without sending a slice.
func UserGroups(client *gumble.Client, user *gumble.User, channel *gumble.Channel) <-chan []string {
	ch := make(chan []string)

	if !user.IsRegistered() {
		close(ch)
		return ch
	}

	var detacher gumble.Detacher
	listener := Listener{
		Disconnect: func(e *gumble.DisconnectEvent) {
			detacher.Detach()
			close(ch)
		},
		ChannelChange: func(e *gumble.ChannelChangeEvent) {
			if e.Channel == channel && e.Type.Has(gumble.ChannelChangeRemoved) {
				detacher.Detach()
				close(ch)
			}
		},
		PermissionDenied: func(e *gumble.PermissionDeniedEvent) {
			if e.Channel == channel && e.Type == gumble.PermissionDeniedPermission && (e.Permission&gumble.PermissionWrite) != 0 {
				detacher.Detach()
				close(ch)
			}
		},
		ACL: func(e *gumble.ACLEvent) {
			if e.ACL.Channel != channel {
				return
			}
			var names []string
			for _, g := range e.ACL.Groups {
				if (g.UsersAdd[user.UserID] != nil || g.UsersInherited[user.UserID] != nil) && g.UsersRemove[user.UserID] == nil {
					names = append(names, g.Name)
				}
			}
			detacher.Detach()
			ch <- names
			close(ch)
		},
	}
	detacher = client.Config.Attach(&listener)
	channel.RequestACL()

	return ch
}